Exemple #1
0
 def on_ssos_query(self):
     try:
         new_workunit = self.model.get_current_workunit().query_ssos()
         self.model.add_workunit(new_workunit)
     except AssertionError as e:
         logger.critical(str(e))
         pass
     self.model.next_item()
Exemple #2
0
 def on_ssos_query(self):
     try:
         new_workunit = self.model.get_current_workunit().query_ssos()
         self.model.add_workunit(new_workunit)
     except AssertionError as e:
         logger.critical(str(e))
         pass
     self.model.next_item()
Exemple #3
0
    def build_source_reading(self, expnum, ccd, X, Y):
        """
        Given the location of a source in the image, create a source reading.

        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        slice_rows=config.read("CUTOUTS.SINGLETS.SLICE_ROWS")
        slice_cols=config.read("CUTOUTS.SINGLETS.SLICE_COLS")

        if X == -9999 or Y == -9999  :
            logger.warning("Skipping {} as x/y not resolved.".format(image_uri))
            return None

        if not (-slice_cols/2. < X < 2048+slice_cols/2. and -slice_rows/2. < Y < 4600+slice_rows/2.0):
            logger.warning("Central location ({},{}) off image cutout.".format(X,Y))
            return None

        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical('Image exists but processing incomplete. Mopheader missing. {}'.format(image_uri))
            return None


        mopheader = get_mopheader(expnum, ccd)


        # Build astrom.Observation
        observation = astrom.Observation(expnum=str(expnum),
                                         ftype='p',
                                         ccdnum=str(ccd),
                                         fk="")

        observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2)

        observation.header = mopheader

        return observation
Exemple #4
0
    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))
Exemple #5
0
    def build_workunit(self, input_fullpath):
        try:
            parsed_data = self.parser.parse(input_fullpath)
        except AssertionError as e:
            logger.critical(str(e))
            events.send(events.NO_AVAILABLE_WORK)
        logger.debug("Parsed %s (%d sources)" %
                     (input_fullpath, parsed_data.get_source_count()))

        _, input_filename = os.path.split(input_fullpath)

        return self._do_build_workunit(input_filename, parsed_data,
                                       self.progress_manager,
                                       self.output_context, self.dry_run)
Exemple #6
0
    def from_source_reference(expnum, ccd, X, Y):
        """
        Given the location of a source in the image, create a source reading.
        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        if X == -9999 or Y == -9999 :
            logger.warning("Skipping {} as x/y not resolved.".format(image_uri))
            return None


        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical('Image exists but processing incomplete. Mopheader missing. {}'.format(image_uri))
            return None


        mopheader = storage.get_mopheader(expnum, ccd)

        # Build astrom.Observation
        observation = Observation(expnum=str(expnum),
                                         ftype='p',
                                         ccdnum=str(ccd),
                                         fk="")

        observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2)

        observation.header = mopheader

        return observation
Exemple #7
0
    def from_source_reference(expnum, ccd, x, y):
        """
        Given the location of a source in the image, create a source reading.
        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        if x == -9999 or y == -9999:
            logger.warning(
                "Skipping {} as x/y not resolved.".format(image_uri))
            return None

        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical(
                'Image exists but processing incomplete. Mopheader missing. {}'
                .format(image_uri))
            return None

        # Build astrom.Observation
        observation = Observation(expnum=str(expnum),
                                  ftype='p',
                                  ccdnum=str(ccd),
                                  fk="")
        observation.rawname = os.path.splitext(
            os.path.basename(image_uri))[0] + str(ccd).zfill(2)

        return observation
Exemple #8
0
def create_application(taskname, working_directory, output_directory,
                       dry_run=False, debug=False):
    logger.info("Starting %s task." % taskname)

    if taskname == tasks.CANDS_TASK:
        ProcessCandidatesApplication(working_directory, output_directory,
                                     dry_run=dry_run, debug=debug)
    elif taskname == tasks.REALS_TASK:
        ProcessRealsApplication(working_directory, output_directory,
                                dry_run=dry_run, debug=debug)
    elif taskname == tasks.TRACK_TASK:
        ProcessTracksApplication(working_directory, output_directory,
                                 dry_run=dry_run, debug=debug)
    else:
        error_message = "Unknown task: %s" % taskname
        logger.critical(error_message)
        raise ValueError(error_message)
Exemple #9
0
    def build_workunit(self, input_fullpath):
        try:
            parsed_data = self.parser.parse(input_fullpath)
        except AssertionError as e:
            logger.critical(str(e))
            events.send(events.NO_AVAILABLE_WORK)
        logger.debug("Parsed %s (%d sources)" %
                     (input_fullpath, parsed_data.get_source_count()))

        _, input_filename = os.path.split(input_fullpath)

        return self._do_build_workunit(
            input_filename,
            parsed_data,
            self.progress_manager,
            self.output_context,
            self.dry_run)
Exemple #10
0
def create_application(task_name,
                       working_directory,
                       output_directory,
                       dry_run=False,
                       debug=False,
                       name_filter=None,
                       user_id=None,
                       skip_previous=False):
    logger.info("Starting %s task." % task_name)

    if task_name == tasks.CANDS_TASK:
        ProcessCandidatesApplication(working_directory,
                                     output_directory,
                                     dry_run=dry_run,
                                     debug=debug,
                                     name_filter=name_filter,
                                     user_id=user_id)
    elif task_name == tasks.REALS_TASK:
        ProcessRealsApplication(working_directory,
                                output_directory,
                                dry_run=dry_run,
                                debug=debug,
                                name_filter=name_filter,
                                user_id=user_id)
    elif task_name == tasks.TRACK_TASK:
        ProcessTracksApplication(working_directory,
                                 output_directory,
                                 dry_run=dry_run,
                                 debug=debug,
                                 name_filter=name_filter,
                                 skip_previous=skip_previous,
                                 user_id=user_id)
    else:
        error_message = "Unknown task: %s" % task_name
        logger.critical(error_message)
        raise ValueError(error_message)
Exemple #11
0
    def on_accept(self):
        """
        Initiates acceptance procedure, gathering required data.
        """
        if self.model.is_current_source_named():
            provisional_name = self.model.get_current_source_name()
        else:
            provisional_name = self._generate_provisional_name()

        band = self.model.get_current_band()
        default_comment = ""
        phot_failure = False

        source_cutout = self.model.get_current_cutout()

        display = ds9.ds9(target='validate')
        result = display.get('imexam key coordinate')
        values = result.split()
        logger.debug("IMEXAM returned {}".format(values))
        cen_coords = (float(values[1]), float(values[2]))
        key = values[0]
        source_cutout.update_pixel_location(cen_coords)
        #source_cutout.pixel_x = float(values[1])
        #source_cutout.pixel_y = float(values[2])
        logger.debug("X, Y => {} , {}".format(source_cutout.pixel_x,
                                              source_cutout.pixel_y))
        pixel_x = source_cutout.pixel_x
        pixel_y = source_cutout.pixel_y

        self.view.mark_apertures(self.model.get_current_cutout())

        try:
            cen_x, cen_y, obs_mag, obs_mag_err = self.model.get_current_source_observed_magnitude(
            )
        except Exception as error:
            logger.critical(str(error))
            phot_failure = True
            obs_mag = ""
            cen_x = pixel_x
            cen_y = pixel_y
            obs_mag_err = -1
            band = ""
            default_comment = str(error)

        if math.sqrt((cen_x - pixel_x)**2 + (cen_y - pixel_y)**2) > 1.5:
            # check if the user wants to use the 'hand' coordinates or these new ones.
            self.view.draw_error_ellipse(cen_x, cen_y, 10, 10, 0, color='r')
            self.view.show_offset_source_dialog((pixel_x, pixel_y),
                                                (cen_x, cen_y))
        else:
            source_cutout.update_pixel_location((cen_x, cen_y))
            self.model.get_current_cutout()._adjusted = False

        if self.model.is_current_source_adjusted():
            note1_default = config.read("MPC.NOTE1_HAND_ADJUSTED")
        elif key in mpc.MPCNOTES['Note1'].keys():
            note1_default = key
        else:
            note1_default = ""

        self.view.show_accept_source_dialog(
            provisional_name,
            self.model.get_current_observation_date(),
            self.model.get_current_ra(),
            self.model.get_current_dec(),
            obs_mag,
            obs_mag_err,
            band,
            note1_choices=config.read("MPC.NOTE1OPTIONS"),
            note2_choices=config.read("MPC.NOTE2OPTIONS"),
            note1_default=note1_default,
            note2_default=config.read("MPC.NOTE2DEFAULT"),
            default_observatory_code=config.read(
                "MPC.DEFAULT_OBSERVATORY_CODE"),
            default_comment=default_comment,
            phot_failure=phot_failure,
            pixel_x=source_cutout.pixel_x,
            pixel_y=source_cutout.pixel_y)