def test_two_1d_from_lookup_tables(time_lut): """ Create ExtraCoords from both tables at once using `from_lookup_tables` with `physical_types`. """ exposure_lut = range(10) * u.s pt = ["custom:time:creation"] with pytest.raises(ValueError, match=r"The number of physical types and lookup_tables"): ec = ExtraCoords.from_lookup_tables(["time", "exposure_time"], (0, 0), [time_lut, exposure_lut], pt) pt.append("custom:time:duration") ec = ExtraCoords.from_lookup_tables(["time", "exposure_time"], (0, 0), [time_lut, exposure_lut], pt) # This has created an "orphan" extra_coords with no NDCube connected. with pytest.raises(AttributeError, match=r"'NoneType' object has no attribute 'dimensions'"): assert ec.mapping == (0, 0) assert len(ec._lookup_tables) == 2 assert isinstance(ec.wcs, gwcs.WCS) assert ec.wcs.pixel_n_dim == 2 assert ec.wcs.world_n_dim == 2 assert ec.wcs.world_axis_names == ("time", "exposure_time") for i, physical_types in enumerate(pt): assert ec._lookup_tables[i][1].physical_types == [physical_types]
def test_exceptions(wcs_1d_l): # Test unable to specify inconsistent dimensions and tables with pytest.raises(ValueError): ExtraCoords.from_lookup_tables(None, (0,), (0, 0)) # Test unable to add to WCS EC ec = ExtraCoords() ec.wcs = wcs_1d_l ec.mapping = (0,) with pytest.raises(ValueError): ec.add(None, 0, None) with pytest.raises(KeyError): ExtraCoords()['empty']
def test_single_from_lut(wave_lut): ec = ExtraCoords.from_lookup_tables(("wave", ), (0, ), (wave_lut, )) assert len(ec._lookup_tables) == 1 assert ec.mapping == (0, ) assert isinstance(ec.wcs, gwcs.WCS) assert ec.wcs.pixel_n_dim == 1 assert ec.wcs.world_n_dim == 1 assert ec.wcs.world_axis_names == ("wave", )
def test_skycoord(skycoord_1d_lut): ec = ExtraCoords.from_lookup_tables((("lat", "lon"), ), ((0, 1), ), (skycoord_1d_lut, )) assert len(ec._lookup_tables) == 1 assert ec.mapping == (0, 1) assert isinstance(ec.wcs, gwcs.WCS) assert ec.wcs.pixel_n_dim == 2 assert ec.wcs.world_n_dim == 2 assert ec.wcs.world_axis_names == ("lat", "lon")
def test_exceptions(wcs_1d_l): # Test fail when one of wcs or mapping specified with pytest.raises(ValueError): ExtraCoords(wcs=wcs_1d_l) with pytest.raises(ValueError): ExtraCoords(mapping=0) # Test unable to specify inconsistent dimensions and tables with pytest.raises(ValueError): ExtraCoords.from_lookup_tables(None, (0, ), (0, 0)) # Test unable to add to WCS EC ec = ExtraCoords(wcs=wcs_1d_l, mapping=(0, )) with pytest.raises(ValueError): ec.add_coordinate(None, 0, None) with pytest.raises(KeyError): ExtraCoords()['empty']
def test_two_1d_from_lut(time_lut): exposure_lut = range(10) * u.s ec = ExtraCoords.from_lookup_tables(("time", "exposure_time"), (0, 0), (time_lut, exposure_lut)) assert len(ec._lookup_tables) == 2 assert ec.mapping == (0, 0) assert isinstance(ec.wcs, gwcs.WCS) assert ec.wcs.pixel_n_dim == 2 assert ec.wcs.world_n_dim == 2 assert ec.wcs.world_axis_names == ("time", "exposure_time")