Example #1
0
File: ssos.py Project: R136a1-/MOP
    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
Example #2
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
Example #3
0
def recompute_mag(mpc_obs):
    """
    Get the mag of the object given the mpc.Observation
    """
    # TODO this really shouldn't need to build a 'reading' to get the cutout...
    parts = re.search('(?P<expnum>\d{7})(?P<type>\S)(?P<ccd>\d\d)', mpc_obs.comment.frame)
    if parts is None:
        return None
    expnum = parts.group('expnum')
    ccd = parts.group('ccd')
    ftype = parts.group('type')

    observation =  astrom.Observation(expnum,ftype,ccd)
    observation.header = storage.get_mopheader(int(expnum),int(ccd))
    reading = astrom.SourceReading(float(mpc_obs.comment.X),
                                   float(mpc_obs.comment.Y),
                                   float(mpc_obs.comment.X),
                                   float(mpc_obs.comment.Y),
                                   mpc_obs.coordinate.ra.degrees,
                                   mpc_obs.coordinate.dec.degrees,
                                   float(mpc_obs.comment.X),
                                   float(mpc_obs.comment.Y),
                                   observation,
                                   ssos=True,
                                   from_input_file=True,null_observation=False,discovery=mpc_obs.discovery)


    image_slice_downloader = ImageCutoutDownloader(slice_rows=100, slice_cols=100)
    cutout = image_slice_downloader.download_cutout(reading, needs_apcor=True)
    try:
        (x, y, mag, merr) = cutout.get_observed_magnitude()
        mpc_obs.mag = mag
        mpc_obs.mag_err = merr
    except:
        mpc_obs.mag = None
        mpc_obs.mag_err = None

    return
Example #4
0
 def header(self):
     if self._header is None:
         self._header = storage.get_mopheader(self.expnum, self.ccdnum)
     return self._header
Example #5
0
def recompute_mag(mpc_in):
    """
    Get the mag of the object given the mpc.Observation
    """
    # TODO this really shouldn't need to build a 'reading' to get the cutout...
    from ossos.downloads.cutouts import ImageCutoutDownloader

    mpc_obs = deepcopy(mpc_in)
    assert isinstance(mpc_obs, mpc.Observation)
    if mpc_obs.null_observation:
        return mpc_obs
    parts = re.search('(?P<expnum>\d{7})(?P<type>\S)(?P<ccd>\d\d)', mpc_obs.comment.frame)
    if parts is None:
        return mpc_obs
    expnum = parts.group('expnum')
    ccd = parts.group('ccd')
    file_type = parts.group('type')

    observation = astrom.Observation(expnum, file_type, ccd)
    assert isinstance(observation, astrom.Observation)
    ast_header = storage.get_astheader(int(expnum), int(ccd))

    # The ZP for the current astrometric lines is the pipeline one.  The new ZP is in the astheader file.
    new_zp = ast_header.get('PHOTZP')

    # The ZP in the image header is likely the one used for the original photometry.
    old_zp = storage.get_zeropoint(int(expnum), int(ccd))
    reading = astrom.SourceReading(float(mpc_obs.comment.x), float(mpc_obs.comment.y), float(mpc_obs.comment.x),
                                   float(mpc_obs.comment.y), mpc_obs.coordinate.ra.degrees,
                                   mpc_obs.coordinate.dec.degrees, float(mpc_obs.comment.x),
                                   float(mpc_obs.comment.y),
                                   observation, ssos=True, from_input_file=True, null_observation=False,
                                   discovery=mpc_obs.discovery)
    # reading.is_inverted = reading.compute_inverted()
    reading._header = storage.get_mopheader(expnum, ccd)
    reading._header['MAXCOUNT'] = 30000.0
    image_slice_downloader = ImageCutoutDownloader(slice_rows=100, slice_cols=100)
    cutout = image_slice_downloader.download_cutout(reading, needs_apcor=True)
    cutout.zmag = new_zp

    if math.fabs(new_zp - old_zp) > 0.3:
        logging.warning("Large change in zeropoint detected: {}  -> {}".format(old_zp, new_zp))

    try:
        (x, y, mag, merr) = cutout.get_observed_magnitude(zmag=new_zp)
        (x, y) = cutout.get_observed_coordinates((x, y))
    except:
        logging.warn("Failed to do photometry.")
        return mpc_obs
    if mpc_obs.comment.mag is not None and math.fabs(mpc_obs.comment.mag - mag) > 3.5 * mpc_obs.comment.mag_uncertainty:
        logging.warn("recomputed magnitude shift large: {} --> {}".format(mpc_obs.mag, mag))
    if math.sqrt((x - mpc_obs.comment.x) ** 2 + (y - mpc_obs.comment.y) ** 2) > 1.0:
        logging.warn("Centroid shifted ({},{}) -> ({},{})".format(mpc_obs.comment.x,
                                                                      mpc_obs.comment.y,
                                                                      x,
                                                                      y))
    # Don't use the new X/Y for Hand measured entries.
    if str(mpc_obs.note1) != "H":
        mpc_obs.comment.x = x
        mpc_obs.comment.y = y

    mpc_obs.comment.mag = mag
    mpc_obs.comment.mag_uncertainty = merr
    if mpc_obs.mag is not None:
        mpc_obs.mag = mag

    return mpc_obs