def test_reload_taylordiagram(self): good_json = os.path.join(os.path.dirname(__file__), "share", "vcs_test_save_td_to_json.json") vcs.scriptrun(good_json) td = vcs.gettaylordiagram("vcs_test_save_taylor_to_json_and_python") td.script("vcs_test_save_td_to_json_reload") self.assertTrue( filecmp.cmp("vcs_test_save_td_to_json_reload.json", good_json))
def testLoadJson(self): pth = os.path.dirname(__file__) json = os.path.join(pth, "share", "test_vcs_json.json") for tp in [ "boxfill", "meshfill", "isofill", "isoline", "template", "1d" ]: b4 = vcs.listelements(tp) self.assertFalse("Charles.Doutriaux" in b4) vcs.scriptrun(json) for tp in [ "boxfill", "meshfill", "isofill", "isoline", "template", "1d" ]: after = vcs.listelements(tp) self.assertTrue("Charles.Doutriaux" in after) gm = vcs.elements[tp]["Charles.Doutriaux"]
def test_vcs_read_yx_scr(self): testfile = os.path.join(os.path.dirname(__file__), "share", "read_yxvsx.scr") vcs.scriptrun(testfile) self.assertTrue("testyx" in vcs.listelements("yxvsx")) y = vcs.getyxvsx("testyx") self.assertEqual(y.datawc_x1, -50.) self.assertEqual(y.datawc_x2, 20.) self.assertEqual(y.datawc_y1, 50.) self.assertEqual(y.datawc_timeunits, "days since 2100") self.assertEqual(y.datawc_calendar, 135441) self.assertEqual(y.xaxisconvert, "log10") self.assertEqual(y.yaxisconvert, "area_wt") self.assertEqual(y.linetype, "dash") self.assertEqual(y.linecolor, [0.0, 0.0, 0.0, 100.0]) self.assertEqual(y.linewidth, 1) self.assertEqual(y.marker, "circle") self.assertEqual(y.markercolor, [0.0, 0.0, 0.0, 100.0]) self.assertEqual(y.markersize, 1) self.assertEqual(y.flip, False)
ViridisScript = "/".join([WorkDir, "viridis.json"]) DataDir = sys.argv[2] FileName = "/".join([DataDir, sys.argv[3]]) InFile = ".".join([FileName, "nc"]) OutFile = ".".join([FileName, "png"]) # Process file f = cdms2.open(InFile) pr = f("precip_trend") x = vcs.init() vcs.scriptrun(ViridisScript) colormapname = "bl_to_darkred" # colormapname = "viridis" x.setcolormap(colormapname) iso = x.createisofill() number_different_colors = 64 levels = numpy.arange(-1., 1.00001, 2. / float(number_different_colors + 1)).tolist() iso.levels = levels cols = vcs.getcolors(levels, split=0) iso.fillareacolors = cols iso.legend = vcs.mklabels(numpy.arange(-1, 1.01, .125))
def test_vcs_read_old_scr(self): testfile = os.path.join("uvcdat-testdata", "data", "vcs", "old.scr") Ns = {} for k in vcs.elements.keys(): Ns[k] = len(vcs.elements[k].keys()) vcs.scriptrun(testfile) Ns2 = {} for k in vcs.elements.keys(): Ns2[k] = len(vcs.elements[k].keys()) diffs = { 'projection': 0, 'colormap': 53, 'isofill': 187, 'marker': 0, '3d_dual_scalar': 0, 'texttable': 4, '3d_scalar': 0, 'fillarea': 234, 'font': 0, '3d_vector': 0, '1d': 9, 'template': 43, 'textcombined': 0, 'textorientation': 3, 'xvsy': 0, 'xyvsy': 0, 'isoline': 113, 'boxfill': 239, 'fontNumber': 0, 'line': 21, 'meshfill': 0, 'yxvsx': 9, 'taylordiagram': 0, 'list': 26, 'display': 0, 'vector': 55, 'scatter': 0, "streamline": 0 } for k in vcs.elements.keys(): print "---Checking number of new elements for", k self.assertEqual(diffs[k], Ns2[k] - Ns[k]) gm = vcs.getisofill("pr_time_lat_1") self.assertEqual(gm.ymtics1, "lat5") self.assertTrue(gm.ext_2) self.assertEqual(gm.fillareastyle, "solid") self.assertEqual( gm.fillareacolors, [240, 240, 240, 28, 27, 26, 25, 23, 22, 21, 20, 19, 18, 16]) gm = vcs.getboxfill("lon_lat_mjop05") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.yticlabels1, "lat20") self.assertEqual(gm.datawc_x1, 30) self.assertEqual(gm.datawc_x2, 210.) self.assertEqual(gm.datawc_y1, -30) self.assertEqual(gm.datawc_y2, 30.) self.assertEqual(gm.level_1, -0.05) self.assertEqual(gm.level_2, 0.05) self.assertEqual(gm.color_1, 18) self.assertEqual(gm.color_2, 219) gm = vcs.getline("red_solid") self.assertEqual(gm.type, ['solid']) self.assertEqual(gm.color, [242]) self.assertEqual(gm.width, [2.0]) gm = vcs.getyxvsx("pr_lsfit_lat") self.assertEqual(gm.xmtics1, "lat5") self.assertEqual(gm.linecolor, 242) self.assertEqual(gm.linewidth, 2.) self.assertEqual(gm.datawc_x1, 30) self.assertEqual(gm.datawc_x2, -30.) self.assertEqual(gm.datawc_y1, -5.) self.assertEqual(gm.datawc_y2, 5.) gm = vcs.getisoline("div_anom") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.xticlabels1, "lon15") self.assertEqual(gm.linetypes, [ 'dash', 'dash', 'dash', 'dash', 'solid', 'dash', 'dash', 'dash', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid', 'solid' ]) self.assertEqual(gm.linecolors, [ 241, 241, 241, 241, 242, 241, 241, 241, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]) self.assertEqual(gm.linewidths, [ 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]) gm = vcs.getvector("lon_lat_IO_5") self.assertEqual(gm.xmtics1, "lon5") self.assertEqual(gm.xticlabels1, "lon20") self.assertEqual(gm.linecolor, 242) self.assertEqual(gm.linewidth, 2.) self.assertEqual(gm.scale, 3) self.assertEqual(gm.reference, 5)
def test_vcs_read_old_2(self): testfile = os.path.join("uvcdat-testdata", "data", "vcs", "old_2.scr") Ns = {} Es = {} for k in list(vcs.elements.keys()): Ns[k] = len(list(vcs.elements[k].keys())) Es[k] = vcs.listelements(k) vcs.scriptrun(testfile) Ns2 = {} for k in list(vcs.elements.keys()): Ns2[k] = len(list(vcs.elements[k].keys())) diffs = { 'projection': 0, 'colormap': 4, 'isofill': 102, 'marker': 15, '3d_dual_scalar': 0, 'texttable': 1, '3d_scalar': 0, 'fillarea': 404, 'font': 0, '3d_vector': 0, '1d': 19, 'template': 128, 'textcombined': 0, 'textorientation': 0, 'xvsy': 0, 'xyvsy': 15, 'isoline': 3, 'boxfill': 3, 'fontNumber': 0, 'line': 16, 'meshfill': 0, 'yxvsx': 17, 'taylordiagram': 1, 'list': 68, 'display': 0, 'vector': 5, 'scatter': 2, "streamline": 0 } for k in list(vcs.elements.keys()): print("Cheking number of new elements for", k) self.assertEqual(diffs[k], Ns2[k] - Ns[k]) gm = vcs.getmarker("navy") self.assertEqual(gm.type, ['dot']) self.assertEqual(gm.size, [2]) self.assertEqual(gm.color, [250]) gm = vcs.getisofill("AMIP2_psl") self.assertEqual( gm.levels, [[-1e+20, 97000.0], [97000.0, 97500.0], [97500.0, 98000.0], [98000.0, 98500.0], [98500.0, 99000.0], [99000.0, 99500.0], [99500.0, 100000.0], [100000.0, 100500.0], [100500.0, 101000.0], [101000.0, 101500.0], [101500.0, 102000.0], [102000.0, 102500.0], [102500.0, 103000.0], [103000.0, 103500.0], [103500.0, 104000.0], [104000.0, 1e+20]]) self.assertTrue(gm.ext_2) self.assertEqual(gm.ymtics1, "lat5") self.assertEqual(gm.fillareastyle, "solid") self.assertEqual( gm.fillareacolors, [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 35, 36])
import vcs, sys vcs.scriptrun(sys.argv[1]) assert ("testyx" in vcs.listelements("yxvsx")) y = vcs.getyxvsx("testyx") assert (y.datawc_x1 == -50.) assert (y.datawc_x2 == 20.) assert (y.datawc_y1 == 50.) assert (y.datawc_timeunits == "days since 2100") assert (y.datawc_calendar == 135441) assert (y.xaxisconvert == "log10") assert (y.yaxisconvert == "area_wt") assert (y.line == "dash") assert (y.linecolor == 241) assert (y.linewidth == 1) assert (y.marker == "circle") assert (y.markercolor == 241) assert (y.markersize == 1) assert (y.flip == False)
import vcs,sys vcs.scriptrun(sys.argv[1]) assert("testyx" in vcs.listelements("yxvsx")) y = vcs.getyxvsx("testyx") assert(y.datawc_x1 == -50.) assert(y.datawc_x2 == 20.) assert(y.datawc_y1 == 50.) assert(y.datawc_timeunits == "days since 2100") assert(y.datawc_calendar == 135441) assert(y.xaxisconvert == "log10") assert(y.yaxisconvert == "area_wt") assert(y.line == "dash") assert(y.linecolor == 241) assert(y.linewidth == 1) assert(y.marker == "circle") assert(y.markercolor == 241) assert(y.markersize == 1) assert(y.flip == False)
import vcs import sys json = sys.argv[1] for tp in ["boxfill","meshfill","isofill","isoline","template","1d"]: b4 = vcs.listelements(tp) assert (not "Charles.Doutriaux" in b4) vcs.scriptrun(json) for tp in ["boxfill","meshfill","isofill","isoline","template","1d"]: after = vcs.listelements(tp) assert ("Charles.Doutriaux" in after) gm = vcs.elements[tp]["Charles.Doutriaux"]
import vcs import sys json = sys.argv[1] for tp in ["boxfill", "meshfill", "isofill", "isoline", "template", "1d"]: b4 = vcs.listelements(tp) assert (not "Charles.Doutriaux" in b4) vcs.scriptrun(json) for tp in ["boxfill", "meshfill", "isofill", "isoline", "template", "1d"]: after = vcs.listelements(tp) assert ("Charles.Doutriaux" in after) gm = vcs.elements[tp]["Charles.Doutriaux"]