Example #1
0
def prof_mangle_pix(points):
    """Profile pixelized mangle."""
    #mng = mangle.Mangle('../../geometry/centerpost_mask.ply')
    mng = mangle.Mangle('../../geometry/badfield_mask_unphot-ugriz_pix.ply')
    print(mng.pixelization)
    prof = cProfile.Profile()
    prof.runcall(mng.get_polyids, points.RA, points.DEC)
    return prof
Example #2
0
 def test_write(self):
     """Test writing the polygon file and re-reading it."""
     self.mng.writeply(self.writetestfile)
     mng_temp = mangle.Mangle(self.writetestfile)
     np.testing.assert_allclose(mng_temp.polyids, self.mng.polyids)
     np.testing.assert_allclose(mng_temp.areas, self.mng.areas)
     np.testing.assert_allclose(mng_temp.weights, self.mng.weights)
     for poly1, poly2 in zip(mng_temp.polylist, self.mng.polylist):
         np.testing.assert_allclose(poly1, poly2)
     if 'pixels' in dir(self.mng):
         np.testing.assert_allclose(mng_temp.pixels, self.mng.pixels)
Example #3
0
    def setUp(self):
        # set up the mangle polygon geometries
        #self.polyfile = '../data/current_boss_geometry.ply'
        #self.polyfile = '../data/geometry/geometry-boss_1-11-balkanized.ply'
        #self.polyfile = '../data/geometry/geometry-boss_7-10.ply'
        #self.polyfile = '/Users/parejkoj/astronomy/BOSS/data/geometry/geometry-boss_7-11-balkanized.ply'
        self.polyfile = '/Users/parejkoj/astronomy/BOSS/data/geometry/geometry-boss7.ply'
        self.mng = mangle.Mangle(self.polyfile)
        self.mng_orig = mangle_orig.Mangle(self.polyfile)

        # just require that the fits file exist for now.
        self.fitsfile = self.polyfile.split('.ply')[0] + '.fits'
        if glob.glob(self.fitsfile):
            self.mng_fits = mangle.Mangle(self.fitsfile)
        else:
            self.mng_fits = None

        # read in some test data of galaxies
        # these two lines give a relatively quick test
        data = pyfits.open(
            '/Users/parejkoj/astronomy/BOSS/data/final-boss7.fits')
        self.data = data[1].data[:1000]
        # these two lines give a very long test, and are not recommended
        # for use with any non-vectorized mangle, as they will take for ever.
        #data = pyfits.open('/Users/parejkoj/astronomy/BOSS/data/samples/boss+legacy_7-12_CMASS-randoms-2000000.fits')
        #self.data = data[1].data
        data = None

        self.writetestfile = './mangle_test_polys.ply'

        # Write out a file containing RA DEC for the commandline mangle
        self.mangletestfile = './mangle_test_data.dat'
        outfile = file(self.mangletestfile, 'w')
        outcsv = csv.writer(outfile, delimiter=' ')
        outfile.write('#RA Dec\n')
        outfile.write('#This file written by test_mangle for unittesting.\n')
        outfile.write('#It may be safely deleted.\n')
        outcsv.writerows(zip(self.data.RA, self.data.DEC))
Example #4
0
    def setUp(self):
        """
        Set up for an individual test.

        We want to create a new mangle instance for every test,
        incase we mess it up while testing. This makes the tests take longer,
        but that's ok as it isn't part of the timed portions.
        """
        # set up the mangle polygon geometries
        self.mng = mangle.Mangle(self.polyfile)
        self.mng_pix = mangle.Mangle(self.polyfile_pix)
        #print('Using',self.polyfile,'as the polygon file.')
        #print('Using',self.polyfile,'as the pixelized polygon file.')

        # TBD: just require that the fits file exist for now.
        # Should eventually have a test that compares .ply and .fits versions.
        self.fitsfile = self.polyfile.split('.ply')[0] + '.fits'
        if os.path.exists(self.fitsfile):
            self.mng_fits = mangle.Mangle(self.fitsfile)
        if os.path.exists(self.fitsfile + '.gz'):
            self.mng_fits = mangle.Mangle(self.fitsfile + '.gz')
        else:
            self.mng_fits = None
Example #5
0
def fits2ply(infile, outfile=None):
    base, ext = os.path.splitext(infile)
    if ext != '.fits':
        raise Exception("Infile must be FITS.")

    if outfile is None:
        outfile = base + '.ply'
    if os.path.exists(outfile): os.remove(outfile)

    print "Converting %s to %s" % (infile, outfile)

    ### Python Routine
    import mangle
    mask = mangle.Mangle(infile)
    mask.write(outfile)
Example #6
0
def prof_mangle(points):
    mng = mangle.Mangle('../../geometry/boss_geometry_2012_06_18.ply')
    prof = cProfile.Profile()
    prof.runcall(mng.get_polyids, points.RA, points.DEC)
    return prof
import astropy.units as u
import astropy.coordinates as co
from astropy.coordinates import SkyCoord
import numpy as n
import mangle
import sys

chunk = "eboss8"

outputDir = join(os.environ['EBOSS_ROOT'], "target", "elg", "clusteringSample")
outputCatalog = "ELG-catalog-angular.random.dat"

# loads geometry information :
tilingDir = join(os.environ['EBOSS_ROOT'], "ebosstilelist/trunk/outputs",
                 chunk)
maskGeometry = mangle.Mangle(join(tilingDir, "geometry-" + chunk + ".fits"))
maskGeometryTSR = mangle.Mangle(
    join(outputDir, "geometry-" + chunk + "-TSR.ply"))

# loads randoms that account for the geometry of the photometric survey :
raRinter, decRinter = n.loadtxt(join(os.environ['EBOSS_ROOT'], "target", "elg",
                                     "decalsSelections", "randoms",
                                     "randoms_ELG_280.random.masked"),
                                usecols=(0, 1),
                                unpack=True)
selection = (raRinter > maskGeometry.ramid.min() - 3.) & (
    raRinter < maskGeometry.ramid.max() + 3.) & (
        decRinter > maskGeometry.decmid.min() - 3.) & (
            decRinter < maskGeometry.decmid.max() + 3.)

raR = raRinter[selection]
Example #8
0
                 chunk)
hduTiled = fits.open(join(tilingDir, "final-" + chunk + ".fits"))
#hduTiled = fits.open(join(tilingDir,"all-"+chunk+".fits"))
raTiled = hduTiled[1].data['RA']
decTiled = hduTiled[1].data['DEC']

brickidTiled = hduTiled[1].data['BRICKID_DECALS']
objidTiled = hduTiled[1].data['OBJID_DECALS']
strIDTiled = n.array([
    str(brickidTiled[ii]) + "_" + str(objidTiled[ii])
    for ii in range(len(objidTiled))
])

# print "strIDTiled", strIDTiled, len(strIDTiled)

maskGeometry = mangle.Mangle(join(tilingDir, "geometry-" + chunk + ".ply"))

observed = n.zeros_like(strID, dtype=bool)
for jj in range(len(strID)):
    if len((strID[jj] == strIDTiled).nonzero()[0]) > 0:
        observed[jj] = True
    else:
        observed[jj] = False

len(observed.nonzero()[0])
# print "3"
# compute TSR : N galaxy with fiber / N galaxy targeted in each polygon.
pID = n.array([maskGeometry.polyid(ra[ii], dec[ii]) for ii in range(len(ra))])
pID_tiled = n.array([
    maskGeometry.polyid(raTiled[ii], decTiled[ii])
    for ii in range(len(raTiled))
Example #9
0
def inChunk(geomFile,cat):
    mng=mangle.Mangle(geomFile)
    object_mask = mng.get_polyids(cat[:,0],cat[:,1])
#    print(object_mask)
    return cat[(object_mask>0)]
Example #10
0
def plotGeometry(geomFile):
    mng=mangle.Mangle(geomFile)
    polys = mng.graphics()
#mng.drawpolys()
    for poly in polys:
        plt.plot(poly['ra'],poly ['dec'],lw=1,color='black')#,color=poly['weight']
Example #11
0
# Some initial definitions
# If you want to run this at home
# you need to change these file locations
polyfile = '/Users/hamilton/SDSS/Data/LRG/current_boss_geometry.ply'
targetfile = '/Users/hamilton/SDSS/Data/LRG/FinalFits/final-boss9.fits'
spallfile = '/Users/hamilton/SDSS/Data/LRG/spAll-v5_4_31.fits'
steradian = (np.pi / 180)**2

# first, some polygon manipulation
import mangle
import mangle_utils
import Match
import pairs.mr_wpairs as wpairs
# Initialize a Mangle instance with a polygon file for one chunk.
mng = mangle.Mangle(polyfile)

# Plot all the polygons
polys = mng.graphics()
for poly in polys:
    plot(poly['ra'], poly['dec'], lw=2)

# all polygons with areas greater than 1 sq. deg.
test = mng.areas > 3. * (np.pi / 180)**2
polys = mng[test].graphics()
for poly in polys:
    plt.plot(poly['ra'], poly['dec'], lw=2)