Unidata / siphon

Siphon - A collection of Python utilities for retrieving atmospheric and oceanic data from remote sources, focusing on being able to retrieve data from Unidata data technologies, such as the THREDDS data server.
https://unidata.github.io/siphon
BSD 3-Clause "New" or "Revised" License
216 stars 75 forks source link

Current Datetime Creator #296

Open jrleeman opened 4 years ago

jrleeman commented 4 years ago

Doing this to get data is clunky (say for the top of the current hour):

date = datetime.utcnow()
request_time = date.replace(minute=0, second=0, microsecond=0)
ds = cat.datasets.filter_time_nearest(request_time)

What about a utcnow type function that takes a precision argument or similar that zeros out everything smaller than it:

roundedutcnow(precision='day')  # or month, hour, minute, second

Naming is the hard thing here, but it sure seems useful - or maybe its a rounder that operates on a datetime?

dopplershift commented 4 years ago

I think the feature seems reasonable. Could also make it take a datetime as an optional argument, defaulting to utcnow.