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

Raise error in CameraReadout.from_name if no corresponding file can be found #1703

Merged
merged 2 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ctapipe/instrument/camera/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def from_name(cls, camera_name):
"""

geometry = CameraGeometry.from_name(camera_name)
readout = CameraReadout.from_name(camera_name)
try:
readout = CameraReadout.from_name(camera_name)
except FileNotFoundError:
readout = None
return cls(camera_name=camera_name, geometry=geometry, readout=readout)

def __str__(self):
Expand Down
24 changes: 5 additions & 19 deletions ctapipe/instrument/camera/readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,11 @@ def from_name(cls, camera_name="NectarCam", version=None):
else:
verstr = f"-{version:03d}"

try:
tabname = "{camera_name}{verstr}.camreadout".format(
camera_name=camera_name, verstr=verstr
)
table = get_table_dataset(tabname, role="dl0.tel.svc.camera")
return CameraReadout.from_table(table)
except FileNotFoundError:
# TODO: remove case when files have been generated
logger.warning(
f"Resorting to default CameraReadout,"
f" File does not exist: ({tabname})"
)
reference_pulse_shape = np.array([norm.pdf(np.arange(96), 48, 6)])
return cls(
camera_name=camera_name,
sampling_rate=u.Quantity(1, u.GHz),
reference_pulse_shape=reference_pulse_shape,
reference_pulse_sample_width=u.Quantity(1, u.ns),
)
tabname = "{camera_name}{verstr}.camreadout".format(
camera_name=camera_name, verstr=verstr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use f-string syntax?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add/change this code, just removed a try except around. There is no real reason to remove format

)
table = get_table_dataset(tabname, role="dl0.tel.svc.camera")
return CameraReadout.from_table(table)

def to_table(self):
"""Convert this to an `astropy.table.Table`."""
Expand Down
10 changes: 8 additions & 2 deletions ctapipe/instrument/camera/tests/test_readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,11 @@ def test_hashing():
@pytest.mark.parametrize("camera_name", camera_names)
def test_camera_from_name(camera_name):
""" check we can construct all cameras from name"""
camera = CameraReadout.from_name(camera_name)
assert str(camera) == camera_name

try:
camera = CameraReadout.from_name(camera_name)
assert str(camera) == camera_name
except FileNotFoundError:
# these two don't have readout definitions on the dataserver
if camera_name not in ["MAGICCam", "Whipple109"]:
raise