def test_cone_search(self): mpc_line=" O13AE3Y* C2013 04 04.42583 14 09 16.989-11 14 50.60 23.18r 568 1615909p27 O13AE3Y Y 1715.1 2159.5 23.18 0.10 UUUU %" observation = mpc.Observation.from_string(mpc_line) result_table = storage.cone_search(observation.coordinate.lonangle.degrees, observation.coordinate.latangle.degrees, ) self.assertIsInstance(result_table, table.Table) self.assertEquals(result_table['dataset_name'][0],1607614)
def test_cone_search(self): mpc_line=" O13AE3Y* C2013 04 04.42583 14 09 16.989-11 14 50.60 23.18r 568 1615909p27 O13AE3Y Y 1715.1 2159.5 23.18 0.10 UUUU %" observation = mpc.Observation.from_string(mpc_line) result_table = storage.cone_search(observation.coordinate.lonangle.degrees, observation.coordinate.latangle.degrees, ) self.assertIsInstance(result_table, table.Table) self.assertEquals(result_table['collectionID'][0],1607614)
def retrieve_comparison_image(self, downloader): """ Search the DB for a comparison image for this cutout. """ # selecting comparator when on a comparator should load a new one. ref_wcs = wcs.WCS(self.fits_header) try: ref_x = self.fits_header['NAXIS1'] / 2.0 ref_y = self.fits_header['NAXIS2'] / 2.0 (ref_ra, ref_dec) = ref_wcs.xy2sky(ref_x, ref_y) except Exception as e: logger.info(str(e)) logger.info(str(self.fits_header)) return None dra = self.fits_header['CD1_1'] * self.fits_header['NAXIS1'] / 2.0 ddec = self.fits_header['CD2_2'] * self.fits_header['NAXIS2'] / 2.0 radius = max(dra, ddec) logger.info("BOX({} {} {} {})".format(ref_ra, ref_dec, dra, ddec)) query_result = storage.cone_search(ref_ra, ref_dec, dra, ddec) # returns an astropy.table.table.Table comparison = None if len(query_result['collectionID']) > 0: # are there any comparison images even available on that sky? for collectionID in query_result['collectionID']: if collectionID not in self._bad_comparison_images: comparison = collectionID self._bad_comparison_images.append(comparison) break if comparison is None: logger.critical(str(self.fits_header)) self._comparison_image = None return else: query_result.pprint() logger.info("No comparison images available for this piece of sky.") print "No comparison images available for this piece of sky." self._comparison_image = None return base_url = "https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/vospace/nodes/OSSOS/dbimages/{}/{}p.fits".format( comparison, comparison) cutout = 'CIRCLE ICRS {} {} {}'.format(ref_ra, ref_dec, radius) url = base_url + "?" + urllib.urlencode({'view': 'cutout', 'cutout': cutout}) hdu_list = downloader.download_hdulist(uri=None, URL=url) comp_wcs = wcs.WCS(hdu_list[-1].header) (x, y) = comp_wcs.sky2xy(ref_ra, ref_dec) obs = Observation(str(comparison), 'p', ccdnum=str(hdu_list[-1].header.get('EXTVER', 0))) reading = SourceReading(x, y, ref_x, ref_y, ref_ra, ref_dec, ref_x, ref_y, obs, is_inverted=False) self._comparison_image = SourceCutout(reading, hdu_list, CoordinateConverter(0, 0))
def retrieve_comparison_image(self, downloader): """ Search the DB for a comparison image for this cutout. """ # selecting comparitor when on a comparitor should load a new one. ref_wcs = wcs.WCS(self.fits_header) ref_x = self.fits_header['NAXIS1']/2.0 ref_y = self.fits_header['NAXIS2']/2.0 (ref_ra, ref_dec) = ref_wcs.xy2sky(ref_x,ref_y) dra = self.fits_header['CD1_1']*self.fits_header['NAXIS1']/2.0 ddec= self.fits_header['CD2_2']*self.fits_header['NAXIS2']/2.0 radius=max(dra,ddec) logger.debug("BOX({} {} {} {})".format(ref_ra, ref_dec,dra, ddec)) query_result = storage.cone_search(ref_ra, ref_dec, dra, ddec) comparison = None for collectionID in query_result['collectionID']: if collectionID not in self._bad_comparison_images: comparison = collectionID self._bad_comparison_images.append(comparison) break if comparison is None: self._comparison_image = None return base_url = "https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/vospace/nodes/OSSOS/dbimages/{}/{}p.fits".format(comparison, comparison) cutout = 'CIRCLE ICRS {} {} {}'.format(ref_ra,ref_dec,radius) url = base_url+"?"+urllib.urlencode({'view': 'cutout', 'cutout': cutout}) hdu_list = downloader.download_hdulist(uri=None, URL=url) comp_wcs = wcs.WCS(hdu_list[-1].header) (x, y) = comp_wcs.sky2xy(ref_ra, ref_dec) obs = Observation(str(comparison),'p',ccdnum=str(hdu_list[-1].header.get('EXTVER',0))) reading = SourceReading(x,y,ref_x, ref_y, ref_ra, ref_dec,ref_x,ref_y, obs) self._comparison_image = SourceCutout(reading ,hdu_list, CoordinateConverter(0,0))
def ephem_search(mpc_filename, search_date="2014 07 24.0"): """ builds a TSV file in the format of SSOIS by querying for possible observations in CADC/CAOM2. This is a fall back program, should only be useful when SSOIS is behind. """ columns = ('Image', 'Ext', 'X', 'Y', 'MJD', 'Filter', 'Exptime', 'Object_RA', 'Object_Dec', 'Image_target', 'Telescope/Instrument', 'MetaData', 'Datalink') ephem_table = Table(names=columns, dtypes=('S10', 'i4', 'f8', 'f8', 'f8', 'S10', 'f8', 'f8', 'f8', 'S20', 'S20', 'S20', 'S50')) ephem_table.pprint() o = orbfit.Orbfit(mpc.MPCReader(mpc_filename).mpc_observations) o.predict(search_date) fields = storage.cone_search(o.coordinate.ra.degrees, o.coordinate.dec.degrees, dra=0.3, ddec=0.3, calibration_level=1) mjdates = numpy.unique(fields['mjdate']) collectionIDs = [] for mjdate in mjdates: jd = 2400000.5 + mjdate o.predict(jd) for field in storage.cone_search(o.coordinate.ra.degrees, o.coordinate.dec.degrees, dra=30. / 3600.0, ddec=30. / 3600.0, mjdate=mjdate, calibration_level=1): collectionIDs.append(field['collectionID']) expnums = numpy.unique(numpy.array(collectionIDs)) for expnum in expnums: header = storage.get_astheader(expnum, 22) o.predict(header['MJDATE'] + 2400000.5) print(o.time.iso, o.coordinate.ra.degrees, o.coordinate.dec.degrees) for ccd in range(36): header = storage.get_astheader(expnum, ccd) w = wcs.WCS(header) (x, y) = w.sky2xy(o.coordinate.ra.degrees, o.coordinate.dec.degrees) print(ccd, x, y) if 0 < x < header['NAXIS1'] and 0 < y < header['NAXIS2']: ephem_table.add_row([ expnum, ccd + 1, x, y, header['MJDATE'], header['FILTER'], header['EXPTIME'], o.coordinate.ra.degrees, o.coordinate.dec.degrees, header['OBJECT'], 'CFHT/MegaCam', None, "https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/data/pub/CFHT/{}p[{}]" .format(expnum, ccd) ]) break ephem_table.pprint() ephem_table.write('backdoor.tsv', format='ascii', delimiter='\t')
def caom2(mpc_filename, search_date="2014 07 24.0"): """ builds a TSV file in the format of SSOIS by querying for possilbe observations in CADC/CAOM2. This is a fall back program, should only be useful when SSOIS is behind. """ columns = ('Image', 'Ext', 'X', 'Y', 'MJD', 'Filter', 'Exptime', 'Object_RA', 'Object_Dec', 'Image_target', 'Telescope/Instrument', 'MetaData', 'Datalink') ephem_table = Table(names=columns, dtypes=('S10', 'i4', 'f8', 'f8', 'f8', 'S10', 'f8', 'f8', 'f8', 'S20', 'S20', 'S20', 'S50')) ephem_table.pprint() o = orbfit.Orbfit(mpc.MPCReader(mpc_filename).mpc_observations) o.predict(search_date) fields = storage.cone_search(o.coordinate.ra.degrees, o.coordinate.dec.degrees, dra=0.3, ddec=0.3, calibration_level=1) mjdates = numpy.unique(fields['mjdate']) collectionIDs = [] for mjdate in mjdates: jd = 2400000.5 + mjdate o.predict(jd) for field in storage.cone_search(o.coordinate.ra.degrees, o.coordinate.dec.degrees, dra=30./3600.0, ddec=30./3600.0, mjdate=mjdate, calibration_level=1): collectionIDs.append(field['collectionID']) expnums = numpy.unique(numpy.array(collectionIDs)) for expnum in expnums: header = storage.get_astheader(expnum, 22) o.predict(header['MJDATE']+2400000.5) print o.time.iso, o.coordinate.ra.degrees, o.coordinate.dec.degrees for ccd in range(36): header = storage.get_astheader(expnum, ccd) w = wcs.WCS(header) (x, y) = w.sky2xy(o.coordinate.ra.degrees, o.coordinate.dec.degrees) print ccd, x, y if 0 < x < header['NAXIS1'] and 0 < y < header['NAXIS2']: ephem_table.add_row([expnum, ccd+1, x, y, header['MJDATE'], header['FILTER'], header['EXPTIME'], o.coordinate.ra.degrees, o.coordinate.dec.degrees, header['OBJECT'], 'CFHT/MegaCam', None, "http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/data/pub/CFHT/{}p[{}]".format(expnum, ccd)]) break ephem_table.pprint() ephem_table.write('backdoor.tsv', format='ascii', delimiter='\t')