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

Update how to determine depth dimension #170

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 70 additions & 26 deletions stglib/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,40 +1004,84 @@ def create_z(ds):
ds["z"].attrs["units"] = "m"
ds["z"].attrs["standard_name"] = "height"

if "P_1ac" in ds:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
presvar = np.nanmean(ds["P_1ac"]) + ds["bindist"].values
elif ds.attrs["orientation"].upper() == "UP":
presvar = np.nanmean(ds["P_1ac"]) - ds["bindist"].values
else:
presvar = np.nanmean(ds["P_1ac"])
elif "P_1" in ds:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
presvar = np.nanmean(ds["P_1"]) + ds["bindist"].values
elif ds.attrs["orientation"].upper() == "UP":
presvar = np.nanmean(ds["P_1"]) - ds["bindist"].values
else:
presvar = np.nanmean(ds["P_1"])
else:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
presvar = ds.attrs["WATER_DEPTH"] + ds["bindist"].values
elif ds.attrs["orientation"].upper() == "UP":
presvar = ds.attrs["WATER_DEPTH"] - ds["bindist"].values
# find depth dimension values
# check for sea floor depth standard names
sfds = ["geoid", "geopotential_datum", "mean_sea_level", "reference_ellipsoid"]
dnowacki-usgs marked this conversation as resolved.
Show resolved Hide resolved
for k in sfds:
name = "sea_floor_depth_below_" + k
longname = "depth below " + k.replace("_", " ")
if name in ds.attrs:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
depvar = (
ds.attrs[name]
- ds.attrs["initial_instrument_height"]
+ ds["bindist"].values
)
elif ds.attrs["orientation"].upper() == "UP":
depvar = (
ds.attrs[name]
- ds.attrs["initial_instrument_height"]
- ds["bindist"].values
)
else:
depvar = ds.attrs[name] - ds.attrs["initial_instrument_height"]
break
Copy link
Member

Choose a reason for hiding this comment

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

Remove break line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made change


if "depvar" not in locals():
Copy link
Member

Choose a reason for hiding this comment

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

Then replace this line with if not depvar:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

instead used --> if depvar is None:

if "D_3" in ds:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
depvar = np.nanmean(ds["D_3"]) + ds["bindist"].values
elif ds.attrs["orientation"].upper() == "UP":
depvar = np.nanmean(ds["D_3"]) - ds["bindist"].values
else:
depvar = np.nanmean(ds["P_1ac"])
name = "sea_floor_depth_below_mean_sea_level"
longname = "depth below mean sea level from data"
elif "P_1ac" in ds:
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
depvar = np.nanmean(ds["P_1ac"]) + ds["bindist"].values
elif ds.attrs["orientation"].upper() == "UP":
depvar = np.nanmean(ds["P_1ac"]) - ds["bindist"].values
else:
depvar = np.nanmean(ds["P_1ac"])
name = "sea_floor_depth_below_mean_sea_level"
longname = "depth below mean sea level from data"
else:
presvar = ds.attrs["WATER_DEPTH"] - ds.attrs["initial_instrument_height"]
if "sea_floor_depth_below_sea_surface" in ds.attrs:
name = "sea_floor_depth_below_sea_surface" # this is not ref to datum
longname = "depth below sea surface"
else:
name = "WATER_DEPTH"
longname = "depth below WATER_DEPTH ref"

if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
depvar = (
ds.attrs[name]
- ds.attrs["initial_instrument_height"]
+ ds["bindist"].values
)
elif ds.attrs["orientation"].upper() == "UP":
depvar = (
ds.attrs[name]
- ds.attrs["initial_instrument_height"]
- ds["bindist"].values
)
else:
depvar = ds.attrs[name] - ds.attrs["initial_instrument_height"]

if "bindist" in ds:
ds["depth"] = xr.DataArray(presvar, dims="depth")
ds["depth"] = xr.DataArray(depvar, dims="depth")
dnowacki-usgs marked this conversation as resolved.
Show resolved Hide resolved
else:
ds["depth"] = xr.DataArray([presvar], dims="depth")
ds["depth"] = xr.DataArray([depvar], dims="depth")

ds["depth"].attrs["positive"] = "down"
ds["depth"].attrs["units"] = "m"
ds["depth"].attrs["standard_name"] = "depth_below_geoid"
ds["depth"].attrs["long_name"] = "depth below mean sea level"
ds["depth"].attrs["long_name"] = longname

return ds

Expand Down
4 changes: 2 additions & 2 deletions stglib/tests/data/glob_att1123A_msl.txt
Git LFS file not shown