Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta load netcdf bug #63

Merged
merged 4 commits into from
Dec 13, 2021
Merged

Meta load netcdf bug #63

merged 4 commits into from
Dec 13, 2021

Conversation

aburrell
Copy link
Member

@aburrell aburrell commented Dec 9, 2021

Description

Found a bug when running data validation that revealed meta data available in the netCDF4 files was not being loaded for the coordinates.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-0f94a05e9ffd> in <module>
----> 1 (pairs, pairs_meta, inst_dat, mod_dat, inst_loc) = sami3_val.pair_sami3_inst(stime, etime, inst_name, mod_prefix,
      2                                     user=user, password=password,
      3                                     skip_download=skip_download,
      4                                     mod_dir=mod_dir, data_dir=data_dir,
      5                                     data_type=data_type, comp_clean=comp_clean)

~/Programs/Models/SAMI3/tools/sami3_validation_rout.py in pair_sami3_inst(stime, etime, inst_name, mod_prefix, user, password, skip_download, mod_dir, data_dir, data_type, comp_clean)
    299                     'exb_mer': 'u1p'}
    300 
--> 301     inst_sami = pm_utils.match.collect_inst_model_pairs(
    302         stime, etime, tinc, inst,
    303         inst_download_kwargs={'skip_download': skip_download},

~/Programs/Git/pysatModels/pysatModels/utils/match.py in collect_inst_model_pairs(start, stop, tinc, inst, inst_download_kwargs, model_load_rout, model_load_kwargs, inst_clean_rout, inst_lon_name, mod_lon_name, lon_pos, inst_name, mod_name, mod_datetime_name, mod_time_name, mod_units, sel_name, time_method, pair_method, method, model_label, comp_clean)
    219 
    220             if not inst.empty and np.any(inst.index >= istart):
--> 221                 added_names = extract.extract_modelled_observations(
    222                     inst=inst, model=mdata, inst_name=inst_name,
    223                     mod_name=mod_name, mod_datetime_name=mod_datetime_name,

~/Programs/Git/pysatModels/pysatModels/utils/extract.py in extract_modelled_observations(inst, model, inst_name, mod_name, mod_datetime_name, mod_time_name, mod_units, sel_name, time_method, pair_method, method, model_label, model_units_attr)
    807         long_units = re.split(r"\W+|_",
    808                               inst.meta[iname, inst.meta.labels.units])[0]
--> 809         inst_scale[i] = pyutils.scale_units(mod_units[i], long_units)
    810 
    811     # Determine the model time resolution

~/Programs/Git/pysat/pysat/utils/_core.py in scale_units(out_unit, in_unit)
    100 
    101     if in_key not in accepted_units.keys():
--> 102         raise ValueError('Unknown input unit {:}'.format(in_unit))
    103 
    104     if out_key in ['m', 'm/s', 'm-3'] or in_key in ['m', 'm/s', 'm-3']:

ValueError: Unknown input unit 

The unknown in put unit was a blank string, but the file has the data present:

$ ncdump gps130102g.002.netCDF4 | more
netcdf gps130102g.002 {
dimensions:
        timestamps = 288 ;
        gdlat = 180 ;
        glon = 360 ;
variables:
        double timestamps(timestamps) ;
                timestamps:units = "Unix seconds" ;
                timestamps:description = "Number of seconds since UT midnight 1970-01-01" ;
        double gdlat(gdlat) ;
                gdlat:units = "deg" ;
                gdlat:description = "Geodetic latitude of measurement" ;

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Rerunning the code that originally raised the error. Also:

import pysat
import pysatMadrigal as py_mad

tec = pysat.Instrument(inst_module=py_mad.instruments.gnss_tec, tag='vtec')
tec.load(2013, 2)

tec.meta['gdlat']

The fixed code yields:

units                                                      deg
long_name                                                gdlat
notes        Catalog information from record 0:KRECC       ...
desc                          Geodetic latitude of measurement
value_min                                                -90.0
value_max                                                 90.0
fill                                                       NaN
children                                                  None
Name: gdlat, dtype: object

Test Configuration

  • Operating system: OS X Mojave
  • Version number: Python 3.8
  • Any details about your local setup that are relevant

Checklist:

  • Make sure you are merging into the develop (not main) branch
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have linted the files updated in this pull request
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • Add a note to CHANGELOG.md, summarizing the changes

If this is a release PR, replace the first item of the above checklist with the
release checklist on the pysat wiki:
https://github.com/pysat/pysat/wiki/Checklist-for-Release

Load both the coordinate and data variable meta data from netCDF4 files.
Updated the instrument unit test docstring format.
Allow file to lack meta data, setting values to defaults.
Expanded the load tests to have variables with and without meta data.
Copy link
Collaborator

@rstoneback rstoneback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aburrell!

@aburrell aburrell merged commit a120e18 into develop Dec 13, 2021
@aburrell aburrell deleted the meta_load_netcdf_bug branch December 13, 2021 14:15
@aburrell aburrell added this to the 0.1.0 Release milestone Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants