Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeseries data format #79

Open
wcarthur opened this issue Mar 17, 2020 · 2 comments
Open

Timeseries data format #79

wcarthur opened this issue Mar 17, 2020 · 2 comments
Assignees

Comments

@wcarthur
Copy link
Member

wcarthur commented Mar 17, 2020

When running a simulation and extracting time series data for stations, the formatting of the datetime string means the interval is not equal, because machine precision seems to result in slightly varying intervals. When writing the data to file, we truncate (not round) the time field to minutes.

Solution:

  • Expand the time format to "%Y-%d-%m %H:%M:%S"
  • Do some rounding of the time values to eliminate the fractional seconds that is leading to this behaviour
@wcarthur wcarthur self-assigned this Mar 17, 2020
@wcarthur
Copy link
Member Author

wcarthur commented Apr 7, 2020

Function definition for rounding datetime objects

def roundTime(dt=None, roundTo=60):
   "''Round a datetime object to any time lapse in seconds
   dt : datetime.datetime object, default now.
   roundTo : Closest number of seconds to round to, default 1 minute.
   Author: Thierry Husson 2012 - Use it as you want but don't blame me.
   """
   if dt == None : dt = datetime.datetime.now()
   seconds = (dt.replace(tzinfo=None) - dt.min).seconds
   rounding = (seconds+roundTo/2) // roundTo * roundTo
   return dt + datetime.timedelta(0,rounding-seconds,-dt.microsecond)

Needs unittest around it, but should be sufficient

@wcarthur
Copy link
Member Author

wcarthur commented Apr 7, 2020

Another option is to store the data as a collection of pandas.DataFrames. Then can use DataFrame.to_csv() with the date_format arg set to "%Y-%d-%m %H:%M:%S"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant