Example #1
0
 def __init__(self, *arg, **kw):
     super(VcsPlot, self).__init__(*arg, **kw)
     self._window = None
     self._canvas = vcs.init()
     self._plot = PlotManager(self._canvas)
     self._plot.graphics_method = vcs.getisofill()  # default
     self._plot.template = vcs.elements['template']['default']  # default
Example #2
0
 def __init__(self, *arg, **kw):
     super(VcsPlot, self).__init__(*arg, **kw)
     self._window = None
     self._canvas = vcs.init()
     self._plot = PlotManager(self._canvas)
     self._plot.graphics_method = vcs.getisofill()              # default
     self._plot.template = vcs.elements['template']['default']  # default
Example #3
0
 def __init__(self, canvas, *arg, **kw):
     self._width = kw.get('width', 800)
     self._height = kw.get('height', 600)
     if (canvas != None):
         self._canvas = canvas
     else:
         self._canvas = vcs.init(
             geometry={'width': self._width, 'height':self._height}, bg=1)
         self._canvas.open()
         self._canvas.backend.renWin.AddObserver("ModifiedEvent", self.modifiedEvent)
     self._plot = PlotManager(self._canvas)
     self._plot.graphics_method = vcs.getisofill()              # default
     self._plot.template = vcs.gettemplate('default')  # default
     self._insideModifiedEvent = False
Example #4
0
 def __init__(self, canvas, *arg, **kw):
     self._width = kw.get('width', 800)
     self._height = kw.get('height', 600)
     if (canvas != None):
         self._canvas = canvas
     else:
         self._canvas = vcs.init(geometry={
             'width': self._width,
             'height': self._height
         },
                                 bg=1)
         self._canvas.open()
         self._canvas.backend.renWin.AddObserver("ModifiedEvent",
                                                 self.modifiedEvent)
     self._plot = PlotManager(self._canvas)
     self._plot.graphics_method = vcs.getisofill()  # default
     self._plot.template = vcs.gettemplate('default')  # default
     self._insideModifiedEvent = False
Example #5
0
import vcs
import cdms2
f = cdms2.open(vcs.sample_data + "/clt.nc")
s = f("clt", time=slice(0, 1), squeeze=1)
x = vcs.init()
x.scriptrun("Test/isoleg.scr")
iso = vcs.getisofill("isoleg")
iso.list()
x.plot(s, iso)
raw_input("Ok")
Example #6
0
    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)
Example #7
0
    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])
Example #8
0
def plot(reference, test, diff, metrics_dict, parameter):
    vcs_canvas = vcs.init(bg=True,
                          geometry=(parameter.canvas_size_w,
                                    parameter.canvas_size_h))
    parameter.case_id

    file_path = os.path.join(acme_diags.INSTALL_PATH, 'polar')
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_7.json'))
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_7_new.json'))

    template_test = vcs_canvas.gettemplate('plotset7_0_x_0')
    template_ref = vcs_canvas.gettemplate('plotset7_0_x_1')
    template_diff = vcs_canvas.gettemplate('plotset7_0_x_2')

    template_test.title.x = 0.01
    template_test.dataname.x = 0.01
    template_test.dataname.y = template_test.title.y - 0.02
    template_test.data.y1 -= 0.025
    template_test.data.y2 -= 0.02

    template_ref.title.x = 0.01
    template_ref.dataname.x = 0.01
    template_ref.dataname.y = template_ref.title.y - 0.02
    template_ref.data.y1 -= 0.025
    template_ref.data.y2 -= 0.025

    template_diff.title.x = 0.01
    template_diff.dataname.x = 0.01
    template_diff.dataname.y = template_diff.title.y - 0.02
    template_diff.data.y1 -= 0.025
    template_diff.data.y2 -= 0.025

    utils.set_units(test, parameter.test_units)
    utils.set_units(reference, parameter.reference_units)
    utils.set_units(diff, parameter.diff_units)

    test.long_name = parameter.test_title
    reference.long_name = parameter.reference_title
    diff.long_name = parameter.diff_title

    test.id = parameter.test_name_yrs
    reference.id = parameter.reference_name
    diff.id = parameter.diff_name

    # model and observation graph
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'test')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict, 'ref')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'diff')

    reference_isofill = vcs.getisofill('reference_isofill')
    reference_isofill.missing = 'grey'
    reference_isofill.xticlabels1 = {
        0: "0",
        30: "30$^\circ$E",
        60: "60$^\circ$E",
        90: "90$^\circ$E",
        120: "120$^\circ$E",
        150: "150$^\circ$E",
        180: "180$^\circ$W",
        210: "150$^\circ$W",
        240: "120$^\circ$W",
        270: "90$^\circ$W",
        300: "60$^\circ$W",
        330: "30$^\circ$W"
    }

    test_isofill = vcs.getisofill('test_isofill')
    test_isofill.missing = 'grey'
    test_isofill.xticlabels1 = {
        0: "0",
        30: "30$^\circ$E",
        60: "60$^\circ$E",
        90: "90$^\circ$E",
        120: "120$^\circ$E",
        150: "150$^\circ$E",
        180: "180$^\circ$W",
        210: "150$^\circ$W",
        240: "120$^\circ$W",
        270: "90$^\circ$W",
        300: "60$^\circ$W",
        330: "30$^\circ$W"
    }

    diff_isofill = vcs.getisofill('diff_isofill')
    diff_isofill.missing = 'grey'
    diff_isofill.xticlabels1 = {
        0: "0",
        30: "30$^\circ$E",
        60: "60$^\circ$E",
        90: "90$^\circ$E",
        120: "120$^\circ$E",
        150: "150$^\circ$E",
        180: "180$^\circ$W",
        210: "150$^\circ$W",
        240: "120$^\circ$W",
        270: "90$^\circ$W",
        300: "60$^\circ$W",
        330: "30$^\circ$W"
    }

    if parameter.var_region.lower().find('polar') != -1:
        reference_isofill.projection = 'polar'
        test_isofill.projection = 'polar'
        diff_isofill.projection = 'polar'
        if parameter.var_region.find('S') != -1:
            lat_y1 = -90
            lat_y2 = -55
        elif parameter.var_region.find('N') != -1:
            lat_y1 = 90
            lat_y2 = 50

        # this should extracted from selected domain
        reference_isofill.datawc_y1 = lat_y1
        reference_isofill.datawc_y2 = lat_y2
        test_isofill.datawc_y1 = lat_y1  # this should extracted from selected domain
        test_isofill.datawc_y2 = lat_y2
        diff_isofill.datawc_y1 = lat_y1  # this should extracted from selected domain
        diff_isofill.datawc_y2 = lat_y2

    utils.set_levels_of_graphics_method(reference_isofill,
                                        parameter.contour_levels, reference,
                                        test)
    utils.set_levels_of_graphics_method(test_isofill, parameter.contour_levels,
                                        test, reference)
    utils.set_levels_of_graphics_method(diff_isofill, parameter.diff_levels,
                                        diff)

    if parameter.arrows:
        reference_isofill.ext_1 = True
        reference_isofill.ext_2 = True
        test_isofill.ext_1 = True
        test_isofill.ext_2 = True
        diff_isofill.ext_1 = True
        diff_isofill.ext_2 = True

    utils.set_colormap_of_graphics_method(vcs_canvas,
                                          parameter.reference_colormap,
                                          reference_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.test_colormap,
                                          test_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.diff_colormap,
                                          diff_isofill, parameter)

    vcs_canvas.plot(utils.add_cyclic(test), template_test, test_isofill)
    vcs_canvas.plot(utils.add_cyclic(reference), template_ref,
                    reference_isofill)
    vcs_canvas.plot(utils.add_cyclic(diff), template_diff, diff_isofill)

    utils.plot_rmse_and_corr(textcombined_objs, vcs_canvas, metrics_dict)

    # Plotting the main title
    main_title = utils.managetextcombined(textcombined_objs, 'main_title',
                                          'main_title', vcs_canvas)
    main_title.string = parameter.main_title
    main_title.y = [0.985]
    # for some reason, this needs to be before a call to vcs_canvas.plot()
    vcs_canvas.portrait()
    vcs_canvas.plot(main_title)

    if not parameter.logo:
        vcs_canvas.drawlogooff()

    fnm = os.path.join(get_output_dir(parameter.current_set, parameter),
                       parameter.output_file)
    for f in parameter.output_format:
        f = f.lower().split('.')[-1]
        if f == 'png':
            vcs_canvas.png(fnm)
            _chown(fnm + '.png', parameter.user)
        elif f == 'pdf':
            vcs_canvas.pdf(fnm)
            _chown(fnm + '.pdf', parameter.user)
        elif f == 'svg':
            vcs_canvas.svg(fnm)
            _chown(fnm + '.svg', parameter.user)
        print('Plot saved in: ' + fnm + '.' + f)
    vcs_canvas.clear()
Example #9
0
def isofill(name):
    try:
        iso = vcs.getisofill(str(name))
    except:
        abort(404)
    return jsonify(vcs.utils.dumpToDict(iso)[0])
Example #10
0
def plot(reference, test, diff, metrics_dict, parameter):
    vcs_canvas = vcs.init(bg=True,
                          geometry=(parameter.canvas_size_w,
                                    parameter.canvas_size_h))
    parameter.case_id

    file_path = os.path.join(acme_diags.INSTALL_PATH, 'lat_lon')
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_5.json'))
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_5_new.json'))

    template_test = vcs_canvas.gettemplate('plotset5_0_x_0')
    template_ref = vcs_canvas.gettemplate('plotset5_0_x_1')
    template_diff = vcs_canvas.gettemplate('plotset5_0_x_2')

    utils.set_units(test, parameter.test_units)
    utils.set_units(reference, parameter.reference_units)
    utils.set_units(diff, parameter.diff_units)

    test.long_name = parameter.test_title
    reference.long_name = parameter.reference_title
    diff.long_name = parameter.diff_title

    test.id = parameter.test_name_yrs
    reference.id = parameter.reference_name
    diff.id = parameter.diff_name

    # model and observation graph
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'test')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict, 'ref')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'diff')

    reference_isofill = vcs.getisofill('reference_isofill')
    reference_isofill.missing = 'grey'
    reference_isofill.yticlabels1 = {
        -90: "90$^\circ$S",
        -60: "60$^\circ$S",
        -30: "30$^\circ$S",
        0: "0$^\circ$",
        30: "30$^\circ$N",
        60: "60$^\circ$N",
        90: "90$^\circ$N"
    }
    test_isofill = vcs.getisofill('test_isofill')
    test_isofill.missing = 'grey'
    test_isofill.yticlabels1 = {
        -90: "90$^\circ$S",
        -60: "60$^\circ$S",
        -30: "30$^\circ$S",
        0: "0$^\circ$",
        30: "30$^\circ$N",
        60: "60$^\circ$N",
        90: "90$^\circ$N"
    }
    diff_isofill = vcs.getisofill('diff_isofill')
    diff_isofill.missing = 'grey'
    diff_isofill.yticlabels1 = {
        -90: "90$^\circ$S",
        -60: "60$^\circ$S",
        -30: "30$^\circ$S",
        0: "0$^\circ$",
        30: "30$^\circ$N",
        60: "60$^\circ$N",
        90: "90$^\circ$N"
    }

    utils.set_levels_of_graphics_method(reference_isofill,
                                        parameter.contour_levels, reference,
                                        test)
    utils.set_levels_of_graphics_method(test_isofill, parameter.contour_levels,
                                        test, reference)
    utils.set_levels_of_graphics_method(diff_isofill, parameter.diff_levels,
                                        diff)

    if parameter.arrows:
        reference_isofill.ext_1 = True
        reference_isofill.ext_2 = True
        test_isofill.ext_1 = True
        test_isofill.ext_2 = True
        diff_isofill.ext_1 = True
        diff_isofill.ext_2 = True

    utils.set_colormap_of_graphics_method(vcs_canvas,
                                          parameter.reference_colormap,
                                          reference_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.test_colormap,
                                          test_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.diff_colormap,
                                          diff_isofill, parameter)

    vcs_canvas.plot(utils.add_cyclic(test), template_test, test_isofill)
    vcs_canvas.plot(utils.add_cyclic(reference), template_ref,
                    reference_isofill)
    vcs_canvas.plot(utils.add_cyclic(diff), template_diff, diff_isofill)

    utils.plot_rmse_and_corr(textcombined_objs, vcs_canvas, metrics_dict)
    # for some reason, this needs to be before a call to vcs_canvas.plot()
    vcs_canvas.portrait()

    # Plotting the main title
    main_title = utils.managetextcombined(textcombined_objs, 'main_title',
                                          'main_title', vcs_canvas)
    main_title.string = parameter.main_title
    vcs_canvas.plot(main_title)

    if not parameter.logo:
        vcs_canvas.drawlogooff()

    fnm = os.path.join(get_output_dir(parameter.current_set, parameter),
                       parameter.output_file)
    for f in parameter.output_format:
        f = f.lower().split('.')[-1]
        if f == 'png':
            vcs_canvas.png(fnm)
            _chown(fnm + '.png', parameter.user)
        elif f == 'pdf':
            vcs_canvas.pdf(fnm)
            _chown(fnm + '.pdf', parameter.user)
        elif f == 'svg':
            vcs_canvas.svg(fnm)
            _chown(fnm + '.svg', parameter.user)
        print('Plot saved in: ' + fnm + '.' + f)
    vcs_canvas.clear()
def plot(reference, test, diff, metrics_dict, parameter):
    vcs_canvas = vcs.init(bg=True,
                          geometry=(parameter.canvas_size_w,
                                    parameter.canvas_size_h))
    case_id = parameter.case_id

    reference = rotate_180(reference)
    test = rotate_180(test)
    diff = rotate_180(diff)

    file_path = os.path.join(sys.prefix, 'share', 'acme_diags',
                             'zonal_mean_2d')
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_4.json'))
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_4_new.json'))

    template_test = vcs_canvas.gettemplate('plotset4_0_x_0')
    template_ref = vcs_canvas.gettemplate('plotset4_0_x_1')
    template_diff = vcs_canvas.gettemplate('plotset4_0_x_2')

    utils.set_units(test, parameter.test_units)
    utils.set_units(reference, parameter.reference_units)
    utils.set_units(diff, parameter.diff_units)

    test.long_name = parameter.test_title
    reference.long_name = parameter.reference_title
    diff.long_name = parameter.diff_title

    test.id = parameter.test_name
    reference.id = parameter.reference_name
    diff.id = parameter.diff_name

    # model and observation graph
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'test')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict, 'ref')
    utils.plot_min_max_mean(textcombined_objs, vcs_canvas, metrics_dict,
                            'diff')

    reference_isofill = vcs.getisofill('reference_isofill')
    reference_isofill.missing = 'grey'
    reference = log_yaxis(reference, reference_isofill)

    test_isofill = vcs.getisofill('test_isofill')
    test_isofill.missing = 'grey'
    test = log_yaxis(test, test_isofill)

    diff_isofill = vcs.getisofill('diff_isofill')
    diff_isofill.missing = 'grey'
    diff = log_yaxis(diff, diff_isofill)

    utils.set_levels_of_graphics_method(reference_isofill,
                                        parameter.contour_levels, reference,
                                        test)
    utils.set_levels_of_graphics_method(test_isofill, parameter.contour_levels,
                                        test, reference)
    utils.set_levels_of_graphics_method(diff_isofill, parameter.diff_levels,
                                        diff)

    if parameter.arrows:
        reference_isofill.ext_1 = True
        reference_isofill.ext_2 = True
        test_isofill.ext_1 = True
        test_isofill.ext_2 = True
        diff_isofill.ext_1 = True
        diff_isofill.ext_2 = True

    utils.set_colormap_of_graphics_method(vcs_canvas,
                                          parameter.reference_colormap,
                                          reference_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.test_colormap,
                                          test_isofill, parameter)
    utils.set_colormap_of_graphics_method(vcs_canvas, parameter.diff_colormap,
                                          diff_isofill, parameter)

    vcs_canvas.plot(test, template_test, test_isofill)
    vcs_canvas.plot(reference, template_ref, reference_isofill)
    vcs_canvas.plot(diff, template_diff, diff_isofill)

    utils.plot_rmse_and_corr(textcombined_objs, vcs_canvas, metrics_dict)

    # Plotting the main title
    main_title = utils.managetextcombined(textcombined_objs, 'main_title',
                                          'main_title', vcs_canvas)
    main_title.string = parameter.main_title
    vcs_canvas.portrait(
    )  # for some reason, this needs to be before a call to vcs_canvas.plot()
    vcs_canvas.plot(main_title)

    if not parameter.logo:
        vcs_canvas.drawlogooff()

    fnm = os.path.join(get_output_dir(parameter.current_set, parameter),
                       parameter.output_file)
    for f in parameter.output_format:
        f = f.lower().split('.')[-1]
        if f == 'png':
            vcs_canvas.png(fnm)
            _chown(fnm + '.png', parameter.user)
        elif f == 'pdf':
            vcs_canvas.pdf(fnm)
            _chown(fnm + '.pdf', parameter.user)
        elif f == 'svg':
            vcs_canvas.svg(fnm)
            _chown(fnm + '.svg', parameter.user)
        print('Plot saved in: ' + fnm + '.' + f)

    vcs_canvas.clear()
Example #12
0
def plot(reference, test, diff, metrics_dict, parameter):
    vcs_canvas = vcs.init(bg=True, geometry=(parameter.canvas_size_w, parameter.canvas_size_h))
    case_id = parameter.case_id

    file_path = os.path.join(sys.prefix, 'share', 'acme_diags', 'set7')
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_7.json'))
    vcs_canvas.scriptrun(os.path.join(file_path, 'plot_set_7_new.json'))
    
    template_test = vcs_canvas.gettemplate('plotset7_0_x_0')
    template_ref = vcs_canvas.gettemplate('plotset7_0_x_1')
    template_diff = vcs_canvas.gettemplate('plotset7_0_x_2')

    template_test.title.x = 0.01
    template_test.dataname.x = 0.01
    template_test.dataname.y = template_test.title.y - 0.02
    template_test.data.y1 -= 0.025
    template_test.data.y2 -= 0.02

    template_ref.title.x = 0.01
    template_ref.dataname.x = 0.01
    template_ref.dataname.y = template_ref.title.y - 0.02
    template_ref.data.y1 -= 0.025
    template_ref.data.y2 -= 0.025

    template_diff.title.x = 0.01
    template_diff.dataname.x = 0.01
    template_diff.dataname.y = template_diff.title.y - 0.02
    template_diff.data.y1 -= 0.025
    template_diff.data.y2 -= 0.025

    set_units(test, parameter.test_units)
    set_units(reference, parameter.reference_units)
    set_units(diff, parameter.diff_units)

    test.long_name = parameter.test_title
    reference.long_name = parameter.reference_title
    diff.long_name = parameter.diff_title

    test.id = parameter.test_name
    reference.id = parameter.reference_name
    diff.id = parameter.diff_name

    # model and observation graph
    plot_min_max_mean(vcs_canvas, metrics_dict, 'test')
    plot_min_max_mean(vcs_canvas, metrics_dict, 'ref')
    plot_min_max_mean(vcs_canvas, metrics_dict, 'diff')

    reference_isofill = vcs.getisofill('reference_isofill')
    reference_isofill.missing = 'grey'
    test_isofill = vcs.getisofill('test_isofill')
    test_isofill.missing = 'grey'
    diff_isofill = vcs.getisofill('diff_isofill')
    diff_isofill.missing = 'grey'
    if parameter.var_region.lower().find('polar') !=-1:
        reference_isofill.projection = 'polar'
        test_isofill.projection = 'polar'
        diff_isofill.projection = 'polar'
        if parameter.var_region.find('S') !=-1: 
            lat_y1 = -90 
            lat_y2 = -55 
        elif parameter.var_region.find('N') !=-1:
            lat_y1 = 90 
            lat_y2 = 50 
 
        reference_isofill.datawc_y1 = lat_y1  # this should extracted from selected domain
        reference_isofill.datawc_y2 = lat_y2
        test_isofill.datawc_y1 = lat_y1  # this should extracted from selected domain
        test_isofill.datawc_y2 = lat_y2
        diff_isofill.datawc_y1 = lat_y1  # this should extracted from selected domain
        diff_isofill.datawc_y2 = lat_y2


    set_levels_of_graphics_method(reference_isofill, parameter.contour_levels, reference, test)
    set_levels_of_graphics_method(test_isofill, parameter.contour_levels, test, reference)
    set_levels_of_graphics_method(diff_isofill, parameter.diff_levels, diff)

    if parameter.arrows:
        reference_isofill.ext_1 = True
        reference_isofill.ext_2 = True
        test_isofill.ext_1 = True
        test_isofill.ext_2 = True
        diff_isofill.ext_1 = True
        diff_isofill.ext_2 = True

    set_colormap_of_graphics_method(vcs_canvas, parameter.reference_colormap, reference_isofill)
    set_colormap_of_graphics_method(vcs_canvas, parameter.test_colormap, test_isofill)
    set_colormap_of_graphics_method(vcs_canvas, parameter.diff_colormap, diff_isofill)

    vcs_canvas.plot(add_cyclic(test), template_test, test_isofill)
    vcs_canvas.plot(add_cyclic(reference), template_ref, reference_isofill)
    vcs_canvas.plot(add_cyclic(diff), template_diff, diff_isofill)

    plot_rmse_and_corr(vcs_canvas, metrics_dict)

    # Plotting the main title
    main_title = managetextcombined('main_title', 'main_title', vcs_canvas)
    main_title.string = parameter.main_title
    main_title.y = [0.985]
    vcs_canvas.portrait()  # for some reason, this needs to be before a call to vcs_canvas.plot()
    vcs_canvas.plot(main_title)

    if not parameter.logo:
        vcs_canvas.drawlogooff()

    fnm = os.path.join(get_output_dir('7', parameter), parameter.output_file)
    for f in parameter.output_format:
        f = f.lower().split('.')[-1]
        if f == 'png':
            vcs_canvas.png(fnm)
        elif f == 'pdf':
            vcs_canvas.pdf(fnm)
        elif f == 'svg':
            vcs_canvas.svg(fnm)
        print('Plot saved in: ' + fnm + '.' + f)
    vcs_canvas.clear()