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

Catch variability in orientation and CF metadata #138

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion scripts/aqdturnaround.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

T_orig = meta["AQDTransMatrix"].copy()
T = meta["AQDTransMatrix"]
if args.orientation == "DOWN":
if args.orientation.upper() == "DOWN":
T[1, :] = -T[1, :]
T[2, :] = -T[2, :]

Expand Down
12 changes: 10 additions & 2 deletions stglib/aqd/aqdutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ def set_orientation(VEL, T):

T_orig = T.copy()

if VEL.attrs["orientation"] == "UP":
if VEL.attrs["orientation"].upper() == "UP":
print("User instructed that instrument was pointing UP")

VEL["z"] = xr.DataArray(elev + VEL["bindist"].values, dims="z")
VEL["depth"] = xr.DataArray(
np.nanmean(VEL[presvar]) - VEL["bindist"].values, dims="depth"
)

if VEL.attrs["orientation"] == "DOWN":
if VEL.attrs["orientation"].upper() == "DOWN":
print("User instructed that instrument was pointing DOWN")
T[1, :] = -T[1, :]
T[2, :] = -T[2, :]
Expand Down Expand Up @@ -1368,6 +1368,14 @@ def check_valid_config_metadata(metadata, inst_type="AQD"):
"Conventions other than a version of the CF Metadata Conventions are not supported"
)

if metadata["Conventions"] != "CF-1.8":
warnings.warn(
f"You are using a version of the CF Conventions ({metadata['Conventions']}) that is not the latest supported version (CF-1.8). Consider changing to CF-1.8."
)

if "orientation" in metadata:
metadata["orientation"] = metadata["orientation"].upper()


def apply_wave_coord_output(ds, T, T_orig):
# Transform coordinates from ENU to BEAM if necessary
Expand Down
6 changes: 3 additions & 3 deletions stglib/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,23 +988,23 @@ def create_z(ds):
if "bindist" in ds:
if ds.attrs["orientation"].upper() == "DOWN":
presvar = np.nanmean(ds["P_1ac"]) + ds["bindist"].values
elif ds.attrs["orientation"] == "UP":
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"] == "UP":
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"] == "UP":
elif ds.attrs["orientation"].upper() == "UP":
presvar = ds.attrs["WATER_DEPTH"] - ds["bindist"].values
else:
presvar = ds.attrs["WATER_DEPTH"] - ds.attrs["initial_instrument_height"]
Expand Down
18 changes: 9 additions & 9 deletions stglib/eofe.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def add_attributes(var, dsattrs):
"sensor_type": "ECHOLOGGER AA400",
}
)

# don't include all attributes for coordinates that are also variables
#for var in ds.variables:
# if (var not in ds.coords) and ("time" not in var):
Expand Down Expand Up @@ -487,14 +487,14 @@ def calc_bin_height(ds):
"Calculating center of bin height from seafloor as: initial intrument height - bin(center) distance from transducer"
)

if ds.attrs["orientation"] == "down" or ds.attrs["orientation"] == "DOWN":
if ds.attrs["orientation"].upper() == "DOWN":
ds["bin_height"] = (
ds.attrs["initial_instrument_height"] - ds["bindist"]
) # get bin distance referenced from sea floor

math_sign = "-"

elif ds.attrs["orientation"] == "up" or ds.attrs["orientation"] == "UP":
elif ds.attrs["orientation"].upper() == "UP":
ds["bin_height"] = (
ds.attrs["initial_instrument_height"] + ds["bindist"]
) # get bin distance referenced from sea floor
Expand Down Expand Up @@ -571,14 +571,14 @@ def calc_seabed_elev(ds):
% ds.attrs["geopotential_datum_name"]
)

if ds.attrs["orientation"] == "DOWN" or ds.attrs["orientation"] == "down":
if ds.attrs["orientation"].upper() == "DOWN":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["NAVD88_ref"]
+ (ds.brange * -1)
+ ds.attrs["initial_instrument_height"]
)

elif ds.attrs["orientation"] == "UP" or ds.attrs["orientation"] == "up":
elif ds.attrs["orientation"].upper() == "UP":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["NAVD88_ref"]
+ ds.brange
Expand All @@ -591,14 +591,14 @@ def calc_seabed_elev(ds):
% ds.attrs["geopotential_datum_name"]
)

if ds.attrs["orientation"] == "DOWN" or ds.attrs["orientation"] == "down":
if ds.attrs["orientation"].upper() == "DOWN":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["height_above_geopotential_datum"]
+ (ds.brange * -1)
+ ds.attrs["initial_instrument_height"]
)

elif ds.attrs["orientation"] == "UP" or ds.attrs["orientation"] == "up":
elif ds.attrs["orientation"].upper() == "UP":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["height_above_geopotential_datum"]
+ ds.brange
Expand All @@ -612,14 +612,14 @@ def calc_seabed_elev(ds):
% ds.attrs["geopotential_datum_name"]
)

if ds.attrs["orientation"] == "DOWN" or ds.attrs["orientation"] == "down":
if ds.attrs["orientation"].upper() == "DOWN":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["WATER_DEPTH"]
+ ds.brange
- ds.attrs["initial_instrument_height"]
)

if ds.attrs["orientation"] == "UP" or ds.attrs["orientation"] == "up":
if ds.attrs["orientation"].upper() == "UP":
ds["seabed_elevation"] = xr.DataArray(
ds.attrs["WATER_DEPTH"]
+ (ds.brange * -1)
Expand Down
6 changes: 4 additions & 2 deletions stglib/vec/cdf2nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,21 @@ def set_orientation(VEL, T):

T_orig = T.copy()

if VEL.attrs["orientation"] == "UP":
if VEL.attrs["orientation"].upper() == "UP":
print("User instructed that instrument was pointing UP")

VEL["z"] = xr.DataArray(elev + [0.15], dims="z")
VEL["depth"] = xr.DataArray(np.nanmean(VEL[presvar]) - [0.15], dims="depth")

elif VEL.attrs["orientation"] == "DOWN":
elif VEL.attrs["orientation"].upper() == "DOWN":
print("User instructed that instrument was pointing DOWN")
T[1, :] = -T[1, :]
T[2, :] = -T[2, :]

VEL["z"] = xr.DataArray(elev - [0.15], dims="z")
VEL["depth"] = xr.DataArray(np.nanmean(VEL[presvar]) + [0.15], dims="depth")
else:
raise ValueError("Could not determine instrument orientation from user input")

VEL["z"].attrs["standard_name"] = "height"
VEL["z"].attrs["units"] = "m"
Expand Down
Loading