pysat / pysatMadrigal

Madrigal instrument support for the pysat ecosystem
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Meta load netcdf bug #63

Closed aburrell closed 2 years ago

aburrell commented 2 years ago

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.

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

Checklist:

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