From 5fa4c130c643f0954b29f9abcc079e65c13034ac Mon Sep 17 00:00:00 2001 From: Jessy Barrette <30420025+JessyBarrette@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:34:07 -0500 Subject: [PATCH] isort . black . --- ocean_data_parser/parsers/amundsen.py | 12 +++++++----- ocean_data_parser/parsers/nmea.py | 10 ++++++---- ocean_data_parser/parsers/sunburst.py | 24 +++++++++--------------- ocean_data_parser/process/process.py | 2 +- tests/test_process.py | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/ocean_data_parser/parsers/amundsen.py b/ocean_data_parser/parsers/amundsen.py index cd4d8234..2292e144 100644 --- a/ocean_data_parser/parsers/amundsen.py +++ b/ocean_data_parser/parsers/amundsen.py @@ -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", diff --git a/ocean_data_parser/parsers/nmea.py b/ocean_data_parser/parsers/nmea.py index ddd46953..504f88c6 100644 --- a/ocean_data_parser/parsers/nmea.py +++ b/ocean_data_parser/parsers/nmea.py @@ -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", @@ -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}) diff --git a/ocean_data_parser/parsers/sunburst.py b/ocean_data_parser/parsers/sunburst.py index c30b8f66..d265dced 100644 --- a/ocean_data_parser/parsers/sunburst.py +++ b/ocean_data_parser/parsers/sunburst.py @@ -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() diff --git a/ocean_data_parser/process/process.py b/ocean_data_parser/process/process.py index 2a349586..3def06a7 100644 --- a/ocean_data_parser/process/process.py +++ b/ocean_data_parser/process/process.py @@ -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") diff --git a/tests/test_process.py b/tests/test_process.py index f1a3f4e2..1eaa2c92 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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"