Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Log axes 2d #316

Merged
merged 20 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/share/template_test_associated_dump.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@
"priority": 0,
"textorientation": "defcenter",
"texttable": "default",
"y": 0.870000004768
"y": 0.880000004768
},
"xmintic1": {
"line": "default",
"priority": 0,
"y1": 0.259999990463,
"y2": 0.256999999285
"y2": 0.248999999285
},
"xmintic2": {
"line": "default",
"priority": 0,
"y1": 0.860000014305,
"y2": 0.860000014305
"y2": 0.868000014305
},
"xname": {
"priority": 1,
Expand Down
115 changes: 115 additions & 0 deletions tests/test_vcs_axisconvert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import basevcstest
import vcs

import numpy


class TestVCSAxisConvert(basevcstest.VCSBaseTest):
def testAxisConvert(self):
gm = vcs.create1d()
gm.yaxisconvert = "log10"
data = numpy.arange(10)
self.x.plot(numpy.power(10,data), gm, bg=self.bg)
self.checkImage("test_vcs_yaxisconvert_log10.png")

self.x.clear()
gm.flip = True
gm.yaxisconvert = "linear"
gm.xaxisconvert="log10"
self.x.plot(numpy.power(10,data), gm, bg=self.bg)
self.checkImage("test_vcs_xaxisconvert_log10_flip.png")

self.x.clear()
gm.flip = False
gm.xaxisconvert = "linear"
gm.yaxisconvert="ln"
self.x.plot(numpy.exp(data), gm, bg=self.bg)
self.checkImage("test_vcs_yaxisconvert_ln.png")

self.x.clear()
gm.flip = False
gm.xaxisconvert="area_wt"
gm.yaxisconvert = "linear"
data2 = self.clt("clt",time=slice(0,1), longitude=slice(23,24), squeeze=1)
self.x.plot(data2, gm, bg=self.bg)
self.checkImage("test_vcs_xaxisconvert_areawt.png")

self.x.clear()
gm.flip = True
gm.yaxisconvert="area_wt"
gm.xaxisconvert = "linear"
self.x.plot(data2, gm, bg=self.bg)
self.checkImage("test_vcs_yaxisconvert_areawt_flip.png")


self.x.clear()
gm.flip = False
gm.xaxisconvert="log10"
gm.yaxisconvert = "ln"
self.x.plot(numpy.power(10,data), numpy.exp(data), gm, bg=self.bg)
self.checkImage("test_vcs_axisconvert_log10_ln.png")

self.x.clear()
#gm.flip = True
data2[:] = numpy.power(10,numpy.arange(1, data2.shape[0]+1))
data2 = data2[:10]
gm.xaxisconvert = "area_wt"
gm.yaxisconvert="log10"
self.x.plot(data2 , gm, bg=self.bg)
self.checkImage("test_vcs_axisconvert_area_log10.png")

self.x.clear()
gm.flip = True
gm.yaxisconvert = "area_wt"
gm.xaxisconvert="log10"
self.x.plot(data2 , gm, bg=self.bg)
self.checkImage("test_vcs_axisconvert_area_log10_flip.png")

self.x.clear()
gm.flip = False
gm.xaxisconvert = "area_wt"
gm.yaxisconvert="log10"
self.x.plot(data2.getAxis(0)[:], data2 , gm, bg=self.bg)
self.checkImage("test_vcs_axisconvert_area_log10_2arrays.png")

with self.assertRaises(RuntimeError):
self.x.clear()
gm.flip = True
self.x.plot(data2.getAxis(0)[:], data2 , gm, bg=self.bg)

self.x.clear()
gm.flip = False
gm.xaxisconvert = "area_wt"
gm.yaxisconvert="log10"
gm.xticlabels1 = { -90:"90S", -80:"80S", -70:"70S", -60:"60S"}
gm.xticlabels2 = { -85:"85S", -75:"75S", -65:"65S", -55:"55S"}
mtics = {}
def func(x):
mtics[x]=""

map(func, range(-90,-40,10))
gm.xmtics2 = mtics
mtics = {}
map(func, range(-85,-40,10))
gm.xmtics1 = mtics

gm.yticlabels1 = {100:"hun"}
gm.yticlabels2 = {1000:"thou"}
gm.ymtics1 = {10:"",1000:""}
gm.ymtics2 = {10000:"",1000:""}
gm.list()
tmpl = vcs.createtemplate()
for num in ["1", "2"]:
for loc in ["x", "y"]:
for attr in ["mintic", "tic"]:
filled_attr = "{}{}{}".format(loc,attr,num)
print("PRIO FOR ATT:",filled_attr)
obj = getattr(tmpl,filled_attr)
obj.priority=1
obj.list()
tmpl.xlabel1.priority=1
tmpl.xlabel2.priority=1
tmpl.ylabel1.priority=1
tmpl.ylabel2.priority=1
self.x.plot(data2.getAxis(0)[:], data2 , gm, tmpl, bg=self.bg)
self.checkImage("test_vcs_axisconvert_area_log10_user_labels.png")
63 changes: 63 additions & 0 deletions tests/test_vcs_axisconvert_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import basevcstest
import os
import vcs
import cdms2
import numpy


class TestVCSAxisConvert(basevcstest.VCSBaseTest):
def axisConvertGmLog10Areawt(self, method):
method = method()
f = cdms2.open(vcs.sample_data+"/ta_ncep_87-6-88-4.nc")
data = f("ta", time=slice(0,1), longitude=(12,12,'cob'), squeeze=1)
if isinstance(method, vcs.vector.Gv):
data2 = data
else:
data2 = None
self.axisConvertGm(data, data2, method, 'area_wt', 'log10')

def axisConvertGmLog10(self, method):
method = method()
f = cdms2.open(vcs.sample_data+"/ta_ncep_87-6-88-4.nc")
data = f("ta", longitude=(12,12,'cob'), latitude=(12, 12, 'cob'), squeeze=1)
if isinstance(method, vcs.vector.Gv):
data2 = data
else:
data2 = None
self.axisConvertGm(data, data2, method, 'log10', 'linear')

def axisConvertGmAreaWt(self, method):
method = method()
if isinstance(method, vcs.vector.Gv):
data = self.clt("u")
data2 = self.clt("v")
elif isinstance(method, vcs.meshfill.Gfm):
data = cdms2.open(os.path.join(vcs.sample_data,"sampleCurveGrid4.nc"))("sample")
data2 = None
else:
data = self.clt("clt")
data2 = None
self.axisConvertGm(data, data2, method, 'linear', 'area_wt')

def axisConvertGm(self, data, data2, gm, xconvert, yconvert):
gm.xaxisconvert = xconvert
gm.yaxisconvert = yconvert
self.x.clear()
if data2 is None:
self.x.plot(data, gm)
else:
self.x.plot(data, data2, gm)
self.checkImage("test_vcs_axisconvert_{}_{}_{}.png".format(gm.g_name, xconvert, yconvert))

def test_areawt(self):
for method in [
vcs.createboxfill,
vcs.createisofill,
vcs.createisoline,
vcs.createmeshfill,
# vcs.createvector,
]:
self.axisConvertGmAreaWt(method)
if not method in [vcs.createmeshfill,]:
self.axisConvertGmLog10(method)
self.axisConvertGmLog10Areawt(method)
4 changes: 1 addition & 3 deletions tests/test_vcs_continents.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ def testContinents(self):
bg=self.bg)
elif cont_index == 3:
self.x.setcontinentsline(cont_line)
self.x.setcontinentstype(3)
self.x.plot(clt, template, boxfill, bg=self.bg)
self.x.plot(clt, template, boxfill, continents=3, bg=self.bg)
elif i == 4:
self.x.setcontinentstype(0)
# Make sure absolute path works
path = os.path.join(
vcs.prefix, "share", "vcs", "data_continent_political")
Expand Down
1 change: 1 addition & 0 deletions tests/test_vcs_dump_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import basevcstest
import filecmp
import os
Expand Down
5 changes: 2 additions & 3 deletions tests/test_vcs_isofill_masked_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ def testIsofill(self):

data = os.path.join(self.basedatadir, "coads_climatology.nc")
f = cdms2.open(data)
s = f["SST"]
s = f("SST")
t = s.getTime()
tc = t.asComponentTime()
print("TC:",tc[:3])
t.units = "hours since 1"
iso = self.x.getisofill('a_robinson_isofill')
self.x.plot(s, iso, bg=self.bg)
self.checkImage("test_vcs_isofill_masked_bounds.png")
14 changes: 7 additions & 7 deletions tests/test_vcs_no_continents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def testNoContinents(self):
clt = clt(latitude=(-90.0, 90.0), longitude=(-180., 175.), squeeze=1,
time=('1979-1-1 0:0:0.0', '1988-12-1 0:0:0.0'))

t1 = self.x.createtemplate()
t1.scale(.5, "y")
t1.move(-.15, "y")
t2 = self.x.createtemplate(source=t1.name)
t2.move(.5, 'y')
template_bottom = self.x.createtemplate()
template_bottom.scale(.5, "y")
template_bottom.move(-.15, "y")
template_top = self.x.createtemplate(source=template_bottom.name)
template_top.move(.5, 'y')

self.x.plot(clt, t1, continents=0, bg=self.bg)
self.x.plot(clt, t2, continents=1, bg=self.bg)
self.x.plot(clt, template_bottom, continents=0, bg=self.bg)
self.x.plot(clt, template_top, continents=1, bg=self.bg)

self.checkImage("test_vcs_no_continents.png")
Loading