Skip to content

Commit

Permalink
Modify getter and setter for station._station_time. Now the time form…
Browse files Browse the repository at this point in the history
…at is not controlled/converted during setting but only during getting. This makes the code more readable but the state interally is undefined (but its only the format)
  • Loading branch information
Felix Schlüter committed Mar 30, 2023
1 parent c508e46 commit 027aa09
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions NuRadioReco/framework/base_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,41 @@ def remove_parameter(self, key):
self._parameters.pop(key, None)

def set_station_time(self, time):
if time is None:
self._station_time = None
return
"""
Set the (absolute) time for the station (stored as astropy.time.Time).
Not related to the event._event_time.
Parameters
----------
time: astropy.time.Time or datetime.datetime or float
If time is a float it is interpreted as UTC unix timestamp.
"""

if isinstance(time, datetime.datetime):
time_strings = str(time).split(' ')
self._station_time = astropy.time.Time('{}T{}'.format(time_strings[0], time_strings[1]), format='isot')
self._station_time = astropy.time.Time(time)
elif isinstance(time, astropy.time):
self._station_time = time
else:
if time.format == 'datetime':
time_strings = str(time).split(' ')
self._station_time = astropy.time.Time('{}T{}'.format(time_strings[0], time_strings[1]), format='isot')
else:
self._station_time = time
# time is interpreted as unix utc timestamp
self._station_time = astropy.time.Time(time, format='unix')

def get_station_time(self):
def get_station_time(self, format='isot'):
"""
Returns a astropy.time.Time object
Parameters
----------
format: str
Format in which the time object is displayed. (Default: isot)
Returns
-------
_station_time: astropy.time.Time
"""
self._station_time.format = format
return self._station_time

def get_id(self):
Expand Down

0 comments on commit 027aa09

Please sign in to comment.