Beispiel #1
0
def quad_check(stomp_map, ang, rad, system, res=2048):
    flags = 0

    angle1 = 0.0
    angle2 = 90.0
    wedge_bound = stomp.WedgeBound(ang, rad, angle1, angle2, system)
    mw = stomp.Map(wedge_bound, 1.0, res)
    if stomp_map.Contains(mw):
        flags += FIRST_QUADRANT_OK

    angle1 = 90.0
    angle2 = 180.0
    wedge_bound = stomp.WedgeBound(ang, rad, angle1, angle2, system)
    mw = stomp.Map(wedge_bound, 1.0, res)
    if stomp_map.Contains(mw):
        flags += SECOND_QUADRANT_OK

    angle1 = 180.0
    angle2 = 270.0
    wedge_bound = stomp.WedgeBound(ang, rad, angle1, angle2, system)
    mw = stomp.Map(wedge_bound, 1.0, res)
    if stomp_map.Contains(mw):
        flags += THIRD_QUADRANT_OK

    angle1 = 270.0
    angle2 = 360.0
    wedge_bound = stomp.WedgeBound(ang, rad, angle1, angle2, system)
    mw = stomp.Map(wedge_bound, 1.0, res)
    if stomp_map.Contains(mw):
        flags += FOURTH_QUADRANT_OK

    return flags
Beispiel #2
0
 def setUp(self):
     self.stomp_map = stomp.Map(
         'data/COSMOS_X_zCOSMOS_BRIGHT_excluded.map')
     self.stomp_map.InitializeRegions(8)
     self.reference_cat_name = (
         'data/zCOSMOS_BRIGHT_v3.5_spec_FLAG34_FLAG134.fits')
     self.unknown_cat_name = (
         'data/COSMOS_iband_2009_radecidstomp_regionzp_best.fits')
     self.dummy_args = DummyArgs()
Beispiel #3
0
 def setUp(self):
     self.dummy_args = DummyArgs()
     self.stomp_map = stomp.Map('data/COSMOS_X_zCOSMOS_BRIGHT_excluded.map')
     self.stomp_map.InitializeRegions(8)
     (self.reference_vect, self.reference_id_array,
      self.reference_tree) = stomp_utils.load_reference_sample(
          'data/zCOSMOS_BRIGHT_v3.5_spec_FLAG34_FLAG134.fits',
          self.stomp_map, self.dummy_args)
     self.unknown_tree = stomp_utils.load_unknown_sample(
         'data/COSMOS_iband_2009_radecidstomp_regionzp_best.fits',
         self.stomp_map, self.dummy_args)
Beispiel #4
0
def test_speed(create_each_time=False, explicit=False):
    from time import time
    import columns

    c = columns.Columns("~/sweeps_reduce/gal01.cols")
    ra = c["ra"][0:500000]
    dec = c["dec"][0:500000]

    iw = np.zeros(ra.size, dtype=bool)

    stomp_map = stomp.Map(
        "/home/users/esheldon/masks/stomp-sdss/stripe_dr7.hmap_basic")  # noqa

    tm0 = time()
    if create_each_time:
        stdout.write("Testing creation of angular coord each time\n")
        i = 0
        while i < ra.size:
            ang = stomp.AngularCoordinate(ra[i], dec[i],
                                          stomp.AngularCoordinate.Equatorial)
            iw[i] = stomp_map.Contains(ang)
            del ang
            i += 1
    else:
        stdout.write("Testing re-setting values of same object\n")
        i = 0
        ang = stomp.AngularCoordinate()

        if explicit:
            while i < ra.size:
                ang.SetEquatorialCoordinates(ra[i], dec[i])
                iw[i] = stomp_map.Contains(ang)
                i += 1
        else:
            system = stomp.AngularCoordinate.Equatorial
            while i < ra.size:
                ang.Set(ra[i], dec[i], system)
                iw[i] = stomp_map.Contains(ang)
                i += 1

    tm1 = time()
    esutil.misc.ptime(tm1 - tm0)
Beispiel #5
0
from the_wizz import core_utils
from the_wizz import stomp_utils
from the_wizz import input_flags
from the_wizz import pair_maker_utils

if __name__ == "__main__":
    print("")
    print("the-wizz has begun conjuring: running pair maker...")
    # Load the command line arguments.
    args = input_flags.parse_input_pair_args()
    input_flags.print_args(args)
    # Create the output hdf5 file where we will store the output for the
    # pair finding including raw pairs, area, unmasked fraction. We do this
    # first to soft fail rather than run through the code.
    # Load the stomp geometry coving the area of spectroscopic overlap.
    stomp_map = stomp.Map(args.stomp_map)
    # We request regionation for use with spatial bootstrapping. The
    # resolution found for regionation also sets the max resolution of the
    # different STOMP tree maps.
    stomp_map.InitializeRegions(args.n_regions)
    print("Created %i Regions at resolution %i..." %
          (stomp_map.NRegion(), stomp_map.RegionResolution()))
    # Load the sample with known redshifts.
    (reference_vector, reference_ids, reference_tree_map) = \
        stomp_utils.load_reference_sample(
            args.reference_sample_file, stomp_map, args)
    # Load the unknown sample from disc. Assumed data type is fits.
    unknown_itree = stomp_utils.load_unknown_sample(args.unknown_sample_file,
                                                    stomp_map, args)
    # We also wish to subtract a random sample from density estimate. This
    # function creates a set of uniform data points on the geometry of the
Beispiel #6
0
    hdu = fits.open(args.input_fits_file)
    data = hdu[1].data
    ra_min = data[args.ra_name].min()
    ra_max = data[args.ra_name].max()
    dec_min = data[args.dec_name].min()
    dec_max = data[args.dec_name].max()

    print("Creating bounding area...")
    latlon_bound = stomp.LatLonBound(np.double(dec_min), np.double(dec_max),
                                     np.double(ra_min), np.double(ra_max),
                                     stomp.AngularCoordinate.Equatorial)
    print("\tMax possible Area: %.8f deg^2" % latlon_bound.Area())

    print("Creating STOMP map...")
    output_stomp_map = stomp.Map()
    pix_vect = stomp.PixelVector()
    for obj_idx, obj in enumerate(data):
        if (obj_idx + 1) % args.n_object_batch == 0:
            output_stomp_map.IngestMap(pix_vect)
            pix_vect = stomp.PixelVector()
        tmp_ang = stomp.AngularCoordinate(
            np.double(obj[args.ra_name]), np.double(obj[args.dec_name]),
            stomp.AngularCoordinate.Equatorial)
        pix_vect.push_back(stomp.Pixel(tmp_ang, args.resolution, 1.0))
    output_stomp_map.IngestMap(pix_vect)

    print("\tFinal Map Area: %.8f deg ^2; Ratio vs bounding box: %.8f" %
          (output_stomp_map.Area(),
           output_stomp_map.Area() / latlon_bound.Area()))
    print("\tObjects per pixel %.8f" %
    number = []
    for c in cat:
        print c

        cfht_cat = fits.getdata(c)
        if c[52] == 'i':
            mask = np.logical_and(cfht_cat['MAG_i'] >= mag - 0.1,
                                  cfht_cat['MAG_i'] < mag + 0.1)
        else:
            mask = np.logical_and(cfht_cat['MAG_y'] >= mag - 0.1,
                                  cfht_cat['MAG_y'] < mag + 0.1)

        cfht_cat = cfht_cat[mask]

        m = stomp.Map(
            '/vol/fohlen11/fohlen11_1/cmorrison/data/CFHTLenS/Maps/' +
            c[45:53] + 'zrgu_finalmask_mosaic_stomp16384.map')
        A = m.Area()
        number.append(len(cfht_cat) / A)

    data = np.mean(number)
    err = np.var(number)
    numgalaxies.append([data, err])

plt.errorbar(mag_list,
             numgalaxies[:, 0],
             numgalaxies[:, 1],
             fmt='ko',
             lw=2,
             markersize=10)
plt.ylabel(r"N", size=15)
Beispiel #8
0
def create_excluded_map(input_mask, ext_map, output_name, resolution, offset,
                        n_points, counter_clockwise_pixels, wcs_file, verbose):
    """
    Given the input mask, a STOMP map to exclude with, we create the covering
    for the maximum RA and DEC in fits image mask and exclude the area
    specified in the STOMP map creating a output STOMP map that we can then use
    for correlations and other analyses.
    Args:
        input_mask: string name of the input fits image file
        ext_map: stomp.Map object specifying the area to exclude
        output_name: string name of the file to write the resultant STOMP map
        to resolution: int resolution to create the covering STOMP map at.
        offset: int number of pixels to offset from the edge of the image.
        verbose: bool print check statemetns to stdout
    """
    hdu = fits.open(input_mask)
    if wcs_file is None:
        w = wcs.WCS(hdu[0].header)
    else:
        w = wcs.WCS(fits.getheader(wcs_file))

    naxis1_edge_step = ((hdu[0].header['NAXIS1'] - 1 - 2 * offset) //
                        (1. * n_points))
    naxis2_edge_step = ((hdu[0].header['NAXIS2'] - 1 - 2 * offset) //
                        (1. * n_points))

    if counter_clockwise_pixels:
        ang_vect = stomp.AngularVector()
        # South edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[1 + offset + p_idx * naxis1_edge_step, 1 + offset]],
                         np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # West edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    hdu[0].header['NAXIS1'] - offset,
                    1 + offset + p_idx * naxis2_edge_step
                ]], p.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # North edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    hdu[0].header['NAXIS1'] - offset -
                    p_idx * naxis1_edge_step, hdu[0].header['NAXIS2'] - offset
                ]], np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # East edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    1 + offset,
                    hdu[0].header['NAXIS2'] - offset - p_idx * naxis2_edge_step
                ]], np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
    else:
        ang_vect = stomp.AngularVector()
        # South edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[1 + offset, 1 + offset + p_idx * naxis2_edge_step]],
                         np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # West edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    1 + offset + p_idx * naxis1_edge_step,
                    hdu[0].header['NAXIS2'] - offset
                ]], np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # North edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    hdu[0].header['NAXIS1'] - offset,
                    hdu[0].header['NAXIS2'] - offset - p_idx * naxis2_edge_step
                ]], np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))
        # East edge:
        for p_idx in range(n_points):
            tmp_point = w.wcs_pix2world(
                np.array([[
                    hdu[0].header['NAXIS1'] - offset -
                    p_idx * naxis1_edge_step, 1 + offset
                ]], np.float_), 1)[0]
            ang_vect.push_back(
                stomp.AngularCoordinate(tmp_point[0], tmp_point[1],
                                        stomp.AngularCoordinate.Equatorial))

    bound = stomp.PolygonBound(ang_vect)
    print("Max Area: %.8f" % bound.Area())
    output_stomp_map = stomp.Map(bound, 1.0, resolution, verbose)
    output_stomp_map.ExcludeMap(ext_map)
    print("Final Map Area: %.8f" % output_stomp_map.Area())
    output_stomp_map.Write(output_name)

    return None
Beispiel #9
0
def create_exclusion(input_mask, output_map_name, max_resolution, max_load,
                     mask_value, mask_is_less_than, wcs_file, verbose):
    """
    Function for creating an exclusion mask from the input fits mask. Mismatch
    between STOMP pixels and the fits image pixels could cause area the should
    be masked to be unmasked. By creating the exclusion first and making it
    slightly larger than the input masked region we can guarantee that all
    masked area is properly masked.
    Args:
        input_mask: string name for fits image mask to load.
        output_map_name: string output name of the exclusion mask. If None then
            no map is written.
        max_resolution: resolution at which to attempt to create the stomp
            exclusion mask.
        max_load: int number of pixels to load before dumping them into the
            STOMP map.
        verbose: bool print check statements.
    Returns:
        a stomp.Map object
    """
    try:
        mask = fits.getdata(input_mask)
        # Load the WCS from the input fits file.
    except ValueError:
        print("ERROR: Failed to load", input_mask, "exiting")
        return None
    hdu = fits.open(input_mask)
    if wcs_file is None:
        w = wcs.WCS(hdu[0].header)
    else:
        w = wcs.WCS(fits.getheader(wcs_file))

    if mask_is_less_than:
        max_pix = len(mask[mask < mask_value])
    else:
        max_pix = len(mask[mask > mask_value])
    print("Max Pix:", max_pix)
    pix_vect = stomp.PixelVector()

    tot_pix = 0
    output_map = stomp.Map()
    for idx1 in range(mask.shape[0]):
        for idx2 in range(mask.shape[1]):
            if not mask_is_less_than and mask[idx1, idx2] <= 0:
                continue
            elif mask_is_less_than and mask[idx1, idx2] >= 0:
                continue
            wcs_point = w.wcs_pix2world(
                np.array([[idx2 + 1, idx1 + 1]], np.float_), 1)
            ang = stomp.AngularCoordinate(wcs_point[0, 0], wcs_point[0, 1],
                                          stomp.AngularCoordinate.Equatorial)
            if output_map.Contains(ang):
                continue
            pix_vect.push_back(stomp.Pixel(ang, max_resolution, 1.0))
            if pix_vect.size() >= max_load:
                tmp_map = stomp.Map(pix_vect)
                if verbose:
                    print("Created temp map. Area: %s" % tmp_map.Area())
                output_map.IngestMap(tmp_map)
                tot_pix += pix_vect.size()
                pix_vect.clear()
                del tmp_map
    tmp_map = stomp.Map(pix_vect)
    output_map.IngestMap(tmp_map)
    tot_pix += pix_vect.size()
    pix_vect.clear()
    del tmp_map

    print("Final Map:", output_map.Area(), output_map.Size())
    if output_map_name is not None:
        output_map.Write(output_map_name)

    return output_map
Beispiel #10
0
                        'moves around the edge of the image to create the '
                        'map. By default, the code will work if increasing '
                        'x and increasing y are in the direction of '
                        'increasing RA and DEC respectivily.')
    parser.add_argument('--max_load',
                        default=1000000,
                        type=int,
                        help='Number of image pixels to load '
                        'before dumping them into the map. This is a trick to '
                        'reduce the ammount of memory needed for creating the '
                        'exclusion map. It also makes the map creation '
                        'faster.')
    parser.add_argument('-v',
                        '--verbose',
                        action="store_true",
                        help='Output full verbosity for stomp')
    args = parser.parse_args()

    if args.input_exclusion_name is None:
        ext_map = create_exclusion(args.input_fits_mask,
                                   args.output_exclusion_name, args.resolution,
                                   args.max_load, args.mask_value,
                                   args.mask_is_less_than, args.input_wcs_file,
                                   args.verbose)
    else:
        ext_map = stomp.Map(args.input_exclusion_name)
    create_excluded_map(args.input_fits_mask, ext_map, args.output_map_name,
                        args.resolution, args.offset, args.n_points,
                        args.counter_clockwise_pixels, args.input_wcs_file,
                        args.verbose)