def test_wrong_force_load(self, galaxy): x = galaxy.dap['x'] y = galaxy.dap['y'] spaxel = SpaxelBase(x, y, plateifu=galaxy.plateifu, cube=True, maps=False, modelcube=False) with pytest.raises(AssertionError) as ee: spaxel.load(force='crap') assert 'force can only be cube, maps, or models' in str(ee)
def test_load_all(self): bb = SpaxelBase(15, 15, plateifu='8485-1901', cube=True, maps=True, modelcube=True, bintype='HYB10', release='MPL-6') assert isinstance(bb, Bin) assert len(bb.spaxels) > 0 assert bb.spaxels[0].loaded is False bb.load_all() for sp in bb.spaxels: assert sp.loaded is True
def test_pickling_only_cube_file(self, temp_scratch, galaxy): if galaxy.bintype.name != 'SPX': pytest.skip("Can't instantiate a Spaxel from a binned Maps.") cube = Cube(filename=galaxy.cubepath) maps = Maps(filename=galaxy.mapspath) spaxel = cube.getSpaxel(1, 3, properties=maps, models=False) file = temp_scratch.join('test_spaxel.mpf') path_saved = spaxel.save(str(file), overwrite=True) assert file.check() is True assert os.path.exists(path_saved) del spaxel spaxel_restored = SpaxelBase.restore(str(file)) assert spaxel_restored is not None assert isinstance(spaxel_restored, SpaxelBase) assert spaxel_restored._cube is not None assert spaxel_restored._cube.data_origin == 'file' assert isinstance(spaxel_restored._cube.data, astropy.io.fits.HDUList) assert spaxel_restored._maps is not None assert spaxel_restored._maps.data_origin == 'file' assert isinstance(spaxel_restored._maps.data, astropy.io.fits.HDUList)
def test_bad_binid(self): with pytest.raises(MarvinError) as ee: SpaxelBase(0, 0, plateifu='8485-1901', cube=True, maps=True, modelcube=True, bintype='HYB10') assert 'do not correspond to a valid binid' in str(ee) or 'invalid bintype' in str(ee)
def test_force_load(self, galaxy, force): x = galaxy.dap['x'] y = galaxy.dap['y'] spaxel = SpaxelBase(x, y, plateifu=galaxy.plateifu, cube=True, maps=False, modelcube=False) assert spaxel.cube_quantities is not None assert spaxel.maps_quantities == {} assert spaxel.modelcube_quantities == {} spaxel.load(force=force) if force == 'cube': assert spaxel.cube_quantities is not None elif force == 'maps': assert spaxel.maps_quantities is not None elif force == 'models': assert spaxel.modelcube_quantities is not None
def test_getattr(self, galaxy): x = galaxy.dap['x'] y = galaxy.dap['y'] spaxel = SpaxelBase(x, y, plateifu='8485-1901', cube=True, maps=True, modelcube=True) assert spaxel.flux is not None assert spaxel.emline_gflux_ha_6564 is not None assert spaxel.binned_flux is not None
def test_dir(self, galaxy): x = galaxy.dap['x'] y = galaxy.dap['y'] spaxel = SpaxelBase(x, y, plateifu='8485-1901', cube=True, maps=True, modelcube=True) dir_list = dir(spaxel) assert 'flux' in dir_list assert 'emline_gflux_ha_6564' in dir_list assert 'binned_flux' in dir_list
def test_files_maps(self, galaxy): x = galaxy.dap['x'] y = galaxy.dap['y'] spaxel = SpaxelBase(x, y, cube=False, maps=galaxy.mapspath, modelcube=False) assert isinstance(spaxel, SpaxelBase) assert not isinstance(spaxel._cube, Cube) assert isinstance(spaxel._maps, Maps) assert not isinstance(spaxel._modelcube, ModelCube)
def test_pickling_all_api(self, temp_scratch, galaxy): drpver, __ = config.lookUpVersions() cube = Cube(plateifu=galaxy.plateifu, mode='remote') maps = Maps(plateifu=galaxy.plateifu, mode='remote') modelcube = ModelCube(plateifu=galaxy.plateifu, mode='remote') spaxel = cube.getSpaxel(1, 3, properties=maps, models=modelcube) assert spaxel._cube.data_origin == 'api' assert spaxel._maps.data_origin == 'api' assert spaxel._modelcube.data_origin == 'api' file = temp_scratch.join('test_spaxel_api.mpf') path_saved = spaxel.save(str(file), overwrite=True) assert file.check() is True assert os.path.exists(path_saved) del spaxel spaxel_restored = SpaxelBase.restore(str(file)) assert spaxel_restored is not None assert isinstance(spaxel_restored, SpaxelBase) assert spaxel_restored._cube is not None assert isinstance(spaxel_restored._cube, Cube) assert spaxel_restored._cube.data_origin == 'api' assert spaxel_restored._cube.data is None assert spaxel_restored._cube.header['VERSDRP3'] == drpver assert spaxel_restored._maps is not None assert isinstance(spaxel_restored._maps, Maps) assert spaxel_restored._maps.data_origin == 'api' assert spaxel_restored._maps.data is None assert spaxel_restored._modelcube is not None assert isinstance(spaxel_restored._modelcube, ModelCube) assert spaxel_restored._modelcube.data_origin == 'api' assert spaxel_restored._modelcube.data is None
def test_files_modelcube(self, galaxy): x = galaxy.dap['x'] y = galaxy.dap['y'] if galaxy.release == 'MPL-4': pytest.skip() else: modelcube_filename = galaxy.modelpath spaxel = SpaxelBase(x, y, cube=False, maps=False, modelcube=modelcube_filename) assert isinstance(spaxel, SpaxelBase) assert not isinstance(spaxel._cube, Cube) assert not isinstance(spaxel._maps, Maps) if galaxy.release != 'MPL-4': assert isinstance(spaxel._modelcube, ModelCube)
def test_SpaxelBase(self, galaxy, cube_maps_modelcube_modes): plateifu = galaxy.plateifu bintype = galaxy.bintype.name template = galaxy.template.name release = galaxy.release x = galaxy.dap['x'] y = galaxy.dap['y'] cube, maps, modelcube = cube_maps_modelcube_modes if cube == 'object': cube = Cube(plateifu=plateifu, release=release) if maps == 'object': maps = Maps(plateifu=plateifu, bintype=bintype, template=template, release=release) if release == 'MPL-4': modelcube = False elif modelcube == 'object': modelcube = ModelCube(plateifu=plateifu, bintype=bintype, template=template, release=release) if cube is False and maps is False and modelcube is False: pytest.skip() spaxel = SpaxelBase(x, y, plateifu=plateifu, cube=cube, maps=maps, modelcube=modelcube, template=template, bintype=bintype) assert isinstance(spaxel, SpaxelBase) if (spaxel.bintype is not None and spaxel.bintype.binned is True and (spaxel._maps or spaxel._modelcube)): assert isinstance(spaxel, Bin) else: assert isinstance(spaxel, Spaxel) if spaxel._cube: assert len(spaxel.cube_quantities) > 0 else: assert len(spaxel.cube_quantities) == 0 if spaxel._maps: assert len(spaxel.maps_quantities) > 0 else: assert len(spaxel.maps_quantities) == 0 if spaxel._modelcube: assert len(spaxel.modelcube_quantities) > 0 else: assert len(spaxel.modelcube_quantities) == 0 assert spaxel.plateifu == galaxy.plateifu assert spaxel.mangaid == galaxy.mangaid assert isinstance(spaxel.getCube(), Cube) assert isinstance(spaxel.getMaps(), Maps) if release != 'MPL-4': assert isinstance(spaxel.getModelCube(), ModelCube)
def test_no_inputs(self): with pytest.raises(MarvinError) as ee: SpaxelBase(0, 0, cube=None, maps=None, modelcube=None) assert 'no inputs defined' in str(ee)