Skip to content

Commit

Permalink
Try to do a better job filling in missing data dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilburlewis committed Jul 21, 2024
1 parent b369a3e commit f62d4aa
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pytplot/store_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ def store_data(name, data=None, delete=False, newname=None, attr_dict={}):
else:
spec_bins = None
# Provide another dimension if values are more than 1 dimension
if len(values.shape) > 1:
if len(values.shape) == 2:
data['v'] = None
if len(values.shape) > 2:
data['v1'] = None
data['v2'] = None
if len(values.shape) > 3:
data['v3'] = None
Expand All @@ -278,6 +279,37 @@ def store_data(name, data=None, delete=False, newname=None, attr_dict={}):
coordinate_list = sorted(list(data.keys()))
dimension_list = [d + '_dim' for d in coordinate_list]

if len(coordinate_list) < len(values.shape)-1:
logging.warning("store_data: Data array for variable %s has %d dimensions, but only %d v_n keys plus time. Adding empty v_n keys.", name, len(values.shape), len(coordinate_list))
if len(values.shape) == 2:
data['v'] = None
elif len(values.shape) == 3:
if 'v' in data:
vdat = data.pop('v')
data['v1'] = vdat
data['v2'] = None
else:
data['v1'] = None
data['v2'] = None
elif len(values.shape) == 3:
if 'v' in data:
vdat = data.pop('v')
data['v1'] = vdat
data['v2'] = None
data['v3'] = None
else:
if 'v1' not in data:
data['v1'] = None
if 'v2' not in data:
data['v2'] = None
if 'v3' not in data:
data['v3'] = None
coordinate_list = sorted(list(data.keys()))
dimension_list = [d + '_dim' for d in coordinate_list]
# Don't try to use these dimensions as coordinates
spec_bins_exist = False
spec_bins = None

# Ignore warnings about cdflib non-nanosecond precision timestamps for now
with warnings.catch_warnings():
warnings.filterwarnings("ignore",message="^.*non-nanosecond precision.*$")
Expand All @@ -286,9 +318,10 @@ def store_data(name, data=None, delete=False, newname=None, attr_dict={}):
coords={'time': ('time', times)})
except ValueError as err:
logging.warning("store_data: ValueError trying to set xarray coordinates for variable %s: %s", name, str(err))
spec_bins_exist = False
spec_bins = None
if len(times) == 1:
logging.warning("store_data: This is possibly due to the leading data dimension being lost in an array-valued or vector-valued variable with a single timestamp.")
return

if spec_bins_exist:
try:
Expand Down

0 comments on commit f62d4aa

Please sign in to comment.