Example #1
0
 def test_findall(self):
     rc = RcParams(
         defaultParams={
             'some.test': [1, lambda i: int(i), 'The documentation'],
             'some.other_test':
             [2, lambda i: int(i), 'Another documentation']
         })
     rc.update_from_defaultParams()
     self.assertEqual(rc.find_all('other'), {'some.other_test': 2})
Example #2
0
 def test_catch(self):
     rc = RcParams(
         defaultParams={
             'some.test': [1, lambda i: int(i), 'The documentation'],
             'some.other_test':
             [2, lambda i: int(i), 'Another documentation']
         })
     rc.update_from_defaultParams()
     with rc.catch():
         rc['some.test'] = 2
         self.assertEqual(rc['some.test'], 2)
     self.assertEqual(rc['some.test'], 1)
Example #3
0
    def test_error(self):
        """Test whether the correct Error is raised"""
        def validate(i):
            try:
                return int(i)
            except:
                raise ValueError("Expected failure")

        rc = RcParams(
            defaultParams={
                'some.test': [1, validate, 'The documentation'],
                'some.other_test': [2, validate, 'Another documentation']
            })
        rc.update_from_defaultParams()
        with self.assertRaisesRegex(ValueError, "Expected failure"):
            rc['some.test'] = 'test'
        with self.assertRaises(KeyError):
            rc['wrong_key'] = 1
        rc._deprecated_map['something'] = ['some.test', lambda x: x]
        with self.assertWarnsRegex(UserWarning,
                                   rc.msg_depr % ('something', 'some.test')):
            rc['something'] = 3
        # check whether the value has been changed correctly
        self.assertEqual(rc['some.test'], 3)
        rc._deprecated_ignore_map['ignored'] = 'some.test'
        with self.assertWarnsRegex(
                UserWarning, rc.msg_depr_ignore % ('ignored', 'some.test')):
            rc['ignored'] = None
        # check whether the value has not been changed
        self.assertEqual(rc['some.test'], 3)
Example #4
0
 def load_plugin_pages(self):
     """Load the rcParams for the plugins in separate pages"""
     validators = psy_rcParams.validate
     descriptions = psy_rcParams.descriptions
     for ep in psy_rcParams._load_plugin_entrypoints():
         plugin = ep.load()
         rc = getattr(plugin, 'rcParams', None)
         if rc is None:
             rc = RcParams()
         w = RcParamsWidget(parent=self)
         w.title = 'rcParams of ' + ep.module_name
         w.default_path = PsyRcParamsWidget.default_path
         w.initialize(rcParams=rc,
                      validators=validators,
                      descriptions=descriptions)
         # use the full rcParams after initialization
         w.rc = psy_rcParams
         self.add_page(w)
Example #5
0
    def test_dump(self):
        """Test the dumping of the rcParams"""
        rc = RcParams(
            defaultParams={
                'some.test': [1, lambda i: int(i), 'The documentation'],
                'some.other_test':
                [2, lambda i: int(i), 'Another documentation']
            })
        rc.update_from_defaultParams()

        rc.HEADER = 'the header'
        s = rc.dump(default_flow_style=False)
        self.assertIn('the header', s)
        self.assertRegex(s, r'# The documentation\n\s*some.test')
        self.assertRegex(s, r'# Another documentation\n\s*some.other_test')
Example #6
0
rcParams = RcParams(
    defaultParams={

        # -------------------------------------------------------------------------
        # ----------------------- Registered plotters -----------------------------
        # -------------------------------------------------------------------------
        'project.plotters': [{
            'simple': {
                'module':
                'psy_simple.plotters',
                'plotter_name':
                'SimplePlotterBase',
                'plot_func':
                False,
                'summary': (
                    'All plotters that are visualized by the psy-simple '
                    'package')
            },
            'lineplot': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'LinePlotter',
                'prefer_list': True,
                'default_slice': None,
                'summary': 'Make a line plot of one-dimensional data'
            },
            'fldmean': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'FldmeanPlotter',
                'prefer_list': True,
                'default_slice': None,
                'summary':
                'Calculate and plot the mean over x- and y-dimensions'
            },
            'density': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'DensityPlotter',
                'prefer_list': False,
                'default_slice': None,
                'summary': 'Make a density plot of point data'
            },
            'barplot': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'BarPlotter',
                'prefer_list': True,
                'default_slice': None,
                'summary': 'Make a bar plot of one-dimensional data'
            },
            'violinplot': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'ViolinPlotter',
                'prefer_list': True,
                'default_slice': None,
                'summary': 'Make a violin plot of your data'
            },
            'plot2d': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'Simple2DPlotter',
                'prefer_list': False,
                'default_slice': 0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': 'Make a simple plot of a 2D scalar field'
            },
            'vector': {
                'module': 'psy_simple.plotters',
                'plotter_name': 'SimpleVectorPlotter',
                'prefer_list': False,
                'default_slice': 0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': 'Make a simple plot of a 2D vector field',
                'example_call': "filename, name=[['u_var', 'v_var']], ..."
            },
            'combined': {
                'module':
                'psy_simple.plotters',
                'plotter_name':
                'CombinedSimplePlotter',
                'prefer_list':
                True,
                'default_slice':
                0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': ('Plot a 2D scalar field with an overlying vector '
                            'field'),
                'example_call':
                ("filename, name=[['my_variable', ['u_var', 'v_var']]], ...")
            },
        }, validate_dict],

        # -------------------------------------------------------------------------
        # --------------------- Default formatoptions -----------------------------
        # -------------------------------------------------------------------------
        'plotter.baseplotter.tight':
        [False, validate_bool, 'fmt key for tight layout of the plots'],
        'plotter.simple.grid': [
            False,
            try_and_error(validate_bool_maybe_none, validate_color),
            'fmt key to visualize the grid on simple plots (i.e. without '
            'projection)'
        ],

        # labels
        'plotter.baseplotter.title':
        ['', six.text_type, 'fmt key to control the title of the axes'],
        'plotter.baseplotter.figtitle':
        ['', six.text_type, 'fmt key to control the title of the axes'],
        'plotter.baseplotter.text':
        [[], validate_text, 'fmt key to show text anywhere on the plot'],
        'plotter.simple.ylabel': [
            '', six.text_type, 'fmt key to modify the y-axis label for simple'
            'plot (i.e. plots withouth projection)'
        ],
        'plotter.simple.xlabel': [
            '', six.text_type, 'fmt key to modify the y-axis label for simple'
            'plot (i.e. plots withouth projection)'
        ],
        'plotter.plot2d.clabel': [
            '', six.text_type, 'fmt key to modify the colorbar label for 2D'
            'plots'
        ],

        # text sizes
        'plotter.baseplotter.titlesize': [
            'large', validate_fontsize,
            'fmt key for the fontsize of the axes title'
        ],
        'plotter.baseplotter.figtitlesize': [
            12, validate_fontsize,
            'fmt key for the fontsize of the figure title'
        ],
        'plotter.simple.labelsize': [
            'medium',
            DictValValidator('labelsize', ['x', 'y'], validate_fontsize, None,
                             True),
            'fmt key for the fontsize of the x- and y-l abel of simple plots '
            '(i.e. without projection)'
        ],
        'plotter.simple.ticksize': [
            'medium',
            DictValValidator('ticksize', ['major', 'minor'], validate_fontsize,
                             'major', True),
            'fmt key for the fontsize of the ticklabels of x- and y-axis of '
            'simple plots (i.e. without projection)'
        ],
        'plotter.plot2d.cticksize': [
            'medium', validate_fontsize,
            'fmt key for the fontsize of the ticklabels of the colorbar of 2D '
            'plots'
        ],
        'plotter.plot2d.clabelsize': [
            'medium', validate_fontsize,
            'fmt key for the fontsize of the colorbar label'
        ],

        # text weights
        'plotter.baseplotter.titleweight': [
            None, validate_fontweight,
            'fmt key for the fontweight of the axes title'
        ],
        'plotter.baseplotter.figtitleweight': [
            None, validate_fontweight,
            'fmt key for the fontweight of the figure title'
        ],
        'plotter.simple.labelweight': [
            None,
            DictValValidator('labelweight', ['x', 'y'], validate_fontweight,
                             None, True),
            'fmt key for the fontweight of the x- and y-l abel of simple plots '
            '(i.e. without projection)'
        ],
        'plotter.simple.tickweight': [
            None,
            DictValValidator('tickweight', ['major', 'minor'],
                             validate_fontweight, 'major', True),
            'fmt key for the fontweight of the ticklabels of x- and y-axis of '
            'simple plots (i.e. without projection)'
        ],
        'plotter.plot2d.ctickweight': [
            None, validate_fontweight,
            'fmt key for the fontweight of the ticklabels of the colorbar of 2D '
            'plots'
        ],
        'plotter.plot2d.clabelweight': [
            None, validate_fontweight,
            'fmt key for the fontweight of the colorbar label'
        ],

        # text properties
        'plotter.baseplotter.titleprops':
        [{}, validate_dict,
         'fmt key for the additional properties of the title'],
        'plotter.baseplotter.figtitleprops':
        [{}, validate_dict,
         'fmt key for the additional properties of the figure title'],
        'plotter.simple.labelprops':
        [{},
         DictValValidator('labelprops', ['x', 'y'], validate_dict, None, True),
         'fmt key for the additional properties of the x- and y-label'],
        'plotter.simple.xtickprops': [
            {
                'major': {},
                'minor': {}
            },
            DictValValidator('xtickprops', ['major', 'minor'], validate_dict,
                             'major', True),
            'fmt key for the additional properties of the ticklabels of x-axis'
        ],
        'plotter.simple.ytickprops': [
            {
                'major': {},
                'minor': {}
            },
            DictValValidator('ytickprops', ['major', 'minor'], validate_dict,
                             'major', True),
            'fmt key for the additional properties of the ticklabels of y-axis'
        ],
        'plotter.plot2d.clabelprops':
        [{}, validate_dict,
         'fmt key for the additional properties of the colorbar label'],
        'plotter.plot2d.ctickprops':
        [{}, validate_dict,
         'fmt key for the additional properties of the colorbar ticklabels'],

        # mask formatoptions
        'plotter.baseplotter.maskleq': [
            None,
            try_and_error(validate_none, validate_float),
            'fmt key to mask values less or equal than a certain threshold'
        ],
        'plotter.baseplotter.maskless': [
            None,
            try_and_error(validate_none, validate_float),
            'fmt key to mask values less than a certain threshold'
        ],
        'plotter.baseplotter.maskgreater': [
            None,
            try_and_error(validate_none, validate_float),
            'fmt key to mask values greater than a certain threshold'
        ],
        'plotter.baseplotter.maskgeq': [
            None,
            try_and_error(validate_none, validate_float),
            'fmt key to mask values greater than or equal to a certain threshold'
        ],
        'plotter.baseplotter.maskbetween': [
            None,
            try_and_error(validate_none, validate_nseq_float(2)),
            'fmt key to mask values between a certain range'
        ],

        # density plotter
        'plotter.density.coord': [
            None,
            try_and_error(validate_none, validate_dataarray, validate_str,
                          validate_stringlist),
            'Alternative x-coordinate to use for DensityPlotter'
        ],
        'plotter.density.xrange': [
            'minmax', validate_limits,
            'The histogram limits of the density plot'
        ],
        'plotter.density.yrange': [
            'minmax', validate_limits,
            'The histogram limits of the density plot'
        ],
        'plotter.density.precision': [
            0,
            try_and_error(validate_float, ValidateList(float, 2), validate_str,
                          ValidateList(str, 2)),
            'The precision of the data to make sure that the bin width is not '
            'below this value'
        ],
        'plotter.density.bins': [
            10,
            try_and_error(validate_int, ValidateList(int, 2)),
            'The bins in x- and y-direction of the density plot'
        ],
        'plotter.density.normed': [
            None,
            try_and_error(
                validate_none,
                ValidateInStrings('normed', ['area', 'counts'], True)),
            'The normalization of the density histogram'
        ],
        'plotter.density.density':
        ['hist', ValidateInStrings('density', ['hist', 'kde'], True)],

        # axis color
        'plotter.simple.axiscolor': [
            None, validate_axiscolor,
            'fmt key to modify the color of the spines'
        ],

        # SimplePlot
        'plotter.line.coord': [
            None,
            try_and_error(validate_none, validate_dataarray, validate_str,
                          validate_stringlist),
            'Alternative x-coordinate to use for LinePlotter'
        ],
        'plotter.line.plot':
        ['-', validate_lineplot, 'fmt key to modify the line style'],
        'plotter.line.error': [
            'fill',
            try_and_error(ValidateInStrings('error', ['fill'], True),
                          validate_none),
            'The visualization type of the errors for line plots'
        ],
        'plotter.line.marker':
        [None, validate_marker, 'The symbol of the marker'],
        'plotter.line.markersize': [
            None,
            try_and_error(validate_none, validate_float),
            'The size of the marker'
        ],
        'plotter.line.linewidth': [
            None,
            try_and_error(validate_none, validate_float),
            'The widths of the lines'
        ],
        'plotter.line.erroralpha':
        [0.15, validate_alpha, 'The alpha value of the error range'],
        'plotter.bar.coord': [
            None,
            try_and_error(validate_none, validate_dataarray, validate_str,
                          validate_stringlist),
            'Alternative x-coordinate to use for BarPlotter'
        ],
        'plotter.bar.widths': [
            'equal',
            try_and_error(validate_float,
                          ValidateInStrings('widths', ['equal', 'data'],
                                            True)),
            'fmt key to change between equal and data given width of the bars'
        ],
        'plotter.bar.categorical': [
            None, validate_bool_maybe_none,
            'fmt key to change between categorical and non-categorical plotting'
        ],
        'plotter.bar.alpha': [
            1.0, validate_float,
            'fmt key to control the transparency for the bar plots'
        ],
        'plotter.bar.plot': [
            'bar', validate_lineplot,
            'fmt key to modify whether bar plots shall be stacked or not'
        ],
        'plotter.violin.plot': [
            True, validate_bool_maybe_none,
            'fmt key to modify whether violin plots shall be drawn'
        ],
        'plotter.simple.transpose':
        [False, validate_bool, 'fmt key to switch x- and y-axis'],
        'plotter.simple.color': [
            None,
            try_and_error(validate_none, validate_cmap, validate_iter),
            'fmt key to modify the color cycle simple plots'
        ],
        'plotter.simple.ylim':
        ['rounded', validate_limits, 'fmt key to specify the y-axis limits'],
        'plotter.simple.xlim':
        ['rounded', validate_limits, 'fmt key to specify the x-axis limits'],
        'plotter.simple.sym_lims': [
            None, validate_sym_lims,
            'fmt key to make symmetric x- and y-axis limits'
        ],
        'plotter.simple.xticks': [{
            'major': None,
            'minor': None
        },
                                  DictValValidator(
                                      'xticks', ['major', 'minor'],
                                      TicksValidator('xticks', tick_strings,
                                                     True), 'major', True),
                                  'fmt key to modify the x-axis ticks'],
        'plotter.simple.yticks': [{
            'major': None,
            'minor': None
        },
                                  DictValValidator(
                                      'yticks', ['major', 'minor'],
                                      TicksValidator('yticks', tick_strings,
                                                     True), 'major', True),
                                  'fmt key to modify the y-axis ticks'],
        'plotter.simple.xticklabels': [
            None,
            DictValValidator('xticklabels', ['major', 'minor'],
                             validate_ticklabels, 'major', True),
            'fmt key to modify the x-axis ticklabels'
        ],
        'plotter.simple.yticklabels': [
            None,
            DictValValidator('yticklabels', ['major', 'minor'],
                             validate_ticklabels, 'major', True),
            'fmt key to modify the y-axis ticklabels'
        ],
        'plotter.simple.xrotation': [
            0, validate_float,
            'fmt key to modify the rotation of the x-axis ticklabels'
        ],
        'plotter.simple.yrotation': [
            0, validate_float,
            'fmt key to modify the rotation of the x-axis ticklabels'
        ],
        'plotter.simple.legendlabels': [
            '%(arr_name)s',
            try_and_error(validate_str, ValidateList(six.text_type)),
            'fmt key to modify the legend labels'
        ],
        'plotter.simple.legend':
        [True, validate_legend, 'fmt key to draw a legend'],

        # FldmeanPlotter
        'plotter.fldmean.mean': [
            'mean',
            try_and_error(ValidateInStrings('mean', ['mean', 'median'], True),
                          validate_float),
            "The calculation result, either the 'mean', 'median' or a percentile"
        ],
        'plotter.fldmean.err_calc': [
            'std', validate_err_calc,
            "The error calculation method, either the 'std' or a minimum "
            "and maximum percentile"
        ],

        # Plot2D
        'plotter.plot2d.interp_bounds': [
            None, validate_bool_maybe_none,
            'Switch to interpolate the bounds for 2D plots'
        ],
        'plotter.plot2d.plot': [
            'mesh',
            try_and_error(
                validate_none,
                ValidateInStrings('2d plot', [
                    'mesh', 'contourf', 'contour', 'poly', 'tri',
                    'tricontourf', 'tricontour'
                ], True)),
            'fmt key to specify the plot type of 2D scalar plots'
        ],
        'plotter.plot2d.plot.min_circle_ratio': [
            0.05, validate_float,
            'fmt key to specify the min_circle_ratio that is used to mask very '
            ' flat triangles in a triangular plot'
        ],
        'plotter.plot2d.cbar':
        [['b'], validate_cbarpos,
         'fmt key to specify the position of the colorbar'],
        'plotter.plot2d.cbarspacing': [
            'uniform', validate_str,
            'fmt key to specify the spacing of the colorbar'
        ],
        'plotter.plot2d.miss_color': [
            None,
            try_and_error(validate_none, validate_color),
            'fmt key to specify the color of missing values'
        ],
        'plotter.plot2d.cmap':
        ['white_blue_red', validate_cmap, 'fmt key to specify the colormap'],
        'plotter.plot2d.cticks': [
            None,
            try_and_error(
                validate_none,
                BoundsValidator('bounds', ['bounds'] + bound_strings,
                                True,
                                default='bounds')),
            'fmt key to specify the ticks of the colorbar'
        ],
        'plotter.plot2d.cticklabels': [
            None, validate_ticklabels,
            'fmt key to specify the ticklabels of the colorbar'
        ],
        'plotter.plot2d.extend': [
            'neither', validate_extend,
            'fmt key to specify the style of the colorbar on minimum and maximum'
        ],
        'plotter.plot2d.bounds': [
            'rounded',
            BoundsValidator(
                'bounds', bound_strings, True, inis=mpl.colors.Normalize),
            'fmt key to specify bounds and norm of the colorbar'
        ],
        'plotter.plot2d.levels': [
            None,
            BoundsValidator('levels', bound_strings, True),
            'fmt key to specify the levels for a contour plot'
        ],
        # TODO: Implement opacity
        # 'plotter.plot2d.opacity': [None, try_and_error(validate_none,
        #                                                validate_opacity)],
        'plotter.plot2d.datagrid': [
            None,
            try_and_error(validate_none, validate_dict, validate_str),
            'fmt key to plot the lines of the data grid'
        ],

        # VectorPlot
        'plotter.vector.plot': [
            'quiver',
            try_and_error(
                validate_none,
                ValidateInStrings('2d plot', ['quiver', 'stream'], True)),
            'fmt key for the plot type of vector plots'
        ],
        'plotter.vector.arrowsize': [
            None,
            try_and_error(validate_none, validate_float),
            'fmt key for the size of the arrows on vector plots'
        ],
        'plotter.vector.arrowstyle': [
            '-|>',
            ValidateInStrings('arrowstyle', ArrowStyle._style_list),
            'fmt key for the style of the arrows on stream plots'
        ],
        'plotter.vector.density': [
            1.0,
            try_and_error(validate_float, ValidateList(float, 2)),
            'fmt key for the density of arrows on a vector plot'
        ],
        'plotter.vector.linewidth': [
            None,
            LineWidthValidator('linewidth', ['absolute', 'u', 'v'], True),
            'fmt key for the linewidths of the arrows'
        ],
        'plotter.vector.color': [
            'k',
            try_and_error(
                validate_float, validate_color,
                ValidateInStrings('color', ['absolute', 'u', 'v'], True)),
            'fmt key for the colors of the arrows'
        ],

        # default texts
        'texts.labels': [
            {
                'tinfo': '%H:%M',
                'dtinfo': '%B %d, %Y. %H:%M',
                'dinfo': '%B %d, %Y',
                'desc': '%(long_name)s [%(units)s]',
                'sdesc': '%(name)s [%(units)s]'
            }, validate_dict,
            'labels that shall be replaced in TextBase formatoptions',
            ' (e.g. the title formatoption) when inserted within '
            'curly braces ({}))'
        ],
        'texts.default_position': [(1., 1.),
                                   validate_nseq_float(2),
                                   'default position for the text fmt key'],
        'texts.delimiter': [
            ', ', validate_str,
            'default delimiter to separate netCDF meta attributes '
            'when displayed on the plot'
        ],

        # -------------------------------------------------------------------------
        # ---------------------------- Miscallaneous ------------------------------
        # -------------------------------------------------------------------------

        # color lists for user-defined colormaps (see for example
        # psy_simple.colors._cmapnames)
        'colors.cmaps':
        [{}, validate_cmaps,
         'User defined color lists that shall be accessible through the '
         ':meth:`psyplot.plotter.colors.get_cmap` function'],
        'ticks.which': [
            'major',
            ValidateInStrings('ticks.which', ['major', 'minor'], True),
            'default tick that is used when using a x- or y-tick formatoption'
        ],
    })
Example #7
0
rcParams = RcParams(defaultParams={

    # -------------------------------------------------------------------------
    # ----------------------- Registered plotters -----------------------------
    # -------------------------------------------------------------------------

    'project.plotters': [

        {'linreg': {
             'module': 'psy_reg.plotters',
             'plotter_name': 'LinRegPlotter',
             'prefer_list': True,
             'default_slice': None,
             'summary': 'Draw a fit from x to y'},
         'densityreg': {
             'module': 'psy_reg.plotters',
             'plotter_name': 'DensityRegPlotter',
             'prefer_list': False,
             'default_slice': None,
             'summary': ('Make a density plot and draw a fit from x to y of '
                         'points')},
         }, validate_dict],

    # -------------------------------------------------------------------------
    # --------------------- Default formatoptions -----------------------------
    # -------------------------------------------------------------------------
    # Linear regression
    'plotter.linreg.xrange': [
        'minmax', validate_limits, 'The fit limits of the line plot'],
    'plotter.linreg.yrange': [
        'minmax', validate_limits, 'The fit limits of the line plot'],
    'plotter.linreg.line_xlim': [
        'minmax', validate_line_xlim,
        'The x-limits of the drawn best fit line'],
    'plotter.linreg.param_bounds': [
        None, validate_param_bounds,
        'fmt key to specify the boundaries of the fit'],
    'plotter.linreg.p0': [
        'auto', validate_p0,
        'fmt key to specify the initial parameters of the fit'],
    'plotter.linreg.fix': [
        None, validate_fix,
        'fmt key to set a fix point for the linear regression fit'],
    'plotter.linreg.fit': [
        'fit', validate_fit, 'The model to use for fitting a model'],
    'plotter.linreg.nboot': [
        1000, validate_int,
        'Number of bootstrap resamples to estimate the confidence interval'],
    'plotter.linreg.ci': [
        95, try_and_error(validate_none, validate_float),
        'Size of the confidence interval'],
    'plotter.linreg.id_color': [
        None, psyps_rc.validate['plotter.simple.color'],
        'fmt key to modify the color cycle of the ideal lines in a fit plot'],
    'plotter.linreg.ideal': [
        None, validate_ideal,
        'The ideal lines to plot'],
    'plotter.linreg.bootstrap.random_seed': [
        None, try_and_error(validate_none, validate_int),
        'The seed to use for the bootstrap algorithm to estimate the '
        'confidence interval'],

    # combined density and linear regression plot
    'plotter.densityreg.lineplot': [
        '-', try_and_error(validate_none, validate_str,
                           validate_stringlist),
        'fmt key to modify the line style'],
    })
Example #8
0
        'backend is used and no changes are made. Note that it is usually not '
        'possible to change the backend after importing the psyplot.project '
        'module. The default backend embeds the figures into the '],
    'help_explorer.use_intersphinx': [
        False, validate_bool_maybe_none,
        'Use the intersphinx extension and link to the online documentations '
        'of matplotlib, pyplot, psyplot, numpy, etc. when converting rst '
        'docstrings. The inventories are loaded when the first object is '
        'documented. If None, intersphinx is only used with PyQt5'],
    'console.connect_to_help': [
        True, validate_bool,
        'Whether the console shall be connected to the help_explorer or not'],
    'console.auto_set_mp': [
        True, validate_bool,
        "If True, then the 'mp' variable in the console is automatically set "
        "when the current main project changes"],
    'console.auto_set_sp': [
        True, validate_bool,
        "If True, then the 'sp' variable in the console is automatically set "
        "when the current sub project changes"],
    'main.open_files_port': [
        30124, validate_int, "The port number used when new files are opened"],
    }

#: :class:`~psyplot.config.rcsetup.RcParams` instance that stores default
#: formatoptions and configuration settings.
rcParams = RcParams()
rcParams.defaultParams = defaultParams
rcParams.update({key: val[0] for key, val in defaultParams.items()})
rcParams.load_from_file()
Example #9
0
from psyplot.config.rcsetup import RcParams, validate_bool, validate_dict
from psyplot_gui.common import DockMixin
from psyplot_gui.compat.qtcompat import QWidget, Qt


class W1(QWidget, DockMixin):
    title = 'w1'
    dock_position = Qt.LeftDockWidgetArea


class W2(QWidget, DockMixin):
    title = 'w2'
    dock_position = Qt.BottomDockWidgetArea
    hidden = True


rcParams = RcParams(
    defaultParams={
        'test_plugin': [True, validate_bool],
        'project.plotters': [
            {'gui_test_plotter': {
                'module': 'psyplot_gui_test.plotter',
                'plotter_name': 'TestPlotter', 'import_plotter': True}},
            validate_dict]})
rcParams.update_from_defaultParams()
Example #10
0
rcParams = RcParams(
    defaultParams={

        # -------------------------------------------------------------------------
        # ----------------------- Registered plotters -----------------------------
        # -------------------------------------------------------------------------
        'project.plotters': [{
            'maps': {
                'module': 'psy_maps.plotters',
                'plotter_name': 'MapPlotter',
                'plot_func': False,
                'summary': 'The data objects visualized on a map'
            },
            'mapplot': {
                'module': 'psy_maps.plotters',
                'plotter_name': 'FieldPlotter',
                'prefer_list': False,
                'default_slice': 0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': 'Plot a 2D scalar field on a map'
            },
            'mapvector': {
                'module': 'psy_maps.plotters',
                'plotter_name': 'VectorPlotter',
                'prefer_list': False,
                'default_slice': 0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': 'Plot a 2D vector field on a map',
                'example_call': "filename, name=[['u_var', 'v_var']], ..."
            },
            'mapcombined': {
                'module':
                'psy_maps.plotters',
                'plotter_name':
                'CombinedPlotter',
                'prefer_list':
                True,
                'default_slice':
                0,
                'default_dims': {
                    'x': slice(None),
                    'y': slice(None)
                },
                'summary': ('Plot a 2D scalar field with an overlying vector '
                            'field on a map'),
                'example_call':
                ("filename, name=[['my_variable', ['u_var', 'v_var']]], ...")
            },
        }, validate_dict],

        # -------------------------------------------------------------------------
        # --------------------- Default formatoptions -----------------------------
        # -------------------------------------------------------------------------
        # MapBase
        'plotter.maps.lonlatbox': [
            None, validate_lonlatbox,
            'fmt key to define the longitude latitude box of the data'
        ],
        'plotter.maps.map_extent': [
            None, validate_lonlatbox,
            'fmt key to define the extent of the map plot'
        ],
        'plotter.maps.clip': [
            None, validate_bool_maybe_none,
            'fmt key to define clip the axes outside the latitudes'
        ],
        'plotter.maps.clon': [
            None,
            try_and_error(validate_none, validate_float, validate_str),
            'fmt key to specify the center longitude of the projection'
        ],
        'plotter.maps.clat': [
            None,
            try_and_error(validate_none, validate_float, validate_str),
            'fmt key to specify the center latitude of the projection'
        ],
        # TODO: Implement the drawing of shape files on a map
        # 'plotter.maps.lineshapes': [None, try_and_error(
        #     validate_none, validate_dict, validate_str, validate_stringlist)],
        'plotter.maps.grid_labels': [
            None, validate_bool_maybe_none,
            'fmt key to draw labels of the lat-lon-grid'
        ],
        'plotter.maps.grid_labelsize': [
            12.0, validate_fontsize,
            'fmt key to modify the fontsize of the lat-lon-grid labels'
        ],
        'plotter.maps.grid_color': [
            'k',
            try_and_error(validate_none, validate_color),
            'fmt key to modify the color of the lat-lon-grid'
        ],
        'plotter.maps.grid_settings':
        [{}, validate_dict,
         'fmt key for additional line properties for the lat-lon-grid'],
        'plotter.maps.xgrid':
        [True, validate_grid, 'fmt key for drawing meridians on the map'],
        'plotter.maps.ygrid':
        [True, validate_grid, 'fmt key for drawing parallels on the map'],
        'plotter.maps.projection': [
            'cyl',
            ProjectionValidator('projection', [
                'northpole', 'ortho', 'southpole', 'moll', 'geo', 'robin',
                'cyl', 'stereo', 'near'
            ], True), 'fmt key to define the projection of the plot'
        ],
        'plotter.maps.transform': [
            'cyl',
            ProjectionValidator('projection', [
                'northpole', 'ortho', 'southpole', 'moll', 'geo', 'robin',
                'cyl', 'stereo', 'near'
            ], True), 'fmt key to define the native projection of the data'
        ],
        'plotter.maps.lsm':
        [True, validate_lsm, 'fmt key to draw a land sea mask'],
        'plotter.maps.stock_img':
        [False, validate_bool, 'fmt key to draw a stock_img on the map'],

        # -------------------------------------------------------------------------
        # ---------------------------- Miscallaneous ------------------------------
        # -------------------------------------------------------------------------

        # yaml file that holds definitions of lonlatboxes
        'lonlatbox.boxes':
        [{}, validate_dict_yaml,
         'longitude-latitude boxes that shall be accessible for the lonlatbox, '
         'map_extent, etc. keywords. May be a dictionary or the path to a '
         'yaml file'],
    })
Example #11
0
# 2. the validation function of type conversion function
# 3. a short description of the default value
#
# Example::
#
#     defaultParams = {'my.key': [True, bool, 'What my key does']}
defaultParams = {

    # key for defining new plotters
    'project.plotters': [
        {'plot_method_identifer': {
             'module': 'PLUGIN_PYNAME.plotters',
             'plotter_name': 'MyPlotter',   # or any other name
             # any other item for the :func:`psyplot.project.register_plotter`
             # function
             # 'plot_func': False,
             # 'prefer_list': True,
             # ...
             },
         }, dict, "The plot methods in the PLUGIN_NAME package"],
    # if you define new plotters, we recommend to assign a specific rcParams
    # key for it, e.g.
    # 'plotter.PLUGIN_PYNAME.my_fmt': [1, int, ' the value for my_fmt']
    }

# create the rcParams and populate them with the defaultParams. For more
# information on this class, see the :class:`psyplot.config.rcsetup.RcParams`
# class
rcParams = RcParams(defaultParams=defaultParams)
rcParams.update_from_defaultParams()
Example #12
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LGPL-3.0 license for more details.
#
# You should have received a copy of the GNU LGPL-3.0 license
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

from psyplot.config.rcsetup import RcParams, validate_dict

plugin_version = '1.0.0'

rcParams = RcParams(
    defaultParams={
        'test': [1, lambda i: int(i)],
        'project.plotters': [{
            'test_plotter': {
                'module': 'psyplot_test.plotter',
                'plotter_name': 'TestPlotter',
                'import_plotter': True
            }
        }, validate_dict]
    })
rcParams.update_from_defaultParams()

patch_check = []

checking_patch = False


def test_patch(plotter_d, versions):
    if not checking_patch:
        raise ValueError("Accidently applied the patch!")