Exemple #1
0
    def get_field_shifts(self, fieldid):
        """Returns the calibration shifts for a given field.

        Parameters
        ----------
        fieldid : str
            Field identifier, e.g. "0001_aug2003"

        Returns
        -------
        shifts : dictionary {'r':shift_r, 'i': shift_i, 'ha': shift_ha}
            Shifts to add to the magnitudes to calibrate a field.
        """
        idx_field = np.argwhere(IPHASQC.field('id') == fieldid)[0]

        shifts = {}
        for band in constants.BANDS:
            cond_run = (self.calib[band]['run']
                        == IPHASQC.field('run_' + band)[idx_field])
            if cond_run.sum() > 0:
                shifts[band] = self.calib[band]['shift'][cond_run][0]
            else:
                log.warning('No shift for %s' % fieldid)
                shifts[band] = 0.0

        log.debug("Shifts for {0}: {1}".format(fieldid, shifts))
        return shifts            
Exemple #2
0
def bandmerge_one(fieldid):
    """Band-merge a single field """
    with log.log_to_file(os.path.join(constants.LOGDIR, 'bandmerging.log')):
        engine = socket.gethostname()+'/'+str(os.getpid())
        log.info('Starting {0} on {1}'.format(fieldid, engine))

        # Which index does the field have in the QC table?
        idx = np.where(IPHASQC.field('id') == fieldid)[0]
        if len(idx) < 1:
            raise IPHASException('{}: error identifying runs'.format(fieldid))

        # Carry out the band-merging
        bm = BandMerge(fieldid,
                       IPHASQC.field('qflag')[idx[0]],
                       IPHASQC.field('run_ha')[idx[0]],
                       IPHASQC.field('run_r')[idx[0]],
                       IPHASQC.field('run_i')[idx[0]])
        status = bm.run()

        log.info('Finished {0} on {1} (returned {2})'.format(fieldid,
                                                             engine,
                                                             status))
        return status
Exemple #3
0
def bandmerge(clusterview):
    """Band-merge all fields."""
    util.setup_dir(MYDESTINATION)

    # Spread the work across the cluster
    field_ids = IPHASQC.field('id')
    results = clusterview.imap(bandmerge_one, field_ids)

    # Print a friendly message once in a while
    i = 0
    for status in results:
        i += 1
        if (i % 1000) == 0:
            log.info('Completed field {0}/{1}'.format(i, len(field_ids)))
    log.info('Bandmerging finished')
Exemple #4
0
    def select_anchors(self):
        """Returns a boolean array indicating which runs are suitable anchors."""
        median_pair_offset = -0.008 
        IS_STABLE = ( (IPHASQC.field('med_dr') < (median_pair_offset+0.03)) &
                      (IPHASQC.field('med_dr') > (median_pair_offset-0.03)) &
                      (IPHASQC.field('med_di') < (median_pair_offset+0.03)) &
                      (IPHASQC.field('med_di') > (median_pair_offset-0.03)) &
                      (IPHASQC.field('med_dh') < (median_pair_offset+0.03)) &
                      (IPHASQC.field('med_dh') > (median_pair_offset-0.03))
                    )

        if self.band == 'ha':
            # Because the H-alpha calibration is tied to the r-band,
            # we require fields to be "stable" to be an anchor in H-alpha.
            # "Stable" is defined as the fieldpair not showing great shifts.

            # Eyeballing has revealed that the H-alpha shifts should be 
            # equal to the r-band shift for these fields:
            KEEP_FIXED = ['0151_nov2005', '0151o_nov2005',
                          '0207_jul2012', '0207o_jul2012',
                          '0296_nov2006b',
                          '0818_nov2003', '0818o_nov2003',
                          '0922o_oct2004',
                          '0943_sep2010', '0943o_sep2010',
                          '0978_sep2012', '0978o_sep2010',
                          '0983_oct2005b', '0983o_oct2005b',
                          '0985_oct2005b', '0985o_oct2005b',
                          '1000_dec2003', '1000o_dec2003',
                          '1037_dec2003', '1037o_dec2003',
                          '1054_dec2003', '1054o_dec2003',
                          '1065_oct2004', '1065o_oct2004',
                          '1069_nov2006c', '1069o_nov2006c',
                          '1071_nov2012', '1071o_nov2012',
                          '1076_oct2012', '1076o_oct2012',
                          '1084_oct2004', '1084o_oct2004',
                          '1116_dec2004', 
                          '1232_nov2012', '1232o_nov2012',
                          '1262_nov2003b', '1262o_nov2003b',
                          '1285_nov2006c',
                          '1370_oct2004', '1370o_oct2004',
                          '1371_oct2004', '1371o_oct2004',
                          '1374_oct2004', '1374o_oct2004',
                          '1375_oct2004', '1375o_oct2004',
                          '1381_oct2010', '1381o_oct2010',
                          '1383_oct2010', '1383o_oct2010',
                          '1384_oct2004', '1384o_oct2004',
                          '1387_oct2004', '1387o_oct2004',
                          '1388_oct2004', '1388o_oct2004',
                          '1397_nov2012', '1397o_nov2012',
                          '1423_nov2006b', '1423o_nov2006b',
                          '1432_nov2012', '1432o_nov2012',
                          '1436_nov2006d', '1436o_nov2006d',
                          '1685_oct2004', '1685o_oct2004',
                          '1819_nov2012', '1819o_nov2012',
                          '2021_nov2004', '2021o_nov2004',
                          '2361_oct2006', '2361o_oct2006',
                          '2529_nov2003', '2529o_nov2003',
                          '2694_dec2005', '2694o_dec2005',
                          '2767_dec2003', '2767o_dec2003',
                          '2845_nov2006d', '2845o_nov2006d',
                          '2881_dec2003', '2881o_dec2003',
                          '2975_oct2005a', '2975o_oct2005a',
                          '3002_dec2005', '3002o_dec2005',
                          '3004_oct2005b', '3004o_oct2005b',
                          '3632_nov2007', '3632o_nov2007',
                          '3855_nov2012', '3855o_nov2012',
                          '4016_dec2008', '4016o_dec2008',
                          '5127_aug2004b', '5127o_aug2004b',
                          '6476_oct2005b', '6476o_oct2005b',
                          '6494_jun2005', '6494o_jun2005',
                          '6616_dec2008', '6616o_dec2008',
                          ]

            IS_KEEP_FIXED = np.array([myfield in KEEP_FIXED 
                                     for myfield in IPHASQC.field('id')])
            anchors = (IS_STABLE | IS_KEEP_FIXED)[IPHASQC_COND_RELEASE]
            log.info('IS_STABLE: {0} fields are H-alpha anchors'.format(anchors.sum()))
            return anchors

        else:
            tolerance = 0.03  # Default = 0.03
            min_matches = 30  # Default = 20
            anchors = []
            IS_APASS_ANCHOR = ( (IPHASQC.field('rmatch_apassdr7') >= min_matches)
                              & (IPHASQC.field('imatch_apassdr7') >= min_matches)
                              & (np.abs(IPHASQC.field('rshift_apassdr7')) <= tolerance)
                              & (np.abs(IPHASQC.field('ishift_apassdr7')) <= tolerance)
                              & (np.abs(IPHASQC.field('rshift_apassdr7') - IPHASQC.field('ishift_apassdr7')) <= tolerance) )

            IS_OLD_ANCHOR = (IPHASQC.field('anchor') == 1)

            # Extra anchors selected in the final phases of the data release,
            # when a few areas with poor anchor coverage were spotted
            EXTRA_ANCHORS = ascii.read(os.path.join(constants.LIBDIR,
                                                    'anchor-extra.txt'))['field']
            IS_EXTRA_ANCHOR = np.array([myfield in EXTRA_ANCHORS 
                                        for myfield in IPHASQC.field('id')])
            # Make sure the following runs are no anchors
            # cf. e-mail Janet to Geert, 13 Aug 2013
            ANCHOR_BLACKLIST = ascii.read(os.path.join(constants.LIBDIR,
                                                       'anchor-blacklist.txt'))['field']
            IS_BLACKLIST = np.array([myfield in ANCHOR_BLACKLIST 
                                     for myfield in IPHASQC.field('id')])

            # Extra night with good conditions
            ANCHOR_NIGHTS = [20030915, 20031018, 20031101, 20031104, 20031108,
                             20031117, 20040707, 20040805, 20040822, 20041022,
                             20050629, 20050709, 20050710, 20050711, 20050916,
                             20050917, 20050918, 20051023, 20051101, 20051102,
                             20061129, 20061130, 20061214, 20070627, 20070630,
                             20080722, 20080723, 20090808, 20090810, 20091029,
                             20091031]
            IS_IN_EXTRA_NIGHT = np.array([mynight in ANCHOR_NIGHTS 
                                       for mynight in IPHASQC.field('night')])

            # Nights which should NOT provide anchors
            NIGHT_BLACKLIST = [20031117, 20051109, 20061128, 20091029, 20101029,]
            IS_IN_NIGHT_BLACKLIST = np.array([night in NIGHT_BLACKLIST 
                                              for night in IPHASQC.field('night')])

            # Anchors must not have known quality issues
            IS_QUALITY_OK = ((IPHASQC.field('seeing_max') < 2.0) &
                               (IPHASQC.field('airmass_max') < 1.4) &
                               (IPHASQC.field('qflag') != 'C') &
                               (IPHASQC.field('qflag') != 'D'))

            anchors = (-IS_BLACKLIST &
                       -IS_IN_NIGHT_BLACKLIST &
                       IS_STABLE & 
                       IS_QUALITY_OK &
                       (IS_OLD_ANCHOR | IS_EXTRA_ANCHOR | IS_IN_EXTRA_NIGHT | IS_APASS_ANCHOR)
                      )
            result = anchors[IPHASQC_COND_RELEASE]

            log.info('IS_APASS_ANCHOR: {0} fields'.format(IS_APASS_ANCHOR.sum()))
            log.info('IS_OLD_ANCHOR: {0} fields'.format(IS_OLD_ANCHOR.sum()))
            log.info('IS_EXTRA_ANCHOR: {0} fields'.format(IS_EXTRA_ANCHOR.sum()))
            log.info('IS_IN_EXTRA_NIGHT: {0} fields'.format(IS_IN_EXTRA_NIGHT.sum()))
            log.info('IS_BLACKLIST: {0} fields'.format(IS_BLACKLIST.sum()))            
            log.info('Anchors in data release: {0} fields'.format(result.sum()))

            return result