Skip to content

Commit

Permalink
Merge pull request #790 from gammasim/all_telescopes_in_db
Browse files Browse the repository at this point in the history
Add a function that returns all telescope names available in the DB
  • Loading branch information
orelgueta authored Jan 25, 2024
2 parents c05ccba + efc6210 commit f92fbcc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
37 changes: 37 additions & 0 deletions simtools/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,3 +1442,40 @@ def get_all_versions(
self._logger.warning(f"The query {query} did not return any results. No versions found")

return _all_versions

def get_all_available_telescopes(
self,
db_name=DB_CTA_SIMULATION_MODEL,
model_version="Released",
):
"""
Get all available telescope names in the collection "telescopes" in the DB.
Parameters
----------
db_name: str
the name of the DB
model_version: str
Which version to get the telescopes of (default: "Released").
Returns
-------
all_available_telescopes: list
List of all telescope names found
"""

collection = DatabaseHandler.db_client[db_name]["telescopes"]

_model_version = self._convert_version_to_tagged(
names.validate_model_version_name(model_version),
DatabaseHandler.DB_CTA_SIMULATION_MODEL,
)

query = {
"Version": _model_version,
}

_all_available_telescopes = collection.find(query).distinct("Telescope")

return _all_available_telescopes
22 changes: 22 additions & 0 deletions tests/unit_tests/test_db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,25 @@ def test_get_descriptions(db):
== "File name for the quantum efficiency curve."
)
assert descriptions["camera_pixels"]["description"] == "Number of pixels per camera."


def test_get_all_available_telescopes(db):
available_telescopes = db.get_all_available_telescopes(model_version="Prod5")

expected_telescope_names = [
"North-LST-1",
"North-LST-D234",
"North-MST-FlashCam-D",
"North-MST-NectarCam-D",
"North-MST-Structure-D",
"South-LST-D",
"South-MST-FlashCam-D",
"South-MST-Structure-D",
"South-SCT-D",
"South-SST-1M-D",
"South-SST-ASTRI-D",
"South-SST-Camera-D",
"South-SST-GCT-D",
"South-SST-Structure-D",
]
assert all(_t in available_telescopes for _t in expected_telescope_names)

0 comments on commit f92fbcc

Please sign in to comment.