Skip to content

Commit

Permalink
Change source string for RNOG mongo detector
Browse files Browse the repository at this point in the history
  • Loading branch information
fschlueter committed Jan 25, 2024
1 parent 89e86bd commit 9bde5c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NuRadioReco/detector/RNO_G/rnog_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def _get_time_delay(self):

from NuRadioReco.detector import detector

det = detector.Detector(source="mongo", log_level=logging.DEBUG, always_query_entire_description=False,
det = detector.Detector(source="rnog_mongo", log_level=logging.DEBUG, always_query_entire_description=False,
database_connection='RNOG_public', select_stations=24)

det.update(datetime.datetime(2023, 8, 2, 0, 0))
17 changes: 10 additions & 7 deletions NuRadioReco/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def Detector(*args, **kwargs):
This function returns a detector class object. It chooses the correct class based on the "source" argument.
The returned object is of one of these classes:
- kwargs["source'] == "mongo" -> `NuRadioReco.detector.RNO_G.rnog_detector`
- kwargs["source'] == "rnog_mongo" -> `NuRadioReco.detector.RNO_G.rnog_detector`
- kwargs["source'] == "sql" -> `NuRadioReco.detector.detector_base`
- kwargs["source'] == "json" or "dictionary" -> `NuRadioReco.detector.detector_base` or
`NuRadioReco.detector.generic_detector`
Expand Down Expand Up @@ -82,9 +82,9 @@ def Detector(*args, **kwargs):
# when source is sql | json | dictionary
# json_filename = args[0] is used below (when source == 'json').
if len(args) >= 2:
source = args[1]
source = args[1].lower()
else:
source = kwargs.pop("source", "json")
source = kwargs.pop("source", "json").lower()

if len(args) >= 3:
dictionary = args[2]
Expand All @@ -107,7 +107,7 @@ def Detector(*args, **kwargs):
json_filename=None, source=source, dictionary=dictionary,
assume_inf=assume_inf, antenna_by_depth=antenna_by_depth)

elif source == "mongo":
elif source == "rnog_mongo":
return rnog_detector.Detector(*args, **kwargs)

elif source == "dictionary":
Expand All @@ -134,14 +134,16 @@ def Detector(*args, **kwargs):
station_dict = json.load(f)

else:
raise ValueError(f'Unknown source specifed (\"{source}\"). Must be one of \"json\", \"sql\", "\dictionary\", \"mongo\"')
raise ValueError(f'Unknown source specifed (\"{source}\"). '
f'Must be one of \"json\", \"sql\", "\dictionary\", \"mongo\"')

has_reference_entry = find_reference_entry(station_dict)

if source == 'json':
f.close()

has_default = np.any([arg in kwargs and kwargs[arg] is not None for arg in ["default_station", "default_channel", "default_device"]])
has_default = np.any([arg in kwargs and kwargs[arg] is not None
for arg in ["default_station", "default_channel", "default_device"]])

if has_reference_entry or has_default:
if has_default:
Expand All @@ -150,7 +152,8 @@ def Detector(*args, **kwargs):
'channel should be specified in the detector description directly.')

if "default_station" in kwargs:
logging.info(f'Default detector station provided (station {kwargs["default_station"]}) -> Using generic detector')
logging.info('Default detector station provided (station '
f'{kwargs["default_station"]}) -> Using generic detector')

return generic_detector.GenericDetector(
json_filename=filename, source=source, dictionary=dictionary,
Expand Down
4 changes: 2 additions & 2 deletions NuRadioReco/detector/test/test_rnog_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

def test_detector():

det = detector.Detector(source="mongo", log_level=logging.DEBUG, always_query_entire_description=True,
det = detector.Detector(source="rnog_mongo", log_level=logging.DEBUG, always_query_entire_description=True,
database_connection='RNOG_public', select_stations=24)
det.update(datetime.datetime(2023, 8, 2, 0, 0))
det.export("station24.json.xz")

det2 = detector.Detector(source="mongo", detector_file="station24.json.xz", select_stations=24)
det2 = detector.Detector(source="rnog_mongo", detector_file="station24.json.xz", select_stations=24)
det2.update(datetime.datetime(2023, 8, 2, 0, 0))

response = det.get_signal_chain_response(24, 0)
Expand Down

0 comments on commit 9bde5c9

Please sign in to comment.