Skip to content

Commit

Permalink
Merge pull request #110 from pysat/bug/97
Browse files Browse the repository at this point in the history
BUG: GOLD metadata
  • Loading branch information
jklenzing committed Jul 26, 2022
2 parents fb2e29f + dc5b354 commit 968a03a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [0.0.4] - 2022-XX-XX
* Bug Fixes
* Fixed a bug in metadata when loading GOLD Nmax data.
* Fixed a bug in user feedback for `methods.cdaweb.download`
* Maintenance
* Reduce duplication of code in instrument modules

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Python 3.7+.
| Common modules | Community modules |
| -------------- | ----------------- |
| beautifulsoup4 | cdflib |
| lxml | pysat |
| lxml | pysat>=3.0.2 |
| netCDF4 | |
| numpy | |
| pandas | |
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Python 3.7+ and pysat 3.0.0+.
Common modules Community modules
================ =================
beautifulsoup4 cdflib>=0.4.4
lxml pysat>=3.0.0
lxml pysat>=3.0.2
netCDF4
numpy
pandas
Expand Down
2 changes: 1 addition & 1 deletion pysatNASA/instruments/methods/cdaweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def download(date_array, tag=None, inst_id=None, supported_tags=None,
logger.info(' '.join(('File not available for',
date.strftime('%d %B %Y'))))
except requests.exceptions.RequestException as exception:
logger.info(' '.join((exception, '- File not available for',
logger.info(' '.join((str(exception), '- File not available for',
date.strftime('%d %B %Y'))))
return

Expand Down
41 changes: 34 additions & 7 deletions pysatNASA/instruments/ses14_gold.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@

import datetime as dt
import functools
import numpy as np

from pysat.instruments.methods import general as ps_gen
from pysat import logger
from pysat.utils import load_netcdf4
from pysat.utils.io import load_netcdf

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import general as mm_nasa
Expand Down Expand Up @@ -155,22 +156,48 @@ def load(fnames, tag=None, inst_id=None):
--------
::
inst = pysat.Instrument('gold', 'nmax')
inst = pysat.Instrument('ses14', 'gold', tag='nmax')
inst.load(2019, 1)
"""

data, meta = load_netcdf4(fnames, pandas_format=pandas_format)
labels = {'units': ('Units', str), 'name': ('Long_Name', str),
'notes': ('Var_Notes', str), 'desc': ('CatDesc', str),
'plot': ('plot', str), 'axis': ('axis', str),
'scale': ('scale', str),
'min_val': ('Valid_Min', np.float64),
'max_val': ('Valid_Max', np.float64),
'fill_val': ('fill', np.float64)}

# Generate custom meta translation table. When left unspecified the default
# table handles the multiple values for fill. We must recreate that
# functionality in our table. The targets for meta_translation should
# map to values in `labels` above.
meta_translation = {'FIELDNAM': 'plot', 'LABLAXIS': 'axis',
'ScaleTyp': 'scale', 'VALIDMIN': 'Valid_Min',
'Valid_Min': 'Valid_Min', 'VALIDMAX': 'Valid_Max',
'Valid_Max': 'Valid_Max', '_FillValue': 'fill',
'FillVal': 'fill', 'TIME_BASE': 'time_base'}

data, meta = load_netcdf(fnames, pandas_format=pandas_format,
epoch_name='nscans', labels=labels,
meta_translation=meta_translation,
drop_meta_labels='FILLVAL')

if tag == 'nmax':
# Add time coordinate from scan_start_time
data['time'] = ('nscans',
[dt.datetime.strptime(str(val), "b'%Y-%m-%dT%H:%M:%SZ'")
for val in data['scan_start_time'].values])
data = data.swap_dims({'nscans': 'time'})
data['time'] = [dt.datetime.strptime(str(val), "b'%Y-%m-%dT%H:%M:%SZ'")
for val in data['scan_start_time'].values]

# Update coordinates with dimensional data
data = data.assign_coords({'nlats': data['nlats'],
'nlons': data['nlons'],
'nmask': data['nmask'],
'channel': data['channel'],
'hemisphere': data['hemisphere']})
meta['time'] = {meta.labels.notes: 'Converted from scan_start_time'}
meta['nlats'] = {meta.labels.notes: 'Index for latitude values'}
meta['nlons'] = {meta.labels.notes: 'Index for longitude values'}
meta['nmask'] = {meta.labels.notes: 'Index for mask values'}

return data, meta
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ lxml
cdflib>=0.4.4
numpy
pandas
pysat>=3.0.0
pysat>=3.0.2
xarray

0 comments on commit 968a03a

Please sign in to comment.