Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve reading of design models; refactoring and improved docstrings for simtools.utils.names #1396

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions docs/changes/1390.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve function naming and unit test coverage in `simtools.utils.names`.
1 change: 1 addition & 0 deletions docs/changes/1396.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve reading of design models; refactoring and improved docstrings for `simtools.utils.names`.
6 changes: 4 additions & 2 deletions src/simtools/applications/generate_regular_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def main():
# Single telescope at the center
if array_name[0] == "1":
tel_name.append(
names.get_array_element_name_from_type_site_id(tel_size, args_dict["site"], "01")
names.generate_array_element_name_from_type_site_id(
tel_size, args_dict["site"], "01"
)
)
pos_x.append(0 * u.m)
pos_y.append(0 * u.m)
Expand All @@ -86,7 +88,7 @@ def main():
else:
for i in range(1, 5):
tel_name.append(
names.get_array_element_name_from_type_site_id(
names.generate_array_element_name_from_type_site_id(
tel_size, args_dict["site"], f"0{i}"
)
)
Expand Down
17 changes: 11 additions & 6 deletions src/simtools/db/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,20 @@
return ["xSTx-design"] # placeholder to ignore 'instrument' field in query.
if collection == "sites":
return [f"OBS-{site}"]
if "-design" in array_element_name:
if names.is_design_type(array_element_name):
return [array_element_name]
if collection == "configuration_sim_telarray":
# get design model from 'telescope' or 'calibration_device' production tables
production_table = self._read_production_table_from_mongo_db(
names.get_collection_name_from_array_element_name(array_element_name),
production_table["model_version"],
)
try:
return [
production_table["design_model"][array_element_name],
array_element_name,
]
except KeyError:
return [
names.guess_design_model_from_name(array_element_name),
array_element_name,
]
except KeyError as exc:
raise KeyError(

Check warning on line 879 in src/simtools/db/db_handler.py

View check run for this annotation

Codecov / codecov/patch

src/simtools/db/db_handler.py#L878-L879

Added lines #L878 - L879 were not covered by tests
f"Failed generated array element list for db query for {array_element_name}"
) from exc
6 changes: 4 additions & 2 deletions src/simtools/layout/array_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,11 @@
)
try:
tel_model = self._get_telescope_model(telescope_name)
except ValueError:
except ValueError: # telescope not found in the database revert to design model

Check warning on line 448 in src/simtools/layout/array_layout.py

View check run for this annotation

Codecov / codecov/patch

src/simtools/layout/array_layout.py#L448

Added line #L448 was not covered by tests
tel_model = self._get_telescope_model(
names.guess_design_model_from_name(telescope_name),
names.array_element_design_types(
names.get_array_element_type_from_name(telescope_name)
)[0]
)

for para in ("telescope_axis_height", "telescope_sphere_radius"):
Expand Down
4 changes: 2 additions & 2 deletions src/simtools/reporting/docs_read_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def get_all_parameter_descriptions(self):
"""
parameter_description, short_description, inst_class = {}, {}, {}

for instrument_class in names.instrument_classes("telescope"):
for parameter, details in names.load_model_parameters(instrument_class).items():
for instrument_class in names.db_collection_to_instrument_class_key("telescopes"):
for parameter, details in names.model_parameters(instrument_class).items():
parameter_description[parameter] = details.get("description")
short_description[parameter] = details.get("short_description")
inst_class[parameter] = instrument_class
Expand Down
4 changes: 3 additions & 1 deletion src/simtools/schemas/array_elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data:
collection: "telescopes"
observatory: "CTAO"
site: "North"
design_types: ["FlashCam", "NectarCam", "test"]
LSTS:
collection: "telescopes"
observatory: "CTAO"
Expand All @@ -23,6 +24,7 @@ data:
collection: "telescopes"
observatory: "CTAO"
site: "South"
design_types: ["FlashCam", "NectarCam", "test"]
SSTS:
collection: "telescopes"
observatory: "CTAO"
Expand All @@ -37,7 +39,7 @@ data:
collection: "telescopes"
observatory: "CTAO"
site: ["North", "South"]
design_types: ["design", "test", "FlashCam", "NectarCam"]
design_types: ["FlashCam", "NectarCam", "test"]
description: "Mid-sized telescope"
ILLN:
collection: "calibration_devices"
Expand Down
Loading
Loading