Exemplo n.º 1
0
    def test_getMap_invalid_channel(self, galaxy):
        maps = Maps(plateifu=galaxy.plateifu)
        with pytest.raises(ValueError) as ee:
            maps.getMap(property_name='emline_gflux',
                        channel='mythical_channel')

        assert 'Your input value is too ambiguous.' in str(ee.value)
Exemplo n.º 2
0
    def test_datamodel(self, galaxy, exporigin):

        maps = Maps(**self._get_maps_kwargs(galaxy, exporigin))

        fin = 'manga-{0}-{1}-MAPS-{2}.fits.gz'.format(galaxy.plate, galaxy.ifu,
                                                      galaxy.bintemp)
        path = join(galaxy.mangaanalysis, galaxy.drpver, galaxy.dapver,
                    galaxy.bintemp, str(galaxy.plate), galaxy.ifu, fin)
        hdus = astropy.io.fits.open(path)

        for hdu in hdus[1:]:

            if ('IVAR' in hdu.name) or ('MASK' in hdu.name) or ('SIGMACORR'
                                                                in hdu.name):
                continue

            name = hdu.name.lower()
            data = hdu.data
            header = hdu.header

            if len(data.shape) < 3:
                val = maps.getMap(name, exact=True).value
                assert val == pytest.approx(data, 0.0001), name

            else:
                for kk, vv in header.items():
                    channel_num = re.match('^[0-9]+$', kk[1:])

                    if (kk[0] == 'C') and (channel_num is not None):
                        channel = '_'.join(re.findall(r"[\w']+", vv)).lower()
                        fullname = '_'.join((name, channel))
                        val = maps.getMap(fullname, exact=True).value
                        assert val == pytest.approx(data[int(kk[1:]) - 1],
                                                    0.0001), name
Exemplo n.º 3
0
    def test_deepcopy(self, galaxy, property_name, channel):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property_name, channel=channel)
        map2 = deepcopy(map1)

        for attr in vars(map1):
            if not attr.startswith('_'):
                value = getattr(map1, attr)
                value2 = getattr(map2, attr)

                if isinstance(value, np.ndarray):
                    assert np.isclose(value, value2).all()

                elif isinstance(value, np.ma.core.MaskedArray):
                    assert (np.isclose(value.data, value2.data).all() and
                            (value.mask == value2.mask).all())

                elif isinstance(value, Maskbit) or isinstance(value[0], Maskbit):

                    if isinstance(value, Maskbit):
                        value = [value]
                        value2 = [value2]

                    for mb, mb2 in zip(value, value2):
                        for it in ['bits', 'description', 'labels', 'mask', 'name']:
                            assert getattr(mb, it) == getattr(mb2, it)

                        assert (mb.schema == mb2.schema).all().all()

                elif isinstance(value, Maps):
                    pass

                else:
                    assert value == value2, attr
Exemplo n.º 4
0
    def test_subtract_maps(self, galaxy, property1, channel1, property2, channel2):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property1, channel=channel1)
        map2 = maps.getMap(property_name=property2, channel=channel2)
        map12 = map1 - map2

        assert map12.value == pytest.approx(map1.value - map2.value)
        assert map12.ivar == pytest.approx(map1._add_ivar(map1.ivar, map2.ivar))
        assert map12.mask == pytest.approx(map1.mask | map2.mask)
Exemplo n.º 5
0
    def test_pow(self, galaxy, property_name, channel, power):
        maps = Maps(plateifu=galaxy.plateifu)
        map_orig = maps.getMap(property_name=property_name, channel=channel)
        map_new = map_orig**power

        sig_orig = np.sqrt(1. / map_orig.ivar)
        sig_new = map_new.value * power * sig_orig * map_orig.value
        ivar_new = 1 / sig_new**2.

        assert pytest.approx(map_new.value, map_orig.value**power)
        assert pytest.approx(map_new.ivar, ivar_new)
        assert (map_new.mask == map_orig.mask).all()
Exemplo n.º 6
0
    def test_multiply_maps(self, galaxy, property1, channel1, property2, channel2):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property1, channel=channel1)
        map2 = maps.getMap(property_name=property2, channel=channel2)
        map12 = map1 * map2

        ivar = map1._mul_ivar(map1.ivar, map2.ivar, map1.value, map2.value, map12.value)
        ivar[np.isnan(ivar)] = 0
        ivar[np.isinf(ivar)] = 0

        assert map12.value == pytest.approx(map1.value * map2.value)
        assert map12.ivar == pytest.approx(ivar)
        assert map12.mask == pytest.approx(map1.mask | map2.mask)
Exemplo n.º 7
0
    def test_multiply_maps(self, galaxy, property1, channel1, property2,
                           channel2):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property1, channel=channel1)
        map2 = maps.getMap(property_name=property2, channel=channel2)
        map12 = map1 * map2

        assert pytest.approx(map12.value, map1.value * map2.value)
        assert pytest.approx(
            map12.ivar,
            map1._mul_ivar(map1.ivar, map2.ivar, map1.value, map2.value,
                           map12.value))
        assert pytest.approx(map12.mask, map1.mask | map2.mask)
Exemplo n.º 8
0
    def test_pow(self, galaxy, property_name, channel, power):
        maps = Maps(plateifu=galaxy.plateifu)
        map_orig = maps.getMap(property_name=property_name, channel=channel)
        map_new = map_orig**power

        sig_orig = np.sqrt(1. / map_orig.ivar)
        sig_new = map_new.value * power * sig_orig * map_orig.value
        ivar_new = 1 / sig_new**2.
        ivar_new[np.isnan(ivar_new)] = 0
        ivar_new[np.isinf(ivar_new)] = 0

        assert map_new.value == pytest.approx(map_orig.value**power, nan_ok=True)
        assert map_new.ivar == pytest.approx(ivar_new)
        assert (map_new.mask == map_orig.mask).all()
Exemplo n.º 9
0
    def test_divide_maps(self, galaxy, property1, channel1, property2,
                         channel2):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property1, channel=channel1)
        map2 = maps.getMap(property_name=property2, channel=channel2)
        map12 = map1 / map2

        with np.errstate(divide='ignore', invalid='ignore'):
            assert pytest.approx(map12.value, map1.value / map2.value)

        assert pytest.approx(
            map12.ivar,
            map1._mul_ivar(map1.ivar, map2.ivar, map1.value, map2.value,
                           map12.value))
        assert pytest.approx(map12.mask, map1.mask | map2.mask)
Exemplo n.º 10
0
    def test_divide_maps(self, galaxy, property1, channel1, property2, channel2):
        maps = Maps(plateifu=galaxy.plateifu)
        map1 = maps.getMap(property_name=property1, channel=channel1)
        map2 = maps.getMap(property_name=property2, channel=channel2)
        map12 = map1 / map2

        ivar = map1._mul_ivar(map1.ivar, map2.ivar, map1.value, map2.value, map12.value)
        ivar[np.isnan(ivar)] = 0
        ivar[np.isinf(ivar)] = 0

        mask = map1.mask | map2.mask
        bad = np.isnan(map12.value) | np.isinf(map12.value)
        mask[bad] = mask[bad] | map12.pixmask.labels_to_value('DONOTUSE')

        with np.errstate(divide='ignore', invalid='ignore'):
            assert map12.value == pytest.approx(map1.value / map2.value, nan_ok=True)

        assert map12.ivar == pytest.approx(ivar)
        assert map12.mask == pytest.approx(mask)
Exemplo n.º 11
0
#maps = Maps(plateifu='7977-12704', mode='local', data_origin='file')
#print(maps)
# get an emission line map

sas_dir = os.environ['SAS_BASE_DIR']
plate = '7977'

maps_file = glob.glob(sas_dir+'/mangawork/manga/spectro/analysis/v2_0_1/SPX-GAU-MILESHC/'+plate+'/*/manga-*MAPS-SPX-GAU*')


filename='ad_marvin_test.pdf'
with PdfPages(filename) as pdf:

    for i in range(0, len(maps_file)):
        maps = Maps(filename=maps_file[i])
        print(maps)
      
        fig = plt.figure()
    
        haflux = maps.getMap('emline_gflux', channel='ha_6564')
        values = haflux.value
        ivar = haflux.ivar
        mask = haflux.mask
        haflux.plot()
        plt.suptitle(maps_file[i])
        
        pdf.savefig()
        plt.close()

os.system("open %s &" % filename)
Exemplo n.º 12
0
def map_(request, galaxy, data_origin):
    maps = Maps(**_get_maps_kwargs(galaxy, data_origin))
    map_ = maps.getMap(property_name=request.param[0],
                       channel=request.param[1])
    map_.data_origin = data_origin
    return map_