Skip to content

Commit

Permalink
Linter fixes (#192)
Browse files Browse the repository at this point in the history
* Linter stuff

* More linter stuff

* Haven't been calling add_attributes for a long time, so remove
  • Loading branch information
dnowacki-usgs authored Mar 12, 2024
1 parent 2096894 commit 75f125b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 65 deletions.
64 changes: 17 additions & 47 deletions stglib/aqd/aqdutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,24 +983,23 @@ def add_vel_attributes(vel, dsattrs):
"Velocity bins trimmed if out of water or if side lobes intersect sea surface."
)

def add_attributes(var, dsattrs):
if inst_type == "AQD":
sn = dsattrs["AQDSerial_Number"]
elif inst_type == "VEC":
sn = dsattrs["VECSerialNumber"]
elif inst_type == "SIG":
sn = dsattrs["SIGSerialNo"]
"""
var.attrs.update(
{
# "serial_number": sn,
# "initial_instrument_height": dsattrs["initial_instrument_height"],
# "nominal_instrument_depth": dsattrs["nominal_instrument_depth"],
# "height_depth_units": "m",
# "sensor_type": dsattrs["INST_TYPE"],
}
)
"""
# def add_attributes(var, dsattrs):
# if inst_type == "AQD":
# sn = dsattrs["AQDSerial_Number"]
# elif inst_type == "VEC":
# sn = dsattrs["VECSerialNumber"]
# elif inst_type == "SIG":
# sn = dsattrs["SIGSerialNo"]
#
# var.attrs.update(
# {
# # "serial_number": sn,
# # "initial_instrument_height": dsattrs["initial_instrument_height"],
# # "nominal_instrument_depth": dsattrs["nominal_instrument_depth"],
# # "height_depth_units": "m",
# # "sensor_type": dsattrs["INST_TYPE"],
# }
# )

# if utils.is_cf(ds):
# ds.attrs["featureType"] = "timeSeriesProfile"
Expand Down Expand Up @@ -1216,8 +1215,6 @@ def add_attributes(var, dsattrs):
if "P_1ac_note" in ds.attrs:
ds["P_1ac"].attrs.update({"note": ds.attrs["P_1ac_note"]})

add_attributes(ds["P_1ac"], ds.attrs)

if "bin_depth" in ds:
ds["bin_depth"].attrs.update({"units": "m", "long_name": "bin depth"})

Expand Down Expand Up @@ -1321,36 +1318,9 @@ def add_attributes(var, dsattrs):
)

if not waves:
for v in ["AGC_1202", "u_1205", "v_1206", "w_1204"]:
if v in ds:
add_attributes(ds[v], ds.attrs)
for v in ["u_1205", "v_1206", "w_1204", "w2_1204"]:
if v in ds:
add_vel_attributes(ds[v], ds.attrs)
elif waves:
for v in [
"vel1_1277",
"vel2_1278",
"vel3_1279",
"AGC1_1221",
"AGC2_1222",
"AGC3_1223",
]:
if v in ds:
add_attributes(ds[v], ds.attrs)

for v in [
"P_1",
"Tx_1211",
"Hdg_1215",
"Ptch_1216",
"Roll_1217",
"Bat_106",
"bin_depth",
"bindist",
]:
if v in ds:
add_attributes(ds[v], ds.attrs)

return ds

Expand Down
10 changes: 2 additions & 8 deletions stglib/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ def create_water_depth_var(ds):
ds[press].squeeze().mean(dim="sample")
+ ds.attrs["initial_instrument_height"]
)

else:
ds["water_depth"] = xr.DataArray(
ds[press].squeeze() + ds.attrs["initial_instrument_height"]
Expand Down Expand Up @@ -1267,14 +1268,7 @@ def salinity_from_spcon(spcon):
K5 = -6.4788
K6 = 2.5842

return (
K1
+ K2 * R**0.5
+ K3 * R
+ K4 * R ** (3 / 2)
+ K5 * R**2
+ K6 * R ** (5 / 2)
)
return K1 + K2 * R**0.5 + K3 * R + K4 * R ** (3 / 2) + K5 * R**2 + K6 * R ** (5 / 2)


def spcon_from_salinity(S):
Expand Down
1 change: 0 additions & 1 deletion stglib/hobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ def cdf_to_nc(cdf_filename):

if "vert_dim" in ds.attrs:
vdim = ds.attrs["vert_dim"]
attrsbak = ds[vdim].attrs
# axis attr set for z in utils.create_z so need to del if other than z
if ds.attrs["vert_dim"] != "z":
ds[vdim].attrs["axis"] = "Z"
Expand Down
3 changes: 0 additions & 3 deletions stglib/rsk/cdf2nc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import warnings

import numpy as np
import pandas as pd
import xarray as xr

from ..core import qaqc, utils
Expand Down
3 changes: 1 addition & 2 deletions stglib/rsk/csv2cdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def csv_to_cdf(metadata):
if utils.check_fits_in_int32(ds, "obs"):
ds["obs"].encoding["dtype"] = "i4"

dstime = ds["time"].values
ds = ds.drop("time")

ds = ds.rename({"obs": "time"}).set_coords("time").rename({"time": "obs"})
Expand Down Expand Up @@ -337,7 +336,7 @@ def get_metadata(ds, var, meta, field="dataheader"):
thisname = np.where(metanames == var.replace("_", " "))[0][0]
for v in ["units", "calibration", "ranging"]:
if v in dh[thisname]:
if type(dh[thisname][v]) == dict:
if isinstance(dh[thisname][v], dict):
ds[var].attrs[v] = str(dh[thisname][v])
else:
ds[var].attrs[v] = dh[thisname][v]
Expand Down
9 changes: 8 additions & 1 deletion stglib/sig/dlfncdf2nc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pkgutil
import time
import warnings

import dolfyn
import xarray as xr
import xmltodict

from ..aqd import aqdutils
Expand All @@ -13,6 +13,13 @@ def cdf_to_nc(cdf_filename, atmpres=False):
"""
Load a raw .cdf file and generate a processed .nc file
"""

warnings.warn(
"The use of Dolfyn to process Signature data is not currently supported. Use mat_to_cdf instead. Refer to the stglib documentation for more details.",
DeprecationWarning,
stacklevel=2,
)

# TODO: Add atmospheric pressure offset
print(f"Loading {cdf_filename}")
start_time = time.time()
Expand Down
1 change: 0 additions & 1 deletion stglib/tcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def cdf_to_nc(cdf_filename):

if "vert_dim" in ds.attrs:
vdim = ds.attrs["vert_dim"]
attrsbak = ds[vdim].attrs
# axis attr set for z in utils.create_z so need to del if other than z
if ds.attrs["vert_dim"] != "z":
ds[vdim].attrs["axis"] = "Z"
Expand Down
4 changes: 2 additions & 2 deletions stglib/vec/cdf2nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ def ds_drop(ds):
def scale_analoginput(ds):
"""convert AnalogInput from counts to volts"""
ds["AnalogInput1"] = ds["AnalogInput1"] * 5 / 65535
notetxt = f"Converted from counts to volts: volts=counts*5/65535."
notetxt = "Converted from counts to volts: volts=counts*5/65535."
ds = utils.insert_note(ds, "AnalogInput1", notetxt)
ds["AnalogInput2"] = ds["AnalogInput2"] * 5 / 65535
notetxt = f"Converted from counts to volts: volts=counts*5/65535."
notetxt = "Converted from counts to volts: volts=counts*5/65535."
ds = utils.insert_note(ds, "AnalogInput2", notetxt)

return ds

0 comments on commit 75f125b

Please sign in to comment.