Skip to content

Commit

Permalink
Only remove whitespace. Often from my code.
Browse files Browse the repository at this point in the history
  • Loading branch information
fschlueter committed Dec 20, 2023
1 parent 190b9c7 commit 97e55cd
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 144 deletions.
36 changes: 20 additions & 16 deletions NuRadioReco/detector/detector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, source='json', json_filename='ARIANNA/arianna_detector_db.jso
is returned. To force the creation of a new detector instance, pass the additional keyword parameter
`create_new=True` to this function. For more details, check the documentation for the
`Singleton metaclass <NuRadioReco.utilities.html#NuRadioReco.utilities.metaclasses.Singleton>`_.
Parameters
----------
source : str
Expand Down Expand Up @@ -231,7 +231,7 @@ def _query_channels(self, station_id):
return self._channels.search((Channel.station_id == station_id)
& (Channel.commission_time <= self.__current_time.datetime)
& (Channel.decommission_time > self.__current_time.datetime))

def _query_devices(self, station_id):
Device = Query()
if self.__current_time is None:
Expand Down Expand Up @@ -305,13 +305,13 @@ def __get_channel(self, station_id, channel_id):
if station_id not in self._buffered_stations.keys():
self._buffer(station_id)
return self._buffered_channels[station_id][channel_id]


def __get_devices(self, station_id):
if station_id not in self._buffered_stations.keys():
self._buffer(station_id)
return self._buffered_devices[station_id]

def __get_device(self, station_id, device_id):
if station_id not in self._buffered_stations.keys():
self._buffer(station_id)
Expand All @@ -333,7 +333,7 @@ def _buffer(self, station_id):
self._buffered_devices[station_id][device['device_id']] = device
self.__valid_t0 = max(self.__valid_t0, astropy.time.Time(channel['commission_time']))
self.__valid_t1 = min(self.__valid_t1, astropy.time.Time(channel['decommission_time']))


def __buffer_position(self, position_id):
self.__buffered_positions[position_id] = self.__query_position(position_id)
Expand Down Expand Up @@ -411,6 +411,7 @@ def update(self, time):
self.__current_time = astropy.time.Time(time)
else:
self.__current_time = time

logger.info("updating detector time to {}".format(self.__current_time))
if not ((self.__current_time > self.__valid_t0) and (self.__current_time < self.__valid_t1)):
self._buffered_stations = {}
Expand Down Expand Up @@ -440,8 +441,8 @@ def get_channel(self, station_id, channel_id):
dict of channel parameters
"""
return self.__get_channel(station_id, channel_id)


def get_device(self, station_id, device_id):
"""
returns a dictionary of all device parameters
Expand Down Expand Up @@ -530,11 +531,14 @@ def get_relative_position(self, station_id, channel_id, mode = 'channel'):
-------
3-dim array of relative station position
"""
if mode == 'channel': res = self.__get_channel(station_id, channel_id)
elif mode == 'device': res = self.__get_device(station_id, channel_id)
else:
if mode == 'channel':
res = self.__get_channel(station_id, channel_id)
elif mode == 'device':
res = self.__get_device(station_id, channel_id)
else:
logger.error("Mode {} does not exist. Use 'channel' or 'device'".format(mode))
raise NameError

return np.array([res['ant_position_x'], res['ant_position_y'], res['ant_position_z']])

def get_site(self, station_id):
Expand Down Expand Up @@ -639,10 +643,10 @@ def get_parallel_channels(self, station_id):
if np.sum(mask):
parallel_antennas.append(channel_ids[mask])
return np.array(parallel_antennas)




def get_number_of_devices(self, station_id):
"""
Get the number of devices per station
Expand Down Expand Up @@ -921,7 +925,7 @@ def get_noise_RMS(self, station_id, channel_id, stage='amp'):
stage: string (default 'amp')
specifies the stage of reconstruction you want the noise RMS for,
`stage` can be one of
* 'raw' (raw measured trace)
* 'amp' (after the amp was deconvolved)
* 'filt' (after the trace was highpass with 100MHz
Expand Down
16 changes: 8 additions & 8 deletions NuRadioReco/framework/base_shower.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ def has_parameter(self, key):

def get_axis(self):
"""
Returns the (shower) axis.
Returns the (shower) axis.
The axis is antiparallel to the movement of the shower particla and point
towards the origin of the shower.
Returns
-------
np.array(3,)
np.array(3,)
Shower axis
"""
if not self.has_parameter(parameters.showerParameters.azimuth) or \
not self.has_parameter(parameters.showerParameters.zenith):
Expand All @@ -66,18 +66,18 @@ def get_axis(self):
self.get_parameter(parameters.showerParameters.azimuth))

def get_coordinatesystem(self):
"""
"""
Returns radiotools.coordinatesystem.cstrafo for shower geometry.
Can be used to transform the radio pulses or the observer coordiates
in the shower frame. Requieres the shower arrival direction
in the shower frame. Requieres the shower arrival direction
(azimuth and zenith angle) and magnetic field vector (parameters.showerParameters).
Returns
-------
radiotools.coordinatesystem.cstrafo
"""
if not self.has_parameter(parameters.showerParameters.azimuth) or \
not self.has_parameter(parameters.showerParameters.zenith) or \
Expand Down
36 changes: 18 additions & 18 deletions NuRadioReco/framework/base_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ def remove_parameter(self, key):
self._parameters.pop(key, None)

def set_station_time(self, time, format=None):
"""
"""
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, you have to specify its format.
If "time" is a float, you have to specify its format.
format: str
Only used when "time" is a float. Format to interpret "time". (Default: None)
Only used when "time" is a float. Format to interpret "time". (Default: None)
"""

if isinstance(time, datetime.datetime):
Expand All @@ -100,26 +100,26 @@ def set_station_time(self, time, format=None):
self._station_time = astropy.time.Time(time, format=format)

def get_station_time(self, format='isot'):
"""
Returns a astropy.time.Time object
"""
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
"""
if self._station_time is None:
return None

self._station_time.format = format
return self._station_time

def get_station_time_dict(self):
""" Return the station time as dict {value, format}. Used for reading and writing """
if self._station_time is None:
Expand Down Expand Up @@ -270,13 +270,13 @@ def serialize(self, save_efield_traces):
trigger_pkls = []
for trigger in self._triggers.values():
trigger_pkls.append(trigger.serialize())

efield_pkls = []
for efield in self.get_electric_fields():
efield_pkls.append(efield.serialize(save_trace=save_efield_traces))

station_time_dict = self.get_station_time_dict()

data = {'_parameters': NuRadioReco.framework.parameter_serialization.serialize(self._parameters),
'_parameter_covariances': NuRadioReco.framework.parameter_serialization.serialize_covariances(self._parameter_covariances),
'_ARIANNA_parameters': self._ARIANNA_parameters,
Expand All @@ -286,7 +286,7 @@ def serialize(self, save_efield_traces):
'triggers': trigger_pkls,
'_triggered': self._triggered,
'electric_fields': efield_pkls}

return pickle.dumps(data, protocol=4)

def deserialize(self, data_pkl):
Expand All @@ -308,7 +308,7 @@ def deserialize(self, data_pkl):

self._parameter_covariances = NuRadioReco.framework.parameter_serialization.deserialize_covariances(
data['_parameter_covariances'], parameters.stationParameters)

if '_ARIANNA_parameters' in data:
self._ARIANNA_parameters = data['_ARIANNA_parameters']

Expand Down
2 changes: 1 addition & 1 deletion NuRadioReco/framework/electric_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, channel_ids, position=None,
Parameters
----------
channel_ids: array of ints
the channels ids this electric field is valid for.
the channels ids this electric field is valid for.
(For cosmic rays one electric field is typically valid
for several channels. For neutrino simulations, we typically
simulate the electric field for each
Expand Down
28 changes: 14 additions & 14 deletions NuRadioReco/framework/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def register_module_event(self, instance, name, kwargs):
kwargs:
the key word arguments of the run method
"""

self.__modules_event.append([name, instance, kwargs])

def register_module_station(self, station_id, instance, name, kwargs):
Expand All @@ -61,7 +61,7 @@ def register_module_station(self, station_id, instance, name, kwargs):
"""
if station_id not in self.__modules_station:
self.__modules_station[station_id] = []

iE = len(self.__modules_event)
self.__modules_station[station_id].append([iE, name, instance, kwargs])

Expand Down Expand Up @@ -164,7 +164,7 @@ def get_station_ids(self):

def set_station(self, station):
self.__stations[station.get_id()] = station

def has_triggered(self, trigger_name=None):
"""
Returns true if any station has been triggered.
Expand All @@ -175,16 +175,16 @@ def has_triggered(self, trigger_name=None):
* if None: The function returns False if not trigger was set. If one or multiple triggers were set,
it returns True if any of those triggers triggered
* if trigger name is set: return if the trigger with name 'trigger_name' has a trigger
Returns
-------
has_triggered : bool
"""
for station in self.get_stations():
if station.has_triggered(trigger_name):
return True

# if it reaches this point, no station has a trigger
return False

Expand All @@ -200,11 +200,11 @@ def add_particle(self, particle):
if not isinstance(particle, NuRadioReco.framework.particle.Particle):
logger.error("Requested to add non-Particle item to the list of particles. {particle} needs to be an instance of Particle.")
raise TypeError("Requested to add non-Particle item to the list of particles. {particle} needs to be an instance of Particle.")

if particle.get_id() in self.__particles:
logger.error("MC particle with id {particle.get_id()} already exists. Simulated particle id needs to be unique per event")
raise AttributeError("MC particle with id {particle.get_id()} already exists. Simulated particle id needs to be unique per event")

self.__particles[particle.get_id()] = particle

def get_particles(self):
Expand Down Expand Up @@ -254,13 +254,13 @@ def has_particle(self, particle_id=None):
"""
if particle_id is None:
return len(self.__particles) > 0

return particle_id in self.__particles.keys()

def get_interaction_products(self, parent_particle, showers=True, particles=True):
"""
Return all the daughter particles and showers generated in the interaction of the <parent_particle>
Parameters
----------
showers: bool
Expand Down Expand Up @@ -437,9 +437,9 @@ def serialize(self, mode):
showers_pkl = [shower.serialize() for shower in self.get_showers()]
sim_showers_pkl = [shower.serialize() for shower in self.get_sim_showers()]
particles_pkl = [particle.serialize() for particle in self.get_particles()]

hybrid_info = self.__hybrid_information.serialize()

modules_out_event = []
for value in self.__modules_event: # remove module instances (this will just blow up the file size)
modules_out_event.append([value[0], None, value[2]])
Expand Down Expand Up @@ -493,11 +493,11 @@ def deserialize(self, data_pkl):
particle = NuRadioReco.framework.particle.Particle(None)
particle.deserialize(particle_pkl)
self.add_particle(particle)

self.__hybrid_information = NuRadioReco.framework.hybrid_information.HybridInformation()
if 'hybrid_info' in data.keys():
self.__hybrid_information.deserialize(data['hybrid_info'])

self._parameters = data['_parameters']
self.__run_number = data['__run_number']
self._id = data['_id']
Expand Down
4 changes: 2 additions & 2 deletions NuRadioReco/framework/parameters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Provides an interface to store simulated and reconstructed quantities
The parameters module provides access to store and read simulated or
The parameters module provides access to store and read simulated or
reconstructed quantities in the different custom classes used in NuRadioMC.
"""
Expand Down Expand Up @@ -36,7 +36,7 @@ class stationParameters(Enum):
cr_xmax = 28 #: Depth of shower maximum of the air shower
vertex_2D_fit = 29 #: horizontal distance and z coordinate of the reconstructed vertex of the neutrino
distance_correlations = 30
shower_energy = 31 #: the energy of the shower
shower_energy = 31 #: the energy of the shower
viewing_angles = 32 #: reconstructed viewing angles. A nested map structure. First key is channel id, second key is ray tracing solution id. Value is a float


Expand Down
Loading

0 comments on commit 97e55cd

Please sign in to comment.