Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
First importing import astropy.time as t
Input instances for time_string |
Current working of parse_time | Proposed changes to return astropy.Time |
---|---|---|
astropy.Time |
return time_string.datetime |
return time_string |
now |
return datetime.utcnow() |
return t.Time.now() |
pandas.Timeseries |
return time_string.to_pydatetime() |
return t.Time(time_string) |
isinstance(time_string, pandas.Series) and 'datetime64' in str(time_string.dtype) |
return np.array([dt.to_pydatetime() for dt in time_string]) |
return np.array([t.Time(dt) for dt in time_string]) |
datetime |
return time_string |
return t.Time(time_string) |
tuple |
return datetime(*time_string) |
if time = (2018,10,3,10,43,5,6) see code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_time(time_string, time_format='', **kwargs): | |
if isinstance(time_string, date): | |
dat = (''.join("{}-" for i in range(len(time_string.timetuple()[0:3])))).rstrip('-') | |
return T.Time(dat.format(*time_string.timetuple()[0:3]) + " " + datetime.time().isoformat()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import astropy.Time as T | |
def parse_time(time_string, time_format='', **kwargs): | |
if time_format == 'utime' or isinstance(time_string, (int, float)): | |
return T.Time(T.Time('1979-01-01')) + T.TimeDelta(time_string, format = 'sec') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import astropy.Time as T | |
def _parse_dt64(dt): | |
""" | |
Parse a single numpy datetime64 object | |
""" | |
# Validate (in an agnostic way) that we are getting a datetime rather than a date | |
s= ((dt.astype(T.Time).timetuple()[:6])) | |
return T.Time('{}-{}-{}'.format(*s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_time(time, time_format='', **kwargs): | |
# for example time = (2018,10,3,10,43,5,6) | |
if isinstance(time_string, tuple): | |
dat = (''.join("{}-" for i in range(len(time[0:3])))).rstrip('-') | |
tim = (''.join("{}:" for i in range(len(time[3:6])))).rstrip(':') | |
mill_sec = (''.join(".{}" for i in range(len(time[6:])))).rstrip(':') | |
return T.Time((dat + " " + tim + mill_sec).format(*time)) |
OlderNewer