Skip to content

Commit

Permalink
Merge pull request #184 from GEUS-Glaciology-and-Climate/features/tim…
Browse files Browse the repository at this point in the history
…e_offset_correction

Added time offset configuration to correct for non UTC time codes
  • Loading branch information
ladsmund authored Sep 28, 2023
2 parents 841c665 + 90da92c commit c93cac8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
from importlib import metadata
import os, unittest, toml, datetime, uuid, pkg_resources
from typing import Optional

import numpy as np
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
Expand Down Expand Up @@ -263,7 +265,7 @@ def readL0file(self, conf):
'''
file_version = conf.get('file_version', -1)
ds = getL0(conf['file'], conf['nodata'], conf['columns'],
conf["skiprows"], file_version)
conf["skiprows"], file_version, time_offset=conf.get('time_offset'))
ds = populateMeta(ds, conf, ["columns", "skiprows", "modem"])
return ds

Expand Down Expand Up @@ -304,8 +306,8 @@ def getConfig(config_file, inpath):
assert(field in conf[k].keys()), field+" not in config keys"
return conf

def getL0(infile, nodata, cols, skiprows, file_version,
delimiter=',', comment='#'):
def getL0(infile, nodata, cols, skiprows, file_version,
delimiter=',', comment='#', time_offset: Optional[float] = None) -> xr.Dataset:
''' Read L0 data file into pandas DataFrame object
Parameters
Expand All @@ -324,6 +326,8 @@ def getL0(infile, nodata, cols, skiprows, file_version,
String delimiter for L0 file
comment : str
Notifier of commented sections in L0 file
time_offset : Optional[float]
Time offset in hours for correcting for non utc time data.
Returns
-------
Expand Down Expand Up @@ -366,7 +370,9 @@ def getL0(infile, nodata, cols, skiprows, file_version,
print(e)
print('\n\t\t> Trying again removing apostrophes in timestamp (old files format)')
df.index = pd.to_datetime(df.index.str.replace("\"",""))


if time_offset is not None:
df.index = df.index + timedelta(hours=time_offset)

# Drop SKIP columns
for c in df.columns:
Expand Down

0 comments on commit c93cac8

Please sign in to comment.