Skip to content

Commit

Permalink
Update ARGOS_service_data_converter.py
Browse files Browse the repository at this point in the history
change the way times are parsed to remove FutureWarning
  • Loading branch information
shaunwbell committed Dec 4, 2024
1 parent 4cb7ff2 commit 1308d95
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions ARGOS_service_data_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
2018-03-13: Ingest two starter characters that represent time (hour and minute)
and output seconds since midnight.
2018-03-12: Add netcdf output option
2024-12-04: Modify pandas date_parse to be pandas 2.X compliant
Compatibility:
==============
python >=3.6 **tested**
python 2.7 **tested** but may break in the future
python >=3.9 **tested**
"""
import argparse
Expand Down Expand Up @@ -90,7 +90,6 @@ def get_data(fobj=None):
Basic Method to open files. Specific actions can be passes as kwargs for instruments
"""
argo_to_datetime = lambda date: datetime.datetime.strptime(date, "%Y %j %H%M")

header = [
"argosid",
Expand Down Expand Up @@ -120,10 +119,10 @@ def get_data(fobj=None):
"s3": str,
"s4": str,
},
parse_dates=[["year", "doy", "hhmm"]],
date_parser=argo_to_datetime,
)

df["year_doy_hhmm"] = pd.to_datetime(arg=df.pop("year").str.cat(df.pop("doy")).str.cat(df.pop("hhmm")),
format="%Y%j%H%M")
df["longitude"] = df["longitude"] * -1 # convert to +W
df["longitude"] = df.longitude.round(3)
df["latitude"] = df.latitude.round(3)
Expand All @@ -148,7 +147,6 @@ def get_data(fobj=None):
Basic Method to open files. Specific actions can be passes as kwargs for instruments
"""
argo_to_datetime = lambda date: datetime.datetime.strptime(date, "%Y %j %H%M")

header = [
"argosid",
Expand Down Expand Up @@ -186,10 +184,10 @@ def get_data(fobj=None):
"s7": str,
"s8": str,
},
parse_dates=[["year", "doy", "hhmm"]],
date_parser=argo_to_datetime,
)

df["year_doy_hhmm"] = pd.to_datetime(arg=df.pop("year").str.cat(df.pop("doy")).str.cat(df.pop("hhmm")),
format="%Y%j%H%M")
df["longitude"] = df["longitude"] * -1 # convert to +W
df["longitude"] = df.longitude.round(3)
df["latitude"] = df.latitude.round(3)
Expand Down Expand Up @@ -266,7 +264,6 @@ def get_data(fobj=None, time="current"):
Date,AT,RH,WS,WD,BP,QS,AZ,BV
"""
argo_to_datetime = lambda date: datetime.datetime.strptime(date, "%Y %j %H%M")

header = [
"argosid",
Expand Down Expand Up @@ -322,14 +319,13 @@ def get_data(fobj=None, time="current"):
usecols=columns,
on_bad_lines='warn',
dtype=dtype,
parse_dates=[["year", "doy", "hhmm"]],
date_parser=argo_to_datetime,
)

df["year_doy_hhmm"] = pd.to_datetime(arg=df.pop("year").str.cat(df.pop("doy")).str.cat(df.pop("hhmm")),
format="%Y%j%H%M")
df["longitude"] = df["longitude"] * -1 # convert to +W

df.set_index(pd.DatetimeIndex(df["year_doy_hhmm"]), inplace=True)
# df.drop('year_doy_hhmm',axis=1,inplace=True)

return df

Expand Down

0 comments on commit 1308d95

Please sign in to comment.