Skip to content

Commit

Permalink
isort . black .
Browse files Browse the repository at this point in the history
  • Loading branch information
JessyBarrette committed Nov 16, 2023
1 parent 2ad9ab7 commit 5fa4c13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
12 changes: 7 additions & 5 deletions ocean_data_parser/parsers/amundsen.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ def int_format(
key, value = line.strip()[1:].split(":", 1)
metadata[key.strip()] = value.strip()
elif line == "% Fluorescence [ug/L]":
metadata['Fluo'] = "Fluorescence [ug/L]"
metadata["Fluo"] = "Fluorescence [ug/L]"
elif line == "% Conservative Temperature (TEOS-10) [deg C]":
metadata['CONT'] = "Conservative Temperature (TEOS-10) [deg C]"
metadata["CONT"] = "Conservative Temperature (TEOS-10) [deg C]"
elif line == "% In situ density TEOS10 ((s, t, p) - 1000) [kg/m^3]":
metadata['D_CT'] = "In situ density TEOS10 ((s, t, p) - 1000) [kg/m^3]"
metadata["D_CT"] = "In situ density TEOS10 ((s, t, p) - 1000) [kg/m^3]"
elif line == "% Potential density TEOS10 ((s, t, 0) - 1000) [kg/m^3]":
metadata['D0CT'] = "Potential density TEOS10 ((s, t, 0) - 1000) [kg/m^3]"
metadata[
"D0CT"
] = "Potential density TEOS10 ((s, t, 0) - 1000) [kg/m^3]"
elif line == "% Potential density TEOS10 (s, t, 0) [kg/m^3]":
metadata['D0CT'] = "Potential density TEOS10 (s, t, 0) [kg/m^3]"
metadata["D0CT"] = "Potential density TEOS10 (s, t, 0) [kg/m^3]"
elif re.match(r"% .* \[.+\]", line):
logger.warning(
"Unknown variable name will be saved to unknown_variables_information: %s",
Expand Down
10 changes: 6 additions & 4 deletions ocean_data_parser/parsers/nmea.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ def _generate_extra_terms(nmea):
f"{nmea['year']}-{nmea['month']}-{nmea['day']}T{nmea['timestamp']} UTC",
f"%Y-%m-%dT%H%M%S{'.%f' if len(nmea['timestamp'])>6 else''} %Z",
)
if nmea["sentence_type"] == "RMC" and nmea.get('timestamp') and nmea.get('datestamp'):
if (
nmea["sentence_type"] == "RMC"
and nmea.get("timestamp")
and nmea.get("datestamp")
):
extra[("GPS Time", "gps_datetime")] = datetime.strptime(
f"{nmea['datestamp']}T{nmea['timestamp']} UTC",
f"%d%m%yT%H%M%S{'.%f' if len(nmea['timestamp'])>6 else''} %Z",
Expand Down Expand Up @@ -297,9 +301,7 @@ def rename_variable(name):
for col in df:
if nmea_dtype_mapping.get(col) != datetime:
continue
df[col] = (
pd.to_datetime(df[col], utc=True).dt.tz_convert(None)
)
df[col] = pd.to_datetime(df[col], utc=True).dt.tz_convert(None)

df = df.replace({np.nan: None, "": None, "None": None})

Expand Down
24 changes: 9 additions & 15 deletions ocean_data_parser/parsers/sunburst.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,17 @@ def superCO2(path: str, output: str = None) -> xarray.Dataset:
df.columns = [_format_variables(var) for var in df.columns]

# Generate time variable from Date and Time columns
df["time"] = (
pd.to_datetime(
(df["Date"] + " " + df["Time"]), format="%Y%m%d %H%M%S", utc=True
)
.dt.tz_convert(None)
)
df["time"] = pd.to_datetime(
(df["Date"] + " " + df["Time"]), format="%Y%m%d %H%M%S", utc=True
).dt.tz_convert(None)

# Review day of the year variable
df["time_doy_utc"] = (
pd.to_datetime(
df["DOY_UTC"] - 1,
unit="D",
origin=pd.Timestamp(collected_beginning_date.year, 1, 1),
utc=True,
)
.dt.tz_convert(None)
)
df["time_doy_utc"] = pd.to_datetime(
df["DOY_UTC"] - 1,
unit="D",
origin=pd.Timestamp(collected_beginning_date.year, 1, 1),
utc=True,
).dt.tz_convert(None)

# Compare DOY_UTC vs Date + Time
dt = (df["time"] - df["time_doy_utc"]).mean().total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion ocean_data_parser/process/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load_cnv(file: str):
ds = seabird.cnv(file)
ds["time"] = (
ds["timeK"].dims,
pd.to_datetime(ds["timeK"], origin="2000-01-01", unit="s")
pd.to_datetime(ds["timeK"], origin="2000-01-01", unit="s"),
)
return ds.swap_dims({"index": "time"}).drop("index")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_test_dataset():
ds = seabird.cnv(TEST_SEABIRD_FILE)
ds["time"] = (
ds["timeK"].dims,
pd.to_datetime(ds["timeK"], origin="2000-01-01", unit="s")
pd.to_datetime(ds["timeK"], origin="2000-01-01", unit="s"),
)
ds.process.time = "time"
ds.process.lat = "latitude"
Expand Down

0 comments on commit 5fa4c13

Please sign in to comment.