Пример #1
0
    def _get_spaxel_quantities(self, x, y, spaxel=None):
        """Returns a dictionary of spaxel quantities."""

        modelcube_quantities = FuzzyDict({})

        if self.data_origin == 'db':

            session = marvin.marvindb.session
            dapdb = marvin.marvindb.dapdb

        if self.data_origin == 'file' or self.data_origin == 'db':

            _db_row = None

            for dm in self.datamodel:

                data = {'value': None, 'ivar': None, 'mask': None}

                for key in data:

                    if key == 'ivar' and not dm.has_ivar():
                        continue
                    if key == 'mask' and not dm.has_mask():
                        continue

                    if self.data_origin == 'file':

                        extname = dm.fits_extension(None if key ==
                                                    'value' else key)
                        data[key] = self.data[extname].data[:, y, x]

                    elif self.data_origin == 'db':

                        colname = dm.db_column(None if key == 'value' else key)

                        if not _db_row:
                            _db_row = session.query(dapdb.ModelSpaxel).filter(
                                dapdb.ModelSpaxel.modelcube_pk == self.data.pk,
                                dapdb.ModelSpaxel.x == x,
                                dapdb.ModelSpaxel.y == y).use_cache(
                                    self.cache_region).one()

                        data[key] = np.array(getattr(_db_row, colname))

                quantity = Spectrum(data['value'],
                                    ivar=data['ivar'],
                                    mask=data['mask'],
                                    wavelength=self._wavelength,
                                    unit=dm.unit,
                                    pixmask_flag=dm.pixmask_flag)

                if spaxel:
                    quantity._init_bin(spaxel=spaxel,
                                       parent=self,
                                       datamodel=dm)

                modelcube_quantities[dm.full()] = quantity

        if self.data_origin == 'api':

            params = {'release': self._release}
            url = marvin.config.urlmap['api']['getModelCubeQuantitiesSpaxel'][
                'url']

            try:
                response = self._toolInteraction(
                    url.format(name=self.plateifu,
                               x=x,
                               y=y,
                               bintype=self.bintype.name,
                               template=self.template.name,
                               params=params))
            except Exception as ee:
                raise MarvinError(
                    'found a problem when checking if remote modelcube '
                    'exists: {0}'.format(str(ee)))

            data = response.getData()

            for dm in self.datamodel:

                quantity = Spectrum(data[dm.name]['value'],
                                    ivar=data[dm.name]['ivar'],
                                    mask=data[dm.name]['mask'],
                                    wavelength=data['wavelength'],
                                    unit=dm.unit,
                                    pixmask_flag=dm.pixmask_flag)

                if spaxel:
                    quantity._init_bin(spaxel=spaxel,
                                       parent=self,
                                       datamodel=dm)

                modelcube_quantities[dm.full()] = quantity

        return modelcube_quantities
Пример #2
0
    def _get_spaxel_quantities(self, x, y, spaxel=None):
        """Returns a dictionary of spaxel quantities."""

        maps_quantities = FuzzyDict({})

        if self.data_origin == 'file' or self.data_origin == 'db':

            # Stores a dictionary of (table, row)
            _db_rows = {}

            for dm in self.datamodel:

                data = {'value': None, 'ivar': None, 'mask': None}

                for key in data:

                    if key == 'ivar' and not dm.has_ivar():
                        continue
                    if key == 'mask' and not dm.has_mask():
                        continue

                    if self.data_origin == 'file':

                        extname = dm.name + '' if key == 'value' else dm.name + '_' + key

                        if dm.channel:
                            data[key] = self.data[extname].data[dm.channel.idx,
                                                                y, x]
                        else:
                            data[key] = self.data[extname].data[y, x]

                    elif self.data_origin == 'db':

                        mdb = marvin.marvindb

                        table = getattr(mdb.dapdb, dm.model)

                        if table not in _db_rows:
                            _db_rows[table] = mdb.session.query(table).filter(
                                table.file_pk == self.data.pk, table.x == x,
                                table.y == y).use_cache(
                                    self.cache_region).one()

                        colname = dm.db_column(
                            ext=None if key == 'value' else key)
                        data[key] = getattr(_db_rows[table], colname)

                quantity = AnalysisProperty(data['value'],
                                            unit=dm.unit,
                                            ivar=data['ivar'],
                                            mask=data['mask'],
                                            pixmask_flag=dm.pixmask_flag)

                if spaxel:
                    quantity._init_bin(spaxel=spaxel,
                                       parent=self,
                                       datamodel=dm)

                maps_quantities[dm.full()] = quantity

        if self.data_origin == 'api':

            params = {'release': self._release}
            url = marvin.config.urlmap['api']['getMapsQuantitiesSpaxel']['url']

            try:
                response = self._toolInteraction(
                    url.format(name=self.plateifu,
                               x=x,
                               y=y,
                               bintype=self.bintype.name,
                               template=self.template.name,
                               params=params))
            except Exception as ee:
                raise marvin.core.exceptions.MarvinError(
                    'found a problem when checking if remote cube exists: {0}'.
                    format(str(ee)))

            data = response.getData()

            for dm in self.datamodel:

                quantity = AnalysisProperty(data[dm.full()]['value'],
                                            ivar=data[dm.full()]['ivar'],
                                            mask=data[dm.full()]['mask'],
                                            unit=dm.unit,
                                            pixmask_flag=dm.pixmask_flag)

                if spaxel:
                    quantity._init_bin(spaxel=spaxel,
                                       parent=self,
                                       datamodel=dm)

                maps_quantities[dm.full()] = quantity

        return maps_quantities
Пример #3
0
    def _get_spaxel_quantities(self, x, y, spaxel=None):
        """Returns a dictionary of spaxel quantities."""

        cube_quantities = FuzzyDict({})

        if self.data_origin == 'db':

            session = marvin.marvindb.session
            datadb = marvin.marvindb.datadb

        if self.data_origin == 'file' or self.data_origin == 'db':

            # Stores a dictionary of (table, row)
            _db_rows = {}

            for dm in self.datamodel.datacubes + self.datamodel.spectra:

                data = {'value': None, 'ivar': None, 'mask': None, 'std': None}

                for key in data:

                    if key == 'ivar':
                        if dm in self.datamodel.spectra or not dm.has_ivar():
                            continue
                    if key == 'mask':
                        if dm in self.datamodel.spectra or not dm.has_mask():
                            continue
                    if key == 'std':
                        if dm in self.datamodel.datacubes or not dm.has_std():
                            continue

                    if self.data_origin == 'file':

                        extname = dm.fits_extension(None if key ==
                                                    'value' else key)

                        if dm in self.datamodel.datacubes:
                            data[key] = self.data[extname].data[:, y, x]
                        else:
                            data[key] = self.data[extname].data

                    elif self.data_origin == 'db':

                        colname = dm.db_column(None if key == 'value' else key)

                        if dm in self.datamodel.datacubes:

                            if 'datacubes' not in _db_rows:
                                _db_rows['datacubes'] = session.query(
                                    datadb.Spaxel).filter(
                                        datadb.Spaxel.cube == self.data,
                                        datadb.Spaxel.x == x,
                                        datadb.Spaxel.y == y).one()

                            spaxel_data = getattr(_db_rows['datacubes'],
                                                  colname)

                        else:

                            if 'spectra' not in _db_rows:
                                _db_rows['spectra'] = session.query(
                                    datadb.Cube).filter(
                                        datadb.Cube.pk == self.data.pk).one()

                            spaxel_data = getattr(_db_rows['spectra'], colname,
                                                  None)

                        # In case the column was empty in the DB. At some point
                        # this can be removed.
                        if spaxel_data is None:
                            warnings.warn(
                                'cannot find {!r} data for {!r}. '
                                'Maybe the data is not in the DB.'.format(
                                    colname, self.plateifu), MarvinUserWarning)
                            cube_quantities[dm.name] = None
                            continue

                        data[key] = np.array(spaxel_data)

                cube_quantities[dm.name] = Spectrum(
                    data['value'],
                    ivar=data['ivar'],
                    mask=data['mask'],
                    std=data['std'],
                    wavelength=self._wavelength,
                    unit=dm.unit,
                    pixmask_flag=dm.pixmask_flag)

        if self.data_origin == 'api':

            params = {'release': self._release}
            url = marvin.config.urlmap['api']['getCubeQuantitiesSpaxel']['url']

            try:
                response = self._toolInteraction(
                    url.format(name=self.plateifu, x=x, y=y, params=params))
            except Exception as ee:
                raise MarvinError(
                    'found a problem when checking if remote cube '
                    'exists: {0}'.format(str(ee)))

            data = response.getData()

            for dm in self.datamodel.datacubes + self.datamodel.spectra:

                if data[dm.name]['value'] is None:
                    warnings.warn(
                        'cannot find {!r} data for {!r}. '
                        'Maybe the data is not in the DB.'.format(
                            dm.name, self.plateifu), MarvinUserWarning)
                    cube_quantities[dm.name] = None
                    continue

                cube_quantities[dm.name] = Spectrum(
                    data[dm.name]['value'],
                    ivar=data[dm.name]['ivar'],
                    mask=data[dm.name]['mask'],
                    wavelength=data['wavelength'],
                    unit=dm.unit,
                    pixmask_flag=dm.pixmask_flag)

        return cube_quantities