Skip to content

Commit

Permalink
FIX: some more small things
Browse files Browse the repository at this point in the history
  • Loading branch information
cproof committed Aug 8, 2024
1 parent 13ea358 commit 4655a10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyglider/ncprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion pyglider/slocum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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']
Expand Down
27 changes: 19 additions & 8 deletions pyglider/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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...
Expand Down

0 comments on commit 4655a10

Please sign in to comment.