-
Notifications
You must be signed in to change notification settings - Fork 29
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
add Ocean Gliders format output option to seaxexplorer processing #212
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,6 +633,87 @@ | |
return index | ||
|
||
|
||
pyglider_og_var_dict = {'time': 'TIME', | ||
'longitude': 'LONGITUDE', | ||
'latitude': 'LATITUDE', | ||
'depth': 'DEPTH', | ||
'pressure': 'PRES'} | ||
|
||
|
||
def add_og1_metadata(ds, deployment_yaml): | ||
# Translate back to og names from pyglider names | ||
for pyglider_var, og_var in pyglider_og_var_dict.items(): | ||
if pyglider_var in ds.keys(): | ||
ds = ds.rename({pyglider_var: og_var}) | ||
|
||
# add some global attributes | ||
attrs = ds.attrs | ||
attrs["start_date"] = attrs["time_coverage_start"] | ||
ds.attrs = attrs | ||
|
||
# Add empty variables for OG1 | ||
for variable, variable_dict in deployment_yaml['oceangliders_empty_variables'].items(): | ||
attrs = {name: str(val) for name, val in variable_dict.items() if name != 'value'} | ||
ds[variable] = xr.DataArray(variable_dict['value'], attrs=attrs) | ||
|
||
|
||
# Add sensors | ||
for device, device_dict in deployment_yaml['glider_devices'].items(): | ||
attrs = {name: str(val) for name, val in device_dict.items() if name != 'value'} | ||
sensor_name = f"SENSOR_{device}_{device_dict['sensor_serial_number']}" | ||
ds[sensor_name] = xr.DataArray(attrs=attrs) | ||
|
||
# add GPS variables | ||
for vname in ["LATITUDE", "LONGITUDE", "TIME"]: | ||
ds[f"{vname}_GPS"] = ds[vname].copy() | ||
nan_val = np.nan | ||
if vname == 'TIME': | ||
nan_val = np.datetime64("NaT") | ||
ds[f"{vname}_GPS"].values[ds["dead_reckoning"].values != 0] = nan_val | ||
ds[f"{vname}_GPS"].attrs["long_name"] = f"{vname.lower()} of each GPS location" | ||
ds["LATITUDE_GPS"].attrs["URI"] = ( | ||
"https://vocab.nerc.ac.uk/collection/OG1/current/LAT_GPS/" | ||
) | ||
ds["LONGITUDE_GPS"].attrs["URI"] = ( | ||
"https://vocab.nerc.ac.uk/collection/OG1/current/LON_GPS/" | ||
) | ||
|
||
ds["TRAJECTORY"] = xr.DataArray( | ||
ds.attrs["id"], | ||
attrs={"cf_role": "trajectory_id", "long_name": "trajectory name"}, | ||
) | ||
ds["PLATFORM_MODEL"] = xr.DataArray( | ||
ds.attrs["glider_model"], | ||
attrs={ | ||
"long_name": "model of the glider", | ||
"platform_model_vocabulary": "None", | ||
}, | ||
) | ||
ds["PLATFORM_SERIAL_NUMBER"] = xr.DataArray( | ||
f"sea{ds.attrs['glider_serial'].zfill(3)}", | ||
attrs={"long_name": "glider serial number"}, | ||
) | ||
ds["DEPLOYMENT_TIME"] = np.nanmin(ds.TIME.values) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The yamls have a "conversion" field for each variable that tries to fine the method in
with the accompanying change in |
||
ds["DEPLOYMENT_TIME"].attrs = { | ||
"long_name": "date of deployment", | ||
"standard_name": "time", | ||
"units": "seconds since 1970-01-01T00:00:00Z", | ||
"calendar": "gregorian", | ||
} | ||
ds["DEPLOYMENT_LATITUDE"] = ds.LATITUDE.values[0] | ||
ds["DEPLOYMENT_LATITUDE"].attrs = {"long_name": "latitude of deployment"} | ||
ds["DEPLOYMENT_LONGITUDE"] = ds.LONGITUDE.values[0] | ||
ds["DEPLOYMENT_LONGITUDE"].attrs = {"long_name": "longitude of deployment"} | ||
for var_name in ds.keys(): | ||
if "time" in var_name.lower() and var_name is not "TIME": | ||
if 'units' in ds[var_name].attrs.keys(): | ||
ds[var_name].attrs.pop('units') | ||
if 'calendar' in ds[var_name].attrs.keys(): | ||
ds[var_name].attrs.pop('calendar') | ||
ds = ds.rename_dims({'TIME': 'N_MEASUREMENTS'}) | ||
return ds | ||
|
||
|
||
def _parse_gliderxml_pos(fname): | ||
""" | ||
DEPRECATED: use slocum.parse_gliderState instead | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, 'time'/'TIME' could be replaced by a time-encoder yaml entry. eg calls to
ds.time
could be replaced byds[time_var_name]
or similar?Not sure about 'latitude' etc, but why do they need to be translated back and forth? For distance over ground? Maybe just use inside that function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can localise lon/lat to just change within those functions, I'll make a new PR with
ds[time_var_name]
and see what it looks like