Пример #1
0
def main():
    get_photometry(sys.argv[1], sys.argv[2])

    with open('NGC4621_i.cat', 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
        tmp2 = map(lambda line: Sources.SCAMSource(line), tmp)
    ra = map(lambda line: line.ra, tmp2)
    dec = map(lambda line: line.dec, tmp2)

    i_sources = Quadtree.ScamEquatorialQuadtree(min(ra), min(dec),
                                              max(ra), max(dec))
    with open('NGC4621_i.cat', 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
        map(lambda line: i_sources.insert(Sources.SCAMSource(line)), tmp)
        makeRegionFile.makeRegionFile('NGC4621_i.cat', 'NGC4621_i.reg', 10, 'blue')

    with open('NGC4621_g.cat', 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
        tmp2 = map(lambda line: Sources.SCAMSource(line), tmp)
    ra = map(lambda line: line.ra, tmp2)
    dec = map(lambda line: line.dec, tmp2)

    g_sources = Quadtree.ScamEquatorialQuadtree(min(ra), min(dec),
                                              max(ra), max(dec))
    with open('NGC4621_g.cat', 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
        map(lambda line: g_sources.insert(Sources.SCAMSource(line)), tmp)
        makeRegionFile.makeRegionFile('NGC4621_g.cat', 'NGC4621_g.reg', 10, 'blue')

    # Aaron gave me the coordinates
    m59_ucd3_i = i_sources.match(190.54601, 11.64478)
    m59_ucd3_g = g_sources.match(190.54601, 11.64478)

    print '\n'

    print "M58-UCD3's Location in catalog: ", m59_ucd3_i.name
    print "I Mag and G Mag: ",  m59_ucd3_i.mag_auto, m59_ucd3_g.mag_auto
    print 'M59-UCD3 g-i: ', m59_ucd3_g.mag_auto - m59_ucd3_i.mag_auto
    print 'M59-UCD3 FWHM: ', m59_ucd3_g.fwhm*0.2
    print "Coordinates from i-band catalog - "
    print phot_utils.convertRA(m59_ucd3_i.ra), phot_utils.convertDEC(m59_ucd3_i.dec)
    print "Coordinates from g-band catalog - "
    print phot_utils.convertRA(m59_ucd3_g.ra), phot_utils.convertDEC(m59_ucd3_g.dec)

    print '\n'
    print '\n'

    m59cO_i = i_sources.match(190.48056, 11.66771)
    m59cO_g = g_sources.match(190.48056, 11.66771)
    print "M59cO's Location in catalog: ", m59cO_i.name
    print "I Mag and G Mag: ", m59cO_i.mag_auto, m59cO_g.mag_auto
    print 'M59cO g-i: ', m59cO_g.mag_auto - m59cO_i.mag_auto
    print "Coordinates from i-band catalog - "
    print phot_utils.convertRA(m59cO_i.ra), phot_utils.convertDEC(m59cO_i.dec)
    print "Coordinates from g-band catalog - "
    print phot_utils.convertRA(m59cO_g.ra), phot_utils.convertDEC(m59cO_g.dec)

    print '\n'
Пример #2
0
def correct_mags(galaxy, catalog, band):
    print "band: ", band
    zp = calcZeropoint.calcZP(galaxy, catalog, band)
    if verbose:
        print "Zeropoint for " + band + "-band", zp

    with open(catalog, 'r') as f:
        tmp = filter(lambda line: phot_utils.no_head(line), f)

    sources = map(lambda line: Sources.SCAMSource(line), tmp)
    for source in sources:
        source.mag_aper = round(source.mag_aper + zp, 3)
        source.mag_auto = round(source.mag_auto + zp, 3)
        source.mag_best = round(source.mag_best + zp, 3)

    new_catalog = 'zpcorrected_' + catalog
    with open(new_catalog, 'w') as output:
        output.write(''.join(
            map(
                lambda source: '%5s' % source.name + '%15s' % source.flux_iso +
                '%15s' % source.fluxerr_iso + '%15s' % source.flux_aper +
                '%15s' % source.fluxerr_aper + '%15s' % source.ximg + '%15s' %
                source.yimg + '%15s' % source.ra + '%15s' % source.dec + '%15s'
                % source.mag_auto + '%15s' % source.mag_auto_err + '%15s' %
                source.mag_best + '%15s' % source.mag_best_err + '%15s' %
                source.mag_aper + '%15s' % source.mag_aper_err + '%15s' %
                source.a_world + '%15s' % source.a_world_err + '%15s' % source.
                b_world + '%15s' % source.b_world_err + '%15s' % source.
                theta_err + '%15s' % source.theta + '%15s' % source.isoarea +
                '%15s' % source.mu + '%15s' % source.flux_radius + '%15s' %
                source.flags + '%15s' % source.fwhm + '%15s' % source.elogation
                + '%15s' % source.vignet + '\n', sources)))
    return new_catalog
Пример #3
0
def calcZP(galaxy, scam, band):
    """
    To calculate the zeropoint of the Subaru image match the Subaru catalog
    and the table returned from Vizier.
    """
    sdss = getSDSS(galaxy)
    column = str(band + 'mag')
    print "Column: ", column

    # Get only the brightest sources of both SDSS and Subaru.
    mag = map(lambda source: source[column], sdss)
    max_mag = np.mean(mag) + 0.25*np.mean(np.std(mag))
    sdss = filter(lambda s: phot_utils.mag_cut(s[column], 18, max_mag), sdss)

    with open(scam, 'r') as f:
        catalog = [S.SCAMSource(line) for line in f if phot_utils.no_head(line)]

    mag = map(lambda s: s.mag_best, catalog)
    max_mag = np.mean(mag) + 0.25*np.mean(np.std(mag))
    sources = filter(lambda s: phot_utils.mag_cut(s.mag_best, 18, max_mag), catalog)

    ra = [source.ra for source in catalog]
    dec = [source.dec for source in catalog]
    scam_sources = Q.ScamEquatorialQuadtree(min(ra), min(dec),
                                            max(ra), max(dec))
    map(lambda sources: scam_sources.insert(sources), sources)
    matches = associate(sdss, scam_sources)

    m_scam_sources = map(lambda source: source.mag_aper, matches)
    m_sdss_sources = map(lambda source: source.match2[column], matches)

    # Clip outliers of (m_sdss - m_scam)
    difference = []
    for m_sdss, m_scam in zip(m_sdss_sources, m_scam_sources):
        difference.append(m_sdss - m_scam)
    std =  np.std(difference)

    # Make a region file to check the matching
    makeRegionFile.fromList(matches, band + "_scam_match_source.reg", 0.1, "red")
    makeRegionFile.fromList(matches, band + "_sdss_match_source.reg", 0.1, "green")

    clipped = []
    for entry in matches:
        if entry.match2[column] - entry.mag_aper < std*3:
            clipped.append(entry)

    difference = []
    for entry in clipped:
        difference.append(entry.match2[column] - entry.mag_aper)
    m_scam = map(lambda source: source.mag_aper, clipped)

    # Look at offsets
    plt.plot(difference, m_scam, linestyle='none', marker='o')
    plt.xlabel(r'$m_{SDSS}$ - $m_{SCAM}$', fontsize=20)
    plt.ylabel(r'$m_{SCAM}$', fontsize=20, labelpad=30)
    path = os.getcwd()
    phot_utils.save(path, band + '_zp.png')

    # Take median of offset
    return  np.median(difference)
Пример #4
0
def main():
    equinox = 2000
    passband = 'I'
    sample = 1
    s_flag = 1
    pa = 119
    catalog = open(sys.argv[1], 'r')

    # Get rid of any header and real lines into source objects
    tmp = filter(lambda line: pu.noHead(line), catalog)
    src = map(lambda line: S.CFHTSource(line), tmp)
    catalog.close()

    # DSIM requires that RA and DEC be in sexagesimal
    ra = map(lambda obj: pu.convertRA(obj.ra), src)
    dec = map(lambda obj: pu.convertDEC(obj.dec), src)

    # Determine priority for each source
    mag_min = min(map(lambda s: s.mag, src))
    priority = map(lambda s: detPriority(mag_min, s.mag1), src)

    # Put it all together and write to ouput file
    output = open(sys.argv[2], 'w')
    for i in range(len(src)):
        output.write('%10s' % src[i].name + '%15s' % ra[i] + '%15s' % dec[i] +
                        '%6.d' % equinox + '%10.2f' % src[i].mag1 + '%2s' % passband +
                        '%5.0d' % priority[i] + '%5.0d' % sample + '%5s' % s_flag +
                        '%10.d' % pa + '\n')
    output.close()
Пример #5
0
def fromFile(filename, outname, pixsize, color):
    with open(filename, "r") as catalog:
        sources = [Sources.SCAMSource(line) for line in catalog if phot_utils.no_head(line)]
        with open(outname, "w") as out:
            for source in sources:
                out.write("physical;circle(" + str(source.ximg) + "," +
                            str(source.yimg) + "," + str(pixsize) + ") #color=" + str(color) + "\n")
Пример #6
0
def keymatchChains(imagePath):
    # KeyMatchFull, KeyMatchGPU
    
    imageSource = Sources.ImageSource(imagePath, "pgm")
    sift = FeatureExtraction.Sift(imageSource, False, "SiftHess")
    keyMatch = FeatureMatch.KeyMatch(sift, True, "KeyMatchFull", forceRun=True)
    
    print Chain.Render(keyMatch,"UnitTest-keymatchChains-KeyMatchFull-log.txt")
Пример #7
0
def non_flux_terms_dt_tilde_e(tilde_e, tilde_s, tilde_p, lapse, shift,
                              spatial_metric, inv_spatial_metric, source_n,
                              source_i, d_lapse, d_shift, d_spatial_metric,
                              extrinsic_curvature):
    return Sources.source_tilde_e(tilde_e, tilde_s, tilde_p, source_n,
                                  source_i, lapse, d_lapse, d_shift,
                                  d_spatial_metric, inv_spatial_metric,
                                  extrinsic_curvature)
Пример #8
0
def source_tilde_s(tilde_d, tilde_tau, tilde_s, lapse, shift,
                   sqrt_det_spatial_metric, pressure, spatial_velocity,
                   d_lapse, d_shift, d_spatial_metric, inv_spatial_metric,
                   extrinsic_curvature, spatial_metric):
    return Sources.source_tilde_s(tilde_d, tilde_tau, tilde_s,
                                  spatial_velocity, pressure, lapse, d_lapse,
                                  d_shift, d_spatial_metric,
                                  inv_spatial_metric, sqrt_det_spatial_metric,
                                  extrinsic_curvature)
Пример #9
0
def makeRegionFile(filename, outname, pixsize, color):
    catalog = open(filename, "r")
    tmp = filter(lambda line: pu.no_head(line), catalog)

    sources = map(lambda line: S.SCAMSource(line), tmp)

    out = open(outname, "w")
    for source in sources:
        out.write("physical;circle(" + str(source.ximg) + "," +
                  str(source.yimg) + "," + str(pixsize) + ") #color=" +
                  str(color) + "\n")
Пример #10
0
def siftChains(imagePath):
    #SiftWin32, SiftHess, SiftGPU, VLFeat
    
    imageSource = Sources.ImageSource(imagePath, "pgm")
    sift = FeatureExtraction.Sift(imageSource, False, "SiftWin32", forceRun=True)
    
    # SiftWin32 only on windows
    if (Common.Utility.OSName=="Windows"):
        print Chain.Render(sift,"UnitTest-siftChains-SiftWin32-log.txt")
	
	sift.SetProperty("Sift Method", "VLFeat")
	print Chain.Render(sift,"UnitTest-siftChains-VLFeat-log.txt")

    # daisy only on windows (note: this should not be the last test, as the descriptors are for ROIs)
    if (Common.Utility.OSName=="Windows"):
        imageSource = Sources.ImageSource(imagePath, "jpg")
        daisy = FeatureExtraction.Daisy(imageSource, False, roi="0,0,50,50", forceRun=True)
        print Chain.Render(daisy,"UnitTest-siftChains-daisy-log.txt")    
    
    sift.SetProperty("Sift Method", "SiftHess")
    print Chain.Render(sift,"UnitTest-siftChains-SiftHess-log.txt")
Пример #11
0
def source_tilde_s(tilde_d, tilde_tau, tilde_s, tilde_b, tilde_phi, lapse,
                   shift, sqrt_det_spatial_metric, spatial_metric,
                   inv_spatial_metric, d_lapse, d_shift, d_spatial_metric,
                   pressure, spatial_velocity, lorentz_factor, magnetic_field,
                   rest_mass_density, specific_enthalpy, extrinsic_curvature,
                   constraint_damping_parameter):
    return Sources.source_tilde_s(
        tilde_d, tilde_tau, tilde_s, tilde_b, tilde_phi, spatial_velocity,
        magnetic_field, rest_mass_density, specific_enthalpy, lorentz_factor,
        pressure, lapse, d_lapse, d_shift, spatial_metric, d_spatial_metric,
        inv_spatial_metric, sqrt_det_spatial_metric, extrinsic_curvature,
        constraint_damping_parameter)
Пример #12
0
def sfmChainBuild(chainFilePath, imagePath):

    # build chain
    imageSource = Sources.ImageSource(imagePath, "jpg")
    sift = FeatureExtraction.Sift(imageSource, False, "SiftHess")
    keyMatch = FeatureMatch.KeyMatch(sift, False, "KeyMatchFull")
    bundler = BundleAdjustment.Bundler([keyMatch, imageSource])
    radialUndistort = Cluster.RadialUndistort([bundler, imageSource])
    prepCmvsPmvs = Cluster.PrepCmvsPmvs(radialUndistort,
                                        os.path.join(imagePath, "pmvs"))
    cmvs = Cluster.CMVS(prepCmvsPmvs)
    pmvs = Cluster.PMVS(cmvs)

    # persist chain
    Chain.StageRegistry.Save(chainFilePath)
Пример #13
0
def make_trees(catalog):
    with open(catalog, 'r') as f:
        tmp = filter(lambda line: phot_utils.no_head(line), f)
    tmp2 = map(lambda line: Sources.SCAMSource(line), tmp)

    ra = map(lambda line: line.ra, tmp2)
    dec = map(lambda line: line.dec, tmp2)
    sources = Quadtree.ScamEquatorialQuadtree(min(ra), min(dec), max(ra),
                                              max(dec))
    map(lambda line: sources.insert(line), tmp2)

    #if verbose:
    #        makeRegionFile.makeRegionFile('NGC4621_i.cat', 'NGC4621_i.reg', 10, 'blue')

    return sources
Пример #14
0
def resync():
    if not c.UseRemoteServer or len(c.DataUrl) == 0:
        raise Exception("Cannot resync when using local data.")

    print("Syncing with server: {0}".format(c.DataUrl.split("://")[1].split("/")[0]))

    sources = Sources.getRemoteSources(c.DataUrl)
    active = { }

    # Get current call list from server
    ok, response = WebClient.openUrl(c.DataUrl, { "request": 2 })
    if ok:
        data = json.loads(response)
        status = data["status"]

        if status["success"]:
            if isinstance(data["data"], dict):
                # Format: data => source: { cid => [ category, location, meta ] }
                for srcID, calls in data["data"].items():
                    isrc = int(srcID)
                    if not isrc in sources: continue
                    
                    src = sources[isrc]
                    active[src.id] = [ ]

                    for cID, call in calls.items():
                        # Create a call object to represent this item
                        callObj = Calls.CallData(json.loads(call[2]))
                        callObj.category = call[0]
                        callObj.location = call[1]
                        callObj.key = cID
                        callObj.source = src
            
                        active[src.id].append(callObj)
                        print("\t{0}: {1}".format(src.tag, callObj.getShortDisplayString()))
            else:
                print("\t... No calls active.")

        else:
            print("\t...", status["message"])
    else:
        print("\t... failed: " + str(response))

    return sources, active
Пример #15
0
def calc_seeing(catalog, **kwargs):
    """
    Calculate the seeing of an image by taking a SE catalog
    cutting out the extended and dim sources and averaging
    the FWHM. Only for Subaru Suprime-Cam right now
    """
    pixel_scale = 0.20
    with open(catalog, 'r') as f:
        tmp = filter(lambda line: no_head(line), f)
        cat = map(lambda line: sources.SCAMSource(line), tmp)
    shape = map(lambda s: s.a_world, cat)
    peak = det_size_cut(shape, 1000)
    ptsources = filter(lambda s: s.a_world <= peak, cat)
    mag = map(lambda s: s.mag_best, ptsources)
    max_mag = calc_average(mag) - 3.0 * calc_average(variance(mag))
    ptsources = filter(lambda s: mag_cut(s.mag_best, 0, max_mag), ptsources)
    #if kwargs['makereg']:
    fwhm = map(lambda line: line.fwhm, ptsources)
    return sum(fwhm) / len(fwhm) * pixel_scale
Пример #16
0
def main():
    #get_photometry(sys.argv[1], sys.argv[2])
    catalogs = (glob.glob('NGC4621*.cat'))
    for catalog in catalogs:
        if verbose:
            print "Working on catalog: ", catalog
        corrected_catalog = correct_mags(sys.argv[1], catalog, catalog[-5])

    sys.exit()

    with open('NGC4621_g.cat', 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
    g_sources = map(lambda source: Sources.SCAMSource(source), tmp)

    r_sources = make_trees('NGC4621_r.cat')
    i_sources = make_trees('NGC4621_i.cat')

    matches = associate(g_sources, r_sources, i_sources)

    with open('matched_gri.cat', 'w') as out:
        out.write()
Пример #17
0
def bundlerChain(imagePath):
    
    # PMVS path
    pmvsPath = os.path.join(imagePath,"pmvs")

    # build chain
    imageSource = Sources.ImageSource(imagePath, "jpg")
    sift = FeatureExtraction.Sift(imageSource, False, "SiftHess")
    keyMatch = FeatureMatch.KeyMatch(sift, False, "KeyMatchFull")
    bundler = BundleAdjustment.Bundler([keyMatch, imageSource], forceRun=True)
    radialUndistort = Cluster.RadialUndistort([bundler, imageSource], forceRun=True)
    prepCmvsPmvs = Cluster.PrepCmvsPmvs(radialUndistort, pmvsPath, forceRun=True)
    
    # cmvs not build on 32bit Linux yet
    if (Common.Utility.PlatformName != "Linux32bit"):
        cmvs = Cluster.CMVS(prepCmvsPmvs, forceRun=True)
        pmvs = Cluster.PMVS(cmvs, forceRun=True)
    else:
        pmvs = Cluster.PMVS(prepCmvsPmvs, forceRun=True)
        
    # render chain
    print Chain.Render(pmvs,"UnitTest-bundlerChain-log.txt")
Пример #18
0
# For color selection
# Have the slope, y-intercept, and endpoints from M87 data
# This is for <u-z> vs <g-z> space.
b = -0.086
m = 0.50
x0 = 1.5
x1 = 3.0
var = 0.3  # This controls how strict the color cut is

catalog = open("n4459_cfht_ugiz_auto.cat", "r")
catalog.next()  # This is to skip the header

# This reads in the catalog and initalizes each line as a
# CFHT source
sources = map(lambda line: S.CFHTSource(line), catalog)

## Make the color cut
candidates = filter(
    lambda s: pu.makeColorCut(s.mag1, s.mag4, s.mag2, s.mag4, x0, x1, m, b, var
                              ), sources)

# Finds the value of a_world that seems to "contain" the point-like sources
shape = map(lambda s: s.a_world, candidates)
'''
Zach and I use the x-value that seems to contain the gaussian
distribution as the cut off. Not sure how well detSizeCut is
going to work for different data sets so at the moment it's good to
take a look for youself.
'''
pu.LookAtShapes(shape, 1000)
            
            self._properties["Prefix Name"] = prefixName


    def GetOutputImagePath(self, inputImagePath):

        # construct the output image path, including the prefix name
        return os.path.join(self._properties["Output Image Path"],
                            self._properties["Prefix Name"] + 
                            os.path.splitext(os.path.basename(inputImagePath))[0] +
                            "."+self._properties["Image Extension"])
    
    def ProcessImage(self, inputImagePath, outputImagePath):

        # copy the input to output
        shutil.copy(inputImagePath, outputImagePath)


#################################################################################
        
# input/output image path
imagePath = os.path.abspath("../Datasets/ET")
imagePathOut = os.path.join(imagePath, "test")
Common.Utility.MakeDir(imagePathOut)

imageSource = Sources.ImageSource(imagePath, "jpg")

imageCopy = CopyImages(imageSource, "test-", imagePathOut, "jpg")

print Chain.Render(imageCopy)
mass             = parsed_args.mass
channel          = parsed_args.channel
DM_model         = parsed_args.model
add_point_source = parsed_args.add
experiment       = parsed_args.exp
verbose          = parsed_args.verbose
ebl_model        = parsed_args.ebl
ra_shift         = parsed_args.shiftra
dec_shift        = parsed_args.shiftdec
maptree          = parsed_args.maptree

print("running for mass {} GeV".format(mass))
print("            channel {}".format(channel))
print("            {} EBL Model".format(ebl_model))

sources = Sources(DM_model)
sources.set_mass(float(mass))
sources.set_channel(int(float(channel)))
sources.set_EBL_model(ebl_model_name=ebl_model)
sources.shift_templates(ra_shift, dec_shift)
sources.setup(data=experiment)

if add_point_source == 0:
    model = Model(sources.source_M87, sources.source_M49)
else:
    model = Model(sources.source_M87, sources.source_M49,
                  sources.point_M87)

model.link(model.M87.spectrum.main.DMAnnihilationFlux.sigmav,
           model.M49.spectrum.main.DMAnnihilationFlux.sigmav,
           Identity())
Пример #21
0
import random as r
import Quadtree
import Sources as S
import phot_utils

sources = Quadtree.ScamPixelQuadtree(0, 0, 15000, 15000)

with open(
        "/Users/alexawork/Documents/GlobularClusters/Photometry/NGC4649/NGC4649_g.cat"
) as f:
    tmp = filter(lambda line: phot_utils.no_head(line), f)
map(lambda line: sources.insert(S.SCAMSource(line)), tmp)

sources.match(10, 15)
sources.debug()
Пример #22
0
def imageConvertChain(imagePath):
    
    imageSource = Sources.ImageSource(imagePath, "jpg")
    imageConvert = Sources.ImageConvert(imageSource, imagePath, "pgm")
    print Chain.Render(imageConvert,"UnitTest-imageConvertChain-log.txt")
Пример #23
0
    else:
        print("\t... failed: " + str(response))

    return sources, active

# Startup
print("Loading config...")
c = ClientConfig.load()
ClientConfig.save(c)        # This writes default values of new settings

# Get initial data
if c.UseRemoteServer:
    sources, active_calls = resync()
    last_sync = datetime.now()
else:
    sources = Sources.getLocalSources(c.SourceLocation)
    active_calls = { }

# Can't do anything without sources
if len(sources) == 0:
    print("No sources found.")
    sys.exit()

# List source info and initialize call lists
for src in sources.values():
    print("Source #{0}: {1} => {2} [Can check?: {3}]".format(src.id, src.tag, src.parser, Sources.canCheck(src)))
    if not src.id in active_calls:
        active_calls[src.id] = [ ]

# Run
while True:
Пример #24
0
parser.add_argument("--maptree",  dest="maptree", default="../../data/maptree.root")
parser.add_argument("--response", dest="response", default="../../data/response.root")
parsed_args = parser.parse_args()

experiment       = parsed_args.exp
verbose          = parsed_args.verbose
maptree          = parsed_args.maptree
ebin             = parsed_args.ebin
index            = parsed_args.index

lo_range = [0.562, 1.778, 5.623, 17.783, 56.234]
hi_range = [1.778, 5.623, 17.783, 56.234, 177.828]
#lo_range = [1.]
#hi_range = [20.]

sources = Sources()
sources.setup(data=experiment, isQuasiDiff=True, index=index, enLo=lo_range[ebin], enHi=hi_range[ebin])

model_M87 = Model(sources.source_M87)
model_M49 = Model(sources.source_M49)
model_linked    = Model(sources.source_M87, sources.source_M49)
model_notlinked = Model(sources.source_M87, sources.source_M49)

model_linked.link(model_linked.M49.spectrum.main.RangedPowerlaw.K,
                  model_linked.M87.spectrum.main.RangedPowerlaw.K,
                  Identity())

models = [model_M87, model_M49, model_linked, model_notlinked]

if verbose:
    model_linked.display()
Пример #25
0
        from utils import ImageCapturer
        cap = ImageCapturer.ImageCapturer()
        if not cap:
            print "Error opening capture device"
        else:
            print "successfully imported video capture"
        while True:
            rval, frame = cap.get_image()
            fd.processImage(frame)

    if (True):
        img_path = os.path.abspath(
            '/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014'
        )
        [y, block, names, filenames] = Sources.read_images_2(img_path,
                                                             useBatch=2,
                                                             maxNum=1500)

        w = None
        #import csv
        #w = csv.writer(open("../../data/" + 'batch2_46_gamma_dog.csv', 'w'))
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Oliver_2/Oliver-2-41.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Dejan_1/Dejan-1-1.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-3.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-31.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-5.png"

        fd.processImage(cv2.imread(d), 0, w)
        # cv2.imshow("Gallo ", img);
        # import matplotlib.pyplot as plt
        # plt.ion()
Пример #26
0
import glob
import math
import matplotlib.pyplot as plt
import numpy as np

import Sources as S
import phot_utils as pu

noisef = (glob.glob('/Users/alexawork/Documents/GlobularClusters/Photometry/NGC4649/BestApertureFiles/g_ap_*noise*txt'))
signlf = (glob.glob('/Users/alexawork/Documents/GlobularClusters/Photometry/NGC4649/BestApertureFiles/g_ap_*signal*txt'))

noise = []
for thing in noisef:
    f = open(thing)
    ntmp = map(lambda line: S.SCAMSource(line), f)
    f.close()
    nflux = map(lambda f: math.fabs(f.mag_best), ntmp)
    nflux = filter(lambda value: value != 99.0, nflux)
    noise.append(pu.calc_MAD(nflux))

signal = []
for thing in signlf:
    f = open(thing)
    stmp = map(lambda line: S.SCAMSource(line), f)
    f.close()
    sflux = map(lambda f: math.fabs(f.mag_best), stmp)
    sflux = filter(lambda value: value != 99.0, sflux)
    signal.append(pu.calc_MAD(sflux))

Пример #27
0
def findBestAperture(path, image, satur, seeing):
    if os.path.isdir('BestApertureFiles') == False:
        os.mkdir('BestApertureFiles')

    sname = "sign"
    nname = "noise"
    filter_file = "default.conv"
    assoc_file = "measurefluxat.txt"

    output = open(assoc_file, "w")
    for i in xrange(0, 100000):
        output.write('%.3f' % r.uniform(1, 11000) +
                     '%10.3f' % r.uniform(1, 9000) + '\n')

    sp.createSexParam(sname, False)
    sp.createSexParam(nname, True)
    sparam_file = sname + ".param"
    nparam_file = nname + ".param"

    signal = []
    noise = []
    aperture = np.linspace(0.5, 12, num=10)
    for ap in aperture:
        sc.createSexConfig(sname, filter_file, sparam_file, satur, seeing,
                           "nill", ap, False)
        call(['sex', '-c', sname + '.config', image])
        sc.createSexConfig(nname, filter_file, nparam_file, satur, seeing,
                           assoc_file, ap, True)
        call(['sex', '-c', nname + '.config', image])

        scat = open(sname + ".cat")
        stmp = filter(lambda line: pu.no_head(line), scat)
        ncat = open(nname + ".cat")
        ntmp = filter(lambda line: pu.no_head(line), ncat)

        # Background measuresments can't overlap with source detections
        ssources = q.ScamPixelQuadtree(0, 0, 12000, 10000)
        map(lambda line: ssources.insert(S.SCAMSource(line)), stmp)
        nsources = map(lambda line: S.SCAMSource(line), ntmp)

        start = time.time()
        bkgddetections = disassociate(nsources, ssources, ap)
        end = time.time()
        print("ELAPSED TIME: " + str(end - start))
        srcdetections = map(lambda line: S.SCAMSource(line), stmp)

        flux = map(lambda f: f.flux_aper, bkgddetections)
        noise.append(pu.calc_MAD(flux))

        flux = map(lambda f: f.flux_aper, srcdetections)
        signal.append(pu.calc_MAD(flux))

        with open(image[-6] + "_ap_" + str(round(ap, 2)) + "noise.txt",
                  "w") as output:
            for source in bkgddetections:
                output.write(source.line)
        call([
            'mv', image[-6] + "_ap_" + str(round(ap, 2)) + "noise.txt",
            'BestApertureFiles'
        ])

        with open(image[-6] + "_ap_" + str(round(ap, 2)) + "signal.txt",
                  "w") as output:
            for source in srcdetections:
                output.write(source.line)
        call([
            'mv', image[-6] + "_ap_" + str(round(ap, 2)) + "signal.txt",
            'BestApertureFiles'
        ])
    '''
    The files generated here aren't important and need to be
    removed for the next steps to work properly.
    '''

    try:
        os.remove('measurefluxat.txt')
    except OSError:
        pass
    noise_files = (glob.glob('noise*'))
    try:
        for f in noise_files:
            os.remove(f)
    except OSError:
        pass
    sign_files = (glob.glob('sign*'))
    try:
        for f in sign_files:
            os.remove(f)
    except OSError:
        pass

    snr = []
    for i in range(len(noise)):
        snr.append(signal[i] / noise[i])
    plt.plot(aperture, snr, linestyle='none', marker='o')
    plt.xlabel('Aperture (pix)')
    plt.ylabel('SNR')
    pu.save(path, image[-6] + '_snr')
    maxsnr = snr.index(max(snr))
    return aperture[maxsnr]
Пример #28
0
def calcZP(galaxy, scam, band):
    """
    To calculate the zeropoint of the Subaru image match the Subaru catalog
    and the table returned from Vizier.
    """
    sdss = getSDSS(galaxy)

    column = str(band + 'mag')
    with open(scam, 'r') as catalog:
        tmp = filter(lambda line: phot_utils.no_head(line), catalog)
    # Do magnitude cute on data here
    tmp2 = map(lambda line: S.SCAMSource(line), tmp)
    mag = map(lambda s: s.mag_best, tmp2)
    max_mag = phot_utils.calc_average(mag) + 0.25 * phot_utils.calc_average(
        phot_utils.variance(mag))
    sources = filter(lambda s: phot_utils.mag_cut(s.mag_best, 0, max_mag),
                     tmp2)

    ra = map(lambda line: line.ra, tmp2)
    dec = map(lambda line: line.dec, tmp2)
    scam_sources = Q.ScamEquatorialQuadtree(min(ra), min(dec), max(ra),
                                            max(dec))
    map(lambda sources: scam_sources.insert(sources), sources)
    matches = associate(sdss, scam_sources)

    m_scam = map(lambda source: source.mag_aper, matches)
    m_sdss = map(lambda source: source.match2[column], matches)

    # Clip outliers of (m_sdss - m_scam)
    difference = []
    for i, entry in enumerate(m_scam):
        difference.append(m_sdss[i] - m_scam[i])
    std = np.std(difference)

    # Make a region file to check the matching
    with open("scam_match_source.reg", "w") as out:
        for source in matches:
            out.write("j2000; circle " + str(phot_utils.convertRA(source.ra)) +
                      "," + str(phot_utils.convertDEC(source.dec)) +
                      " .1' #color=red \n")

    with open("sdss_match_source.reg", "w") as out:
        for source in matches:
            out.write("j2000; circle " +
                      str(phot_utils.convertRA(source.match2['RAJ2000'])) +
                      "," +
                      str(phot_utils.convertDEC(source.match2['DEJ2000'])) +
                      " .15' #color=green \n")

    clipped = []
    for entry in matches:
        if entry.match2[column] - entry.mag_aper < std * 3:
            clipped.append(entry)

    difference = []
    for entry in clipped:
        difference.append(entry.match2[column] - entry.mag_aper)
    m_scam = map(lambda source: source.mag_aper, clipped)

    # Look at offsets
    plt.plot(difference, m_scam, linestyle='none', marker='o')
    plt.xlabel(r'$m_{SDSS}$ - $m_{SCAM}$', fontsize=20)
    plt.ylabel(r'$m_{SCAM}$', fontsize=20, labelpad=30)
    plt.show()

    # Take median of offset
    return phot_utils.calc_median(difference)
Пример #29
0

def associate(list1, tree2):
    dist = 5
    with open("test.reg", "w") as out:
        for entry in list1:
            match2 = tree2.match(entry.ximg, entry.yimg)
            if match2 != None and _norm.norm(entry.ximg, entry.yimg,
                                             match2.ximg, match2.yimg) <= dist:
                out.write("physical;circle(" + str(entry.ximg) + "," +
                          str(entry.yimg) + " 10) #color=red \n")


with open('NGC4621_i.cat', 'r') as f:
    i_catalog = [
        Sources.SCAMSource(line) for line in f if phot_utils.no_head(line)
    ]

with open('NGC4621_g.cat', 'r') as f:
    g_catalog = [
        Sources.SCAMSource(line) for line in f if phot_utils.no_head(line)
    ]

ximg = [source.ximg for source in i_catalog]
yimg = [source.yimg for source in i_catalog]
sources = Quadtree.ScamPixelQuadtree(min(ximg), min(yimg), max(ximg),
                                     max(yimg))

#ra = [source.ra for source in i_catalog]
#dec = [source.dec for source in i_catalog]
#sources = Quadtree.ScamEquatorialQuadtree(min(ra), min(dec), max(ra), max(dec))
Пример #30
0
# Copyright (c) 2012, Adam J. Rossi. All rights reserved. See README for licensing details.
import sys, os
sys.path.append(os.path.abspath("."))
import Chain  # Chain must be imported first, requirement of registry
import Sources, FeatureExtraction, FeatureMatch, BundleAdjustment, Cluster, Common

# path to images / PMVS
imagePath = os.path.abspath("../Datasets/ET")
pmvsPath = os.path.join(imagePath, "pmvs")

# build chain
imageSourceJpg = Sources.ImageSource(imagePath, "jpg")
imageSource = Sources.ImageConvert(imageSourceJpg, imagePath, "pgm")
asift = FeatureExtraction.ASIFT(imageSource)
keyMatch = FeatureMatch.ASIFTMatch(asift)
bundler = BundleAdjustment.Bundler([keyMatch, imageSource])
radialUndistort = Cluster.RadialUndistort([bundler, imageSourceJpg])
prepCmvsPmvs = Cluster.PrepCmvsPmvs(radialUndistort, pmvsPath)
cmvs = Cluster.CMVS(prepCmvsPmvs)
pmvs = Cluster.PMVS(cmvs)

# render chain
print Chain.Render(pmvs, "asift.txt")
    fd = FaceDetectorAll(show = show)
    if (webcam): #Using the webcam
        from utils import ImageCapturer
        cap = ImageCapturer.ImageCapturer()
        if not cap:
            print "Error opening capture device"
        else:
            print "successfully imported video capture"
        while True:
            rval, frame = cap.get_image()
            fd.processImage(frame)


    if (True):
        img_path = os.path.abspath('/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014')
        [y, block, names, filenames] = Sources.read_images_2(img_path, useBatch=2, maxNum=1500)

        w = None
        #import csv
        #w = csv.writer(open("../../data/" + 'batch2_46_gamma_dog.csv', 'w'))
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Oliver_2/Oliver-2-41.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Dejan_1/Dejan-1-1.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-3.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-31.png"
        d = "/Users/oli/Proj_Large_Data/PiVision/pivision/images/session_30_july_2014/Rebekka_2/Rebekka-2-5.png"

        fd.processImage(cv2.imread(d), 0, w)
        # cv2.imshow("Gallo ", img);
        # import matplotlib.pyplot as plt
        # plt.ion()
        # fig = plt.figure("Hello Convolutional World", figsize=(18, 12))