Beispiel #1
0
    def test_save_and_restore(self, temp_scratch, map_):

        fout = temp_scratch.join('test_map.mpf')
        map_.save(str(fout))
        assert fout.check() is True

        map_restored = Map.restore(str(fout), delete=True)
        assert tuple(map_.shape) == tuple(map_restored.shape)
Beispiel #2
0
    def get_binid(self, model=None):
        """Returns the binid map associated with a model.

        Parameters
        ----------
        model : `datamodel.Model` or None
            The model for which the associated binid map will be returned.
            If ``binid=None``, the default binid is returned.

        Returns
        -------
        binid : `Map`
            A `Map` with the binid associated with ``model`` or the default
            binid.

        """

        assert model is None or isinstance(model, Model), 'invalid model type.'

        if model is not None:
            binid_prop = model.binid
        else:
            binid_prop = self.datamodel.parent.default_binid

        # Before MPL-6, the modelcube does not include the binid extension,
        # so we need to get the binid map from the associated MAPS.
        if (distutils.version.StrictVersion(self._dapver) <
                distutils.version.StrictVersion('2.1')):
            return self.getMaps().get_binid()

        if self.data_origin == 'file':

            if binid_prop.channel is None:
                binid_map_data = self.data[binid_prop.name].data[:, :]
            else:
                binid_map_data = self.data[binid_prop.name].data[
                    binid_prop.channel.idx, :, :]

        elif self.data_origin == 'db':

            mdb = marvin.marvindb

            table = mdb.dapdb.ModelSpaxel
            column = getattr(table, binid_prop.db_column())

            binid_list = mdb.session.query(column).filter(
                table.modelcube_pk == self.data.pk).order_by(table.x,
                                                             table.y).all()

            nx = ny = int(np.sqrt(len(binid_list)))
            binid_array = np.array(binid_list)

            binid_map_data = binid_array.transpose().reshape(
                (ny, nx)).transpose(1, 0)

        elif self.data_origin == 'api':

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

            extension = model.fits_extension().lower(
            ) if model is not None else 'flux'

            try:
                response = self._toolInteraction(url.format(
                    name=self.plateifu,
                    modelcube_extension=extension,
                    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)))

            if response.results['error'] is not None:
                raise MarvinError(
                    'found a problem while getting the binid from API: {}'.
                    format(str(response.results['error'])))

            binid_map_data = np.array(response.getData()['binid'])

        binid_map = Map(binid_map_data, unit=binid_prop.unit)
        binid_map._datamodel = binid_prop

        return binid_map
Beispiel #3
0
 def test_unit_propagation_mismatch(self, unit1, unit2, op):
     with pytest.warns(UserWarning):
         assert Map._unit_propagation(unit1, unit2, op) is None
Beispiel #4
0
 def test_unit_propagation(self, unit1, unit2, op, expected):
     assert Map._unit_propagation(unit1, unit2, op) == expected
Beispiel #5
0
 def test_pow_ivar_none(self, power):
     assert Map._pow_ivar(None, np.arange(4),
                          power) == pytest.approx(np.zeros(4))
Beispiel #6
0
 def test_pow_ivar(self, ivar, value, power, expected):
     ivar = Map._pow_ivar(ivar, value, power)
     ivar[np.isnan(ivar)] = 0
     ivar[np.isinf(ivar)] = 0
     assert ivar == pytest.approx(expected)
Beispiel #7
0
 def test_mul_ivar(self, ivar1, ivar2, value1, value2, value_prod12,
                   expected):
     ivar = Map._mul_ivar(ivar1, ivar2, value1, value2, value_prod12)
     ivar[np.isnan(ivar)] = 0
     ivar[np.isinf(ivar)] = 0
     assert ivar == pytest.approx(expected)
Beispiel #8
0
 def test_add_ivar(self, ivar1, ivar2, expected):
     assert Map._add_ivar(ivar1, ivar2) == pytest.approx(expected)
Beispiel #9
0
 def test_log10_ivar(self, ivar, value, expected):
     actual = Map._log10_ivar(ivar, value)
     assert actual == pytest.approx(expected)
Beispiel #10
0
 def test_pow_ivar(self, ivar, value, power, expected):
     assert pytest.approx(Map._pow_ivar(ivar, value, power), expected)
Beispiel #11
0
 def test_mul_ivar(self, ivar1, ivar2, value1, value2, value_prod12,
                   expected):
     assert pytest.approx(
         Map._mul_ivar(ivar1, ivar2, value1, value2, value_prod12),
         expected)