Пример #1
0
 def test_nsa(self, galaxy, mode, db, source):
     if mode == 'local' and source == 'nsa' and marvin.config.db is None:
         with pytest.raises(MarvinError) as cm:
             data = get_nsa_data(galaxy.mangaid, source=source, mode=mode, drpver=galaxy.drpver)
         errmsg = 'get_nsa_data: cannot find a valid DB connection.'
         assert cm.type == MarvinError
         assert errmsg in str(cm.value)
     else:
         data = get_nsa_data(galaxy.mangaid, source=source, mode=mode, drpver=galaxy.drpver)
         if source == 'nsa':
             self._test_nsa(galaxy, data)
         elif source == 'drpall':
             self._test_drpall(galaxy, data)
Пример #2
0
    def _do_file_checks(obj):
        """Performs a series of check when we load from a file."""

        obj.plateifu = obj.header['PLATEIFU']

        # Checks and populates the release.
        file_drpver = obj.header['VERSDRP3']
        file_drpver = 'v1_5_1' if file_drpver == 'v1_5_0' else file_drpver

        file_ver = marvin.config.lookUpRelease(file_drpver)
        assert file_ver is not None, 'cannot find file version.'

        if file_drpver != obj._drpver:
            warnings.warn('mismatch between file release={0} and object release={1}. '
                          'Setting object release to {0}'.format(file_ver, obj._release),
                          MarvinUserWarning)
            obj._release = file_ver

            # Reload NSA data from file version of drpall file
            obj._drpver, obj._dapver = marvin.config.lookUpVersions(release=obj._release)
            obj._drpall = marvin.config._getDrpAllPath(file_drpver)
            obj.mangaid = obj.header['MANGAID']

            nsa_source = 'drpall' if obj.nsa_source == 'auto' else obj.nsa_source

            obj._nsa = None
            obj._nsa = get_nsa_data(obj.mangaid, mode='auto', source=nsa_source,
                                    drpver=obj._drpver, drpall=obj._drpall)

        obj._drpver, obj._dapver = marvin.config.lookUpVersions(release=obj._release)
Пример #3
0
    def nsa(self):
        """Returns the contents of the NSA catalogue for this target."""

        if hasattr(self, 'nsa_source') and self.nsa_source is not None:
            nsa_source = self.nsa_source
        else:
            nsa_source = 'auto'

        if self._nsa is None:

            if nsa_source == 'auto':
                if self.data_origin == 'file':
                    nsa_source = 'drpall'
                else:
                    nsa_source = 'nsa'

            try:
                self._nsa = get_nsa_data(self.mangaid, mode='auto',
                                         source=nsa_source,
                                         drpver=self._drpver,
                                         drpall=self._drpall)
            except (MarvinError, BrainError):
                warnings.warn('cannot load NSA information for mangaid={!r}.'
                              .format(self.mangaid), MarvinUserWarning)
                return None

        return self._nsa
Пример #4
0
    def get_nsa_drpall_data(self, args, mangaid):
        """Returns the NSA data in drpall for a given mangaid.

        .. :quickref: General; Returns for a given mangaid the NSA data from the drpall file

        Note that this always uses the drpver/drpall versions that are default in the server.

        :param mangaid: The name of the cube as mangaid
        :form release: the release of MaNGA
        :resjson int status: status of response. 1 if good, -1 if bad.
        :resjson string error: error message, null if None
        :resjson json inconfig: json of incoming configuration
        :resjson json utahconfig: json of outcoming configuration
        :resjson string traceback: traceback of an error, null if None
        :resjson json data: dictionary of returned data
        :json dict nsa_data: dict of the NSA parameters from the DRPall file
        :resheader Content-Type: application/json
        :statuscode 200: no error
        :statuscode 422: invalid input parameters

        **Example request**:

        .. sourcecode:: http

           GET /marvin2/api/general/nsa/drpall/1-209232/ HTTP/1.1
           Host: api.sdss.org
           Accept: application/json, */*

        **Example response**:

        .. sourcecode:: http

           HTTP/1.1 200 OK
           Content-Type: application/json
           {
              "status": 1,
              "error": null,
              "inconfig": {"release": "MPL-5"},
              "utahconfig": {"release": "MPL-5", "mode": "local"},
              "traceback": null,
              "data": {"camcol": 2,
                       "elpetro_absmag": [-14.3422, -15.7994,-17.0133, ...],
                       "elpetro_amivar": [],
                       ...
                      }
           }

        """

        try:
            nsa_data = get_nsa_data(mangaid, mode='local', source='drpall')
            self.results['data'] = nsa_data
            self.results['status'] = 1
        except Exception as ee:
            self.results['status'] = -1
            self.results[
                'error'] = 'get_nsa_data failed with error: {0}'.format(
                    str(ee))

        return Response(json.dumps(self.results), mimetype='application/json')
Пример #5
0
    def get_nsa_data(self, args, mangaid):
        """Returns the NSA data for a given mangaid from the full catalogue.

        .. :quickref: General; Returns for a given mangaid the NSA data from the full catalog

        :param mangaid: The name of the cube as mangaid
        :form release: the release of MaNGA
        :resjson int status: status of response. 1 if good, -1 if bad.
        :resjson string error: error message, null if None
        :resjson json inconfig: json of incoming configuration
        :resjson json utahconfig: json of outcoming configuration
        :resjson string traceback: traceback of an error, null if None
        :resjson json data: dictionary of returned data
        :json dict nsa_data: dict of all the NSA parameters
        :resheader Content-Type: application/json
        :statuscode 200: no error
        :statuscode 422: invalid input parameters

        **Example request**:

        .. sourcecode:: http

           GET /marvin2/api/general/nsa/full/1-209232/ HTTP/1.1
           Host: api.sdss.org
           Accept: application/json, */*

        **Example response**:

        .. sourcecode:: http

           HTTP/1.1 200 OK
           Content-Type: application/json
           {
              "status": 1,
              "error": null,
              "inconfig": {"release": "MPL-5"},
              "utahconfig": {"release": "MPL-5", "mode": "local"},
              "traceback": null,
              "data": {"aid": 0,
                       "asymmetry":[-0.0217, 0.00517, -0.0187, ...],
                       "bastokes": [[0.7290, 0.9677, ...], [], ...],
                       ...
                      }
           }

        """

        try:
            nsa_data = get_nsa_data(mangaid, mode='local', source='nsa')
            self.results['data'] = nsa_data
            self.results['status'] = 1
        except Exception as ee:
            self.results['status'] = -1
            self.results[
                'error'] = 'get_nsa_data failed with error: {0}'.format(
                    str(ee))

        # these should be jsonify but switching back to json.dumps until f*****g Utah gets with the f*****g picture
        return Response(json.dumps(self.results), mimetype='application/json')
Пример #6
0
    def _load_cube_from_file(self, data=None):
        """Initialises a cube from a file."""

        if data is not None:
            assert isinstance(data,
                              fits.HDUList), 'data is not an HDUList object'
        else:
            try:
                self.data = fits.open(self.filename)
            except (IOError, OSError) as err:
                raise OSError('filename {0} cannot be found: {1}'.format(
                    self.filename, err))

        self.header = self.data[1].header
        self.wcs = WCS(self.header)

        self._wavelength = self.data['WAVE'].data
        self._shape = (self.data['FLUX'].header['NAXIS2'],
                       self.data['FLUX'].header['NAXIS1'])

        self.plateifu = self.header['PLATEIFU']

        # Checks and populates the release.
        file_drpver = self.header['VERSDRP3']
        file_drpver = 'v1_5_1' if file_drpver == 'v1_5_0' else file_drpver

        file_ver = marvin.config.lookUpRelease(file_drpver)
        assert file_ver is not None, 'cannot find file version.'

        if file_ver != self._release:
            warnings.warn(
                'mismatch between file release={0} and object release={1}. '
                'Setting object release to {0}'.format(file_ver,
                                                       self._release),
                MarvinUserWarning)
            self._release = file_ver

            # Reload NSA data from file version of drpall file
            self._drpver, self._dapver = marvin.config.lookUpVersions(
                release=self._release)
            self._drpall = marvin.config._getDrpAllPath(file_drpver)
            self.mangaid = self.header['MANGAID']

            nsa_source = 'drpall' if self.nsa_source == 'auto' else self.nsa_source

            self._nsa = None
            self._nsa = get_nsa_data(self.mangaid,
                                     mode='auto',
                                     source=nsa_source,
                                     drpver=self._drpver,
                                     drpall=self._drpall)

        self._drpver, self._dapver = marvin.config.lookUpVersions(
            release=self._release)
Пример #7
0
 def test_auto_drpall_without_drpall(self):
     marvin.config._drpall = None
     data = get_nsa_data(self.mangaid, source='drpall', mode='auto')
     self._test_drpall(data)
Пример #8
0
 def test_local_nsa(self):
     data = get_nsa_data(self.mangaid, source='nsa', mode='local')
     self._test_nsa(data)
Пример #9
0
 def test_nodrpall(self, galaxy, monkeyconfig):
     data = get_nsa_data(galaxy.mangaid,
                         source='drpall',
                         mode='auto',
                         drpver=galaxy.drpver)
     self._test_drpall(galaxy, data)
Пример #10
0
 def test_nsa_12(self):
     data = get_nsa_data('12-84679', source='nsa', mode='local')
     self.assertAlmostEqual(data['sersic_flux_ivar'][0], 0.127634227275848)
Пример #11
0
 def test_local_drpall(self):
     data = get_nsa_data(self.mangaid, source='drpall', mode='local')
     self._test_drpall(data)
Пример #12
0
 def test_drpall_dotable(self):
     data = get_nsa_data(self.mangaid, source='drpall', mode='local')
     self.assertEqual(data['iauname'], data.iauname)
Пример #13
0
 def test_nsa_old_target_selection(self):
     data = get_nsa_data('1-178482', source='nsa', mode='local')
     self.assertAlmostEqual(data['sersic_flux_ivar'][0], 1.33179831504822)
Пример #14
0
 def test_hybrid_properties_populated(self):
     data = get_nsa_data(self.mangaid, source='nsa', mode='local')
     self.assertIn('elpetro_mag_g', data)
Пример #15
0
 def test_nsa_dotable(self):
     data = get_nsa_data(self.mangaid, source='nsa', mode='local')
     self.assertEqual(data['elpetro_mag_g'], data.elpetro_mag_g)
Пример #16
0
 def test_remote_nsa(self):
     data = get_nsa_data(self.mangaid, source='nsa', mode='remote')
     self._test_nsa(data)
Пример #17
0
 def test_auto_nsa_without_db(self):
     marvin.config.forceDbOff()
     data = get_nsa_data(self.mangaid, source='nsa', mode='auto')
     self._test_nsa(data)
Пример #18
0
 def test_auto_drpall_with_drpall(self):
     data = get_nsa_data(self.mangaid, source='drpall', mode='auto')
     self._test_drpall(data)
Пример #19
0
 def test_auto_nsa_with_db(self):
     data = get_nsa_data(self.mangaid, source='nsa', mode='auto')
     self._test_nsa(data)
Пример #20
0
 def test_remote_drpall(self):
     data = get_nsa_data(self.mangaid, source='drpall', mode='remote')
     self._test_drpall(data)