def test_hdf_duplicate_string_repr(tmp_path): """Test writing and reading of a subarray with two telescopes that are different but have the same name. """ # test with a subarray that has two different telescopes with the same # camera tel1 = TelescopeDescription.from_name(optics_name="LST", camera_name="LSTCam") # second telescope is almost the same and as the same str repr tel2 = deepcopy(tel1) # e.g. one mirror fell off tel2.optics.num_mirror_tiles = tel1.optics.num_mirror_tiles - 1 array = SubarrayDescription( "test array", tel_positions={1: [0, 0, 0] * u.m, 2: [50, 0, 0] * u.m}, tel_descriptions={1: tel1, 2: tel2}, ) # defensive checks to make sure we are actually testing this assert len(array.telescope_types) == 2 assert str(tel1) == str(tel2) assert tel1 != tel2 path = tmp_path / "subarray.h5" array.to_hdf(path) read = SubarrayDescription.from_hdf(path) assert array == read assert ( read.tel[1].optics.num_mirror_tiles == read.tel[2].optics.num_mirror_tiles + 1 )
def test_hdf(example_subarray): import tables with tempfile.NamedTemporaryFile(suffix=".hdf5") as f: example_subarray.to_hdf(f.name) read = SubarrayDescription.from_hdf(f.name) assert example_subarray == read # test that subarrays without name (v0.8.0) work: with tables.open_file(f.name, "r+") as hdf: del hdf.root.configuration.instrument.subarray._v_attrs.name no_name = SubarrayDescription.from_hdf(f.name) assert no_name.name == "Unknown" # test with a subarray that has two different telescopes with the same # camera tel = { 1: TelescopeDescription.from_name(optics_name="SST-ASTRI", camera_name="CHEC"), 2: TelescopeDescription.from_name(optics_name="SST-GCT", camera_name="CHEC"), } pos = {1: [0, 0, 0] * u.m, 2: [50, 0, 0] * u.m} array = SubarrayDescription("test array", tel_positions=pos, tel_descriptions=tel) with tempfile.NamedTemporaryFile(suffix=".hdf5") as f: array.to_hdf(f.name) read = SubarrayDescription.from_hdf(f.name) assert array == read
def test_hdf(example_subarray): import tables with tempfile.NamedTemporaryFile(suffix=".hdf5") as f: example_subarray.to_hdf(f.name) read = SubarrayDescription.from_hdf(f.name) assert example_subarray == read # test we can write the read subarray read.to_hdf(f.name, overwrite=True) for tel_id, tel in read.tel.items(): assert (tel.camera.geometry.frame.focal_length == tel.optics.equivalent_focal_length) # test if transforming works tel.camera.geometry.transform_to(TelescopeFrame()) # test that subarrays without name (v0.8.0) work: with tables.open_file(f.name, "r+") as hdf: del hdf.root.configuration.instrument.subarray._v_attrs.name no_name = SubarrayDescription.from_hdf(f.name) assert no_name.name == "Unknown" # test with a subarray that has two different telescopes with the same # camera tel = { 1: TelescopeDescription.from_name(optics_name="SST-ASTRI", camera_name="CHEC"), 2: TelescopeDescription.from_name(optics_name="SST-GCT", camera_name="CHEC"), } pos = {1: [0, 0, 0] * u.m, 2: [50, 0, 0] * u.m} array = SubarrayDescription("test array", tel_positions=pos, tel_descriptions=tel) with tempfile.NamedTemporaryFile(suffix=".hdf5") as f: array.to_hdf(f.name) read = SubarrayDescription.from_hdf(f.name) assert array == read
def test_hdf_same_camera(tmp_path): """Test writing / reading subarray to hdf5 with a subarray that has two different telescopes with the same camera """ tel = { 1: TelescopeDescription.from_name(optics_name="SST-ASTRI", camera_name="CHEC"), 2: TelescopeDescription.from_name(optics_name="SST-GCT", camera_name="CHEC"), } pos = {1: [0, 0, 0] * u.m, 2: [50, 0, 0] * u.m} array = SubarrayDescription("test array", tel_positions=pos, tel_descriptions=tel) path = tmp_path / "subarray.h5" array.to_hdf(path) read = SubarrayDescription.from_hdf(path) assert array == read