def test_write_observation_list(self): expected = ("# 1584431p15 \n" "# 1584449p15 \n" "# 1584453p15 \n" ) observations = [Observation("1584431", "p", "15"), Observation("1584449", "p", "15"), Observation("1584453", "p", "15")] self.writer._write_observation_list(observations) assert_that(self.read_output(), equal_to(expected))
def test_write_comment(self): obs = Observation("1234567", "p", "00") reading = SourceReading(334.56, 884.22, 335.56, 885.22, 0, 0, 335.56, 885.22, obs) self.undertest.write_comment(reading, "Something fishy.") assert_that(self.read_outputfile(), equal_to("# 1234567p00 334.56 884.22 Something fishy.\n"))
def test_resolve_uris_from_reading(self): observation = Observation("1584431", "p", "15") # 0's for don't cares reading = SourceReading(0, 0, 0, 0, 0, 0, 0, 0, observation) expected_image_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1584431/1584431p.fits" expected_apcor_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1584431/ccd15/1584431p15.apcor" assert_that(reading.get_image_uri(), equal_to(expected_image_uri)) assert_that(reading.get_apcor_uri(), equal_to(expected_apcor_uri))
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 test_flush(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=False) obs = Observation("1234567", "p", "00") reading = SourceReading(334.56, 884.22, 335.56, 885.22, 0, 0, 335.56, 885.22, obs) self.undertest.write_comment(reading, "Something fishy.") assert_that(self.read_outputfile(), equal_to("")) self.undertest.write_mpc_line("12345", "A234567", "*", "M", "N", "2012 10 21.405160", "26.683336700", # 01 46 44.001 "29.220353200", # +29 13 13.27 "123.5", "A", "523") assert_that(self.read_outputfile(), equal_to("")) self.undertest.write_rejection_line("2012 10 21.405160", "26.683336700", # 01 46 44.001 "29.220353200", # +29 13 13.27 ) assert_that(self.read_outputfile(), equal_to("")) expected_comment = "# 1234567p00 334.56 884.22 Something fishy.\n" expected_mpcline = "12345A234567*MN2012 10 21.40516001 46 44.001+29 13 13.27 123.5A 523\n" expected_reject_line = "! 2012 10 21.40516001 46 44.001+29 13 13.27 \n" self.undertest.flush() assert_that(self.read_outputfile(), equal_to(expected_comment + expected_mpcline + expected_reject_line))
def create_source(self, expnums): """ Create a test source with default values but the provided exposure numbers. """ readings = [self.create_reading(Observation(expnum, "p", "22")) for expnum in expnums] return Source(readings)
def test_resolve_fake_apcor_uri(self): observation = Observation("1616682", "s", "24", fk="fk") expected_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1616682/ccd24/fk1616682s24.apcor" assert_that(observation.get_apcor_uri(), equal_to(expected_uri))
def test_resolve_apcor_uri_single_digit_ccd(self): """Just double checking we don't run into trouble with leading zeros""" observation = Observation("1616681", "p", "05") expected_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1616681/ccd05/1616681p05.apcor" assert_that(observation.get_apcor_uri(), equal_to(expected_uri))
def test_resolve_apcor_uri(self): observation = Observation("1616681", "p", "22") expected_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1616681/ccd22/1616681p22.apcor" assert_that(observation.get_apcor_uri(), equal_to(expected_uri))
def test_resolve_image_uri(self): observation = Observation("1584431", "p", "15") expected_uri = "vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1584431/1584431p.fits" assert_that(observation.get_image_uri(), equal_to(expected_uri))