diff --git a/scripts/aqdturnaround.py b/scripts/aqdturnaround.py index dd45ca1f..8de610a0 100755 --- a/scripts/aqdturnaround.py +++ b/scripts/aqdturnaround.py @@ -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, :] diff --git a/stglib/aqd/aqdutils.py b/stglib/aqd/aqdutils.py index d84bed88..893d482d 100644 --- a/stglib/aqd/aqdutils.py +++ b/stglib/aqd/aqdutils.py @@ -241,7 +241,7 @@ 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") @@ -249,7 +249,7 @@ def set_orientation(VEL, T): 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, :] @@ -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 diff --git a/stglib/core/utils.py b/stglib/core/utils.py index 51455fc4..132e570a 100644 --- a/stglib/core/utils.py +++ b/stglib/core/utils.py @@ -988,7 +988,7 @@ 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"]) @@ -996,7 +996,7 @@ def create_z(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"]) @@ -1004,7 +1004,7 @@ def create_z(ds): 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"] diff --git a/stglib/eofe.py b/stglib/eofe.py index e12d8e11..11787d1f 100644 --- a/stglib/eofe.py +++ b/stglib/eofe.py @@ -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): @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/stglib/vec/cdf2nc.py b/stglib/vec/cdf2nc.py index 35f0da68..e798dd10 100644 --- a/stglib/vec/cdf2nc.py +++ b/stglib/vec/cdf2nc.py @@ -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"