Skip to content

Commit

Permalink
Merge pull request #24 from pysat/meta_fix
Browse files Browse the repository at this point in the history
BUG: netCDF4 file compatibility
  • Loading branch information
rstoneback committed Oct 21, 2020
2 parents 00c3e3b + ba8b429 commit 4f1136c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [0.?.?] - 2020-07-03
- Added coords from pysat.utils
- Bug Fix
- Updated madrigal methods to simplify compound data types and enable
creation of netCDF4 files using `Instrument.to_netcdf4()`.

## [0.0.3] - 2020-06-15
- pypi compatibility
Expand Down
17 changes: 13 additions & 4 deletions pysatMadrigal/instruments/methods/madrigal.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ def load(fnames, tag=None, inst_id=None, xarray_coords=[]):
file_meta = filed['Metadata']['Data Parameters']
# load up what is offered into pysat.Meta
meta = pysat.Meta()
meta.info = {'acknowledgements':
' '.join(["See 'meta.Experiment_Notes' for instrument",
"specific acknowledgements\n", cedar_rules()]),
'references': "See 'meta.Experiment_Notes' for references"}

labels = []
for item in file_meta:
# handle difference in string output between python 2 and 3
Expand All @@ -115,6 +112,18 @@ def load(fnames, tag=None, inst_id=None, xarray_coords=[]):
for key in filed['Metadata']:
if key != 'Data Parameters':
setattr(meta, key.replace(' ', '_'), filed['Metadata'][key][:])

# Update formatting of madrigal experiment information since
# netcdf4 doesn't recommend compound data types.
mad_vars = [('Experiment_Parameters', ': '),
('Independent_Spatial_Parameters', ': '),
('Experiment_Notes', '')]
for mad_var in mad_vars:
snips = [[snip.decode('UTF-8') for snip in items] for items in
getattr(meta, mad_var[0])]
snips = [mad_var[1].join(snip) for snip in snips]
setattr(meta, mad_var[0], snips)

# data into frame, with labels from metadata
data = pds.DataFrame.from_records(file_data, columns=labels)
# lowercase variable names
Expand Down

0 comments on commit 4f1136c

Please sign in to comment.