Skip to content

Commit

Permalink
fixes to cdir, lfs files
Browse files Browse the repository at this point in the history
  • Loading branch information
ssuttles-usgs committed Feb 9, 2024
1 parent 62107d4 commit 63a8151
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
53 changes: 13 additions & 40 deletions stglib/tcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ def ds_rename_vars(ds):
) # convert from cm/s to m/s
ds = ds.rename({"Velocity-N_cms": "v_1206"})

if "Speed_cms" in ds:
ds["Speed_cms"].values = (
ds["Speed_cms"].values / 100
) # convert from cm/s to m/s
ds = ds.rename({"Speed_cms": "CS_300"})

if "Bearing_degrees" in ds:
ds = ds.rename({"Bearing_degrees": "CD_310"})

# drop unneeded vars
todrop = ["Speed_cms", "Bearing_degrees"]
todrop = [""]
ds = ds.drop([x for x in todrop if x in ds])

return ds
Expand Down Expand Up @@ -293,43 +302,10 @@ def magvar_correct(ds):

ds[uvar], ds[vvar] = aqdutils.rotate(ds[uvar], ds[vvar], magvardeg)

return ds


def get_speed_dir(ds):
"""Find current speed and direction from velocity east & north relative to due North (True)"""

def cart2pol(x, y):
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
return (rho, phi)

if "U" in ds and "V" in ds:
uvar = "U"
vvar = "V"
elif "u_1205" in ds and "v_1206" in ds:
uvar = "u_1205"
vvar = "v_1206"

try:
if uvar and vvar:
spdvar = "CS_300"
dirvar = "CD_310"

histtext = f"Creating current speed and direction variables from east ({uvar}) and north ({vvar}) velocities"

ds = utils.insert_history(ds, histtext)

ds[spdvar], ds[dirvar] = cart2pol(ds[uvar], ds[vvar])

ds[dirvar] = 90 - ds[dirvar] * 180 / np.pi
if "CD_310" in ds:
dvar = "CD_310"

ds[dirvar] = ds[dirvar].where((ds[dirvar] > 0), ds[dirvar] + 360)

except:
warnings.warn(
"Current speed and direction not created because u_1205 and/or v_1206 are not in the xarray data set"
)
ds[dvar] = (ds[dvar] + magvardeg) % 360

return ds

Expand All @@ -353,9 +329,6 @@ def cdf_to_nc(cdf_filename):

ds = magvar_correct(ds)

# get current spped & direction using magvar corrected velocities (since instrument reports speed & direction and user might expect it)
ds = get_speed_dir(ds)

# should function this
for var in ds.data_vars:
ds = qaqc.trim_min(ds, var)
Expand Down
4 changes: 2 additions & 2 deletions stglib/tests/data/.gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ gatts_205598_20220104_1336_wtw21.txt filter=lfs diff=lfs merge=lfs -text
config_205598_20220104_1336_wtw21.yaml filter=lfs diff=lfs merge=lfs -text
atmpres_205598_20220104_1336_wtw21.cdf filter=lfs diff=lfs merge=lfs -text
L0221705_v2_rs.csv filter=lfs diff=lfs merge=lfs -text
*.yaml filter=lfs diff=lfs merge=lfs -text
*.txt filter=lfs diff=lfs merge=lfs -text
*.lid filter=lfs diff=lfs merge=lfs -text
Bang_--_MBW.csv filter=lfs diff=lfs merge=lfs -text
Barometer_w_RainGauge.csv filter=lfs diff=lfs merge=lfs -text

0 comments on commit 63a8151

Please sign in to comment.