Skip to content

Commit f089ba5

Browse files
committed
Added concat_dim command line and plot method parameter
1 parent f46853a commit f089ba5

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Added
55
* The yaxis_inverted and xaxis_inverted is now considered when loading and
66
saving a matplotlib axes
77
* Added the `seaborn-style` command line argument
8+
* Added the `concat_dim` command line argument
89

910

1011
v1.0.0

‎psyplot/__main__.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from itertools import chain
66
from collections import defaultdict
77
import yaml
8+
import xarray as xr
89
import psyplot
910
from psyplot.docstring import docstrings
1011
from psyplot.warning import warn
12+
from psyplot.compat.pycompat import get_default_value
1113
from funcargparse import FuncArgParser
1214
import logging
1315

@@ -47,7 +49,8 @@ def main(args=None):
4749
def make_plot(fnames=[], name=[], dims=None, plot_method=None,
4850
output=None, project=None, engine=None, formatoptions=None,
4951
tight=False, rc_file=None, encoding=None, enable_post=False,
50-
seaborn_style=None):
52+
seaborn_style=None,
53+
concat_dim=get_default_value(xr.open_mfdataset, 'concat_dim')):
5154
"""
5255
Eventually start the QApplication or only make a plot
5356
@@ -93,6 +96,9 @@ def make_plot(fnames=[], name=[], dims=None, plot_method=None,
9396
seaborn_style: str
9497
The name of the style of the seaborn package that can be used for
9598
the :func:`seaborn.set_style` function
99+
concat_dim: str
100+
The concatenation dimension if multiple files in `fnames` are
101+
provided
96102
"""
97103
if project is not None and (name != [] or dims is not None):
98104
warn('The `name` and `dims` parameter are ignored if the `project`'
@@ -134,7 +140,7 @@ def make_plot(fnames=[], name=[], dims=None, plot_method=None,
134140
raise ValueError("Unknown plot method %s!" % plot_method)
135141
p = pm(
136142
fnames, name=name, dims=dims or {}, engine=engine,
137-
fmt=formatoptions or {}, mf_mode=True)
143+
fmt=formatoptions or {}, mf_mode=True, concat_dim=concat_dim)
138144
p.export(output, tight=tight)
139145
return
140146

@@ -244,6 +250,8 @@ def get_parser(create=True):
244250

245251
parser.update_arg('seaborn_style', short='sns')
246252

253+
parser.update_arg('concat_dim', short='cd')
254+
247255
if create:
248256
parser.create_arguments()
249257

‎psyplot/compat/pycompat.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
That's a test"""
44
import os
55
import six
6+
import inspect
67

78
if six.PY3:
89

@@ -23,6 +24,12 @@ def iterkeys(d):
2324
def getcwd(*args, **kwargs):
2425
return os.getcwd(*args, **kwargs)
2526

27+
def get_default_value(func, arg):
28+
argspec = inspect.getfullargspec(func)
29+
return next(default for a, default in zip(reversed(argspec[0]),
30+
reversed(argspec.defaults))
31+
if a == arg)
32+
2633
basestring = str
2734
unicode_type = str
2835
bytes_type = bytes
@@ -56,6 +63,12 @@ def iterkeys(d):
5663
def getcwd(*args, **kwargs):
5764
return os.getcwdu(*args, **kwargs)
5865

66+
def get_default_value(func, arg):
67+
argspec = inspect.getargspec(func)
68+
return next(default for a, default in zip(reversed(argspec[0]),
69+
reversed(argspec.defaults))
70+
if a == arg)
71+
5972
basestring = basestring
6073
unicode_type = unicode
6174
bytes_type = str

‎psyplot/project.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import six
1313
from copy import deepcopy as _deepcopy
1414
import logging
15+
import inspect
1516
import pickle
1617
from importlib import import_module
1718
from itertools import chain, repeat, cycle, count
@@ -33,7 +34,8 @@
3334
ArrayList, open_dataset, open_mfdataset, _MissingModule,
3435
to_netcdf, Signal, CFDecoder, safe_list, InteractiveList)
3536
from psyplot.plotter import unique_everseen, Plotter
36-
from psyplot.compat.pycompat import OrderedDict, range, getcwd
37+
from psyplot.compat.pycompat import (OrderedDict, range, getcwd,
38+
get_default_value as _get_default_value)
3739
try:
3840
from cdo import Cdo as _CdoBase
3941
with_cdo = True
@@ -62,6 +64,9 @@
6264
_versions = get_versions(requirements=False)
6365

6466

67+
_concat_dim_default = _get_default_value(xarray.open_mfdataset, 'concat_dim')
68+
69+
6570
def _update_versions():
6671
"""Update :attr:`_versions` with the registered plotter methods"""
6772
for pm_name in plot._plot_methods:
@@ -410,13 +415,16 @@ def close(self, figs=True, data=False, ds=False):
410415
docstrings.delete_params('ArrayList.from_dataset.parameters', 'base')
411416
docstrings.delete_kwargs('ArrayList.from_dataset.other_parameters',
412417
kwargs='kwargs')
418+
docstrings.keep_params('xarray.open_mfdataset.parameters', 'concat_dim')
413419

414420
@_only_main
415421
@docstrings.get_sectionsf('Project._add_data')
416422
@docstrings.dedent
417423
def _add_data(self, plotter_cls, filename_or_obj, fmt={}, make_plot=True,
418424
draw=None, mf_mode=False, ax=None, engine=None, delete=True,
419-
share=False, clear=False, enable_post=None, *args, **kwargs):
425+
share=False, clear=False, enable_post=None,
426+
concat_dim=_concat_dim_default,
427+
*args, **kwargs):
420428
"""
421429
Extract data from a dataset and visualize it with the given plotter
422430
@@ -465,6 +473,8 @@ def _add_data(self, plotter_cls, filename_or_obj, fmt={}, make_plot=True,
465473
enabled and post processing scripts are allowed. If ``None``, this
466474
parameter is set to True if there is a value given for the `post`
467475
formatoption in `fmt` or `kwargs`
476+
%(xarray.open_mfdataset.parameters.concat_dim)s
477+
This parameter only does have an effect if `mf_mode` is True.
468478
%(ArrayList.from_dataset.parameters.no_base)s
469479
470480
Other Parameters
@@ -476,7 +486,8 @@ def _add_data(self, plotter_cls, filename_or_obj, fmt={}, make_plot=True,
476486
if not isinstance(filename_or_obj, xarray.Dataset):
477487
if mf_mode:
478488
filename_or_obj = open_mfdataset(filename_or_obj,
479-
engine=engine)
489+
engine=engine,
490+
concat_dim=concat_dim)
480491
else:
481492
filename_or_obj = open_dataset(filename_or_obj,
482493
engine=engine)

0 commit comments

Comments
 (0)