diff --git a/pyglider/ncprocess.py b/pyglider/ncprocess.py index 8995298..1278b38 100644 --- a/pyglider/ncprocess.py +++ b/pyglider/ncprocess.py @@ -312,7 +312,7 @@ def make_gridfiles(inname, outdir, deploymentyaml, *, fnamesuffix='', dz=1, star # https://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/aphs06.html dsout.attrs['featureType'] = 'trajectoryProfile' dsout['profile'].attrs['cf_role'] = 'profile_id' - dsout['mission_number'] = int32(1) + dsout['mission_number'] = np.int32(1) dsout['mission_number'].attrs['cf_role'] = 'trajectory_id' dsout = dsout.set_coords(['latitude', 'longitude', 'time']) for k in dsout: diff --git a/pyglider/slocum.py b/pyglider/slocum.py index f8fb947..c290cb1 100644 --- a/pyglider/slocum.py +++ b/pyglider/slocum.py @@ -789,7 +789,8 @@ def raw_to_timeseries(indir, outdir, deploymentyaml, *, def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *, search='*.[D|E]BD', fnamesuffix='', time_base='sci_water_temp', profile_filt_time=100, - profile_min_time=300, maxgap=300): + profile_min_time=300, maxgap=300, + replace_attrs=None): """ Convert directly from binary files to netcdf timeseries file. Requires dbdreader to be installed. @@ -821,6 +822,11 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *, profile_min_time : float minimum time to consider a profile an actual profile (seconds) + replace_attrs : dict or None + replace global attributes in the metadata after reading the metadata + file in. Helpful when processing runs with only a couple things that + change. + Returns ------- outname : string @@ -831,6 +837,9 @@ def binary_to_timeseries(indir, cachedir, outdir, deploymentyaml, *, raise ImportError('Cannot import dbdreader') deployment = utils._get_deployment(deploymentyaml) + if replace_attrs: + for att in replace_attrs: + deployment['metadata'][att] = replace_attrs[att] ncvar = deployment['netcdf_variables'] device_data = deployment['glider_devices'] diff --git a/pyglider/utils.py b/pyglider/utils.py index d3de10a..0f1b996 100644 --- a/pyglider/utils.py +++ b/pyglider/utils.py @@ -29,11 +29,15 @@ def get_distance_over_ground(ds): ds : `.xarray.Dataset` With ``distance_over_ground`` key. """ + good = ~np.isnan(ds.latitude + ds.longitude) - dist = gsw.distance(ds.longitude[good].values, ds.latitude[good].values)/1000 - dist = np.roll(np.append(dist, 0), 1) - dist = np.cumsum(dist) - dist = np.interp(ds.time, ds.time[good], dist) + if np.any(good): + dist = gsw.distance(ds.longitude[good].values, ds.latitude[good].values)/1000 + dist = np.roll(np.append(dist, 0), 1) + dist = np.cumsum(dist) + dist = np.interp(ds.time, ds.time[good], dist) + else: + dist = 0 * ds.latitude.values attr = {'long_name': 'distance over ground flown since mission start', 'method': 'get_distance_over_ground', 'units': 'km', @@ -465,10 +469,17 @@ def fill_metadata(ds, metadata, sensor_data): """ good = ~np.isnan(ds.latitude.values + ds.longitude.values) - ds.attrs['geospatial_lat_max'] = np.max(ds.latitude.values[good]) - ds.attrs['geospatial_lat_min'] = np.min(ds.latitude.values[good]) - ds.attrs['geospatial_lon_max'] = np.max(ds.longitude.values[good]) - ds.attrs['geospatial_lon_min'] = np.min(ds.longitude.values[good]) + if np.any(good): + ds.attrs['geospatial_lat_max'] = np.max(ds.latitude.values[good]) + ds.attrs['geospatial_lat_min'] = np.min(ds.latitude.values[good]) + ds.attrs['geospatial_lon_max'] = np.max(ds.longitude.values[good]) + ds.attrs['geospatial_lon_min'] = np.min(ds.longitude.values[good]) + else: + ds.attrs['geospatial_lat_max'] = np.nan + ds.attrs['geospatial_lat_min'] = np.nan + ds.attrs['geospatial_lon_max'] = np.nan + ds.attrs['geospatial_lon_min'] = np.nan + ds.attrs['geospatial_lat_units'] = 'degrees_north' ds.attrs['geospatial_lon_units'] = 'degrees_east' ds.attrs['netcdf_version'] = '4.0' # TODO get this somehow...