예제 #1
0
    def fit_all(self,save_output=True,clobber=False,minmatch=20,mymatches=[], \
                sigma_reject=5.0,verbose=True):
        """
        runs through all the match files and fits the astrometry
        
        clobber -- overwrite output file if it exists
        save_output -- save the output file
        minmatch  -- minimum number of required matches to perform the mapping
        mymatches -- list of files to match (instead of what gets populated in prepare)
        sigma_reject -- rejection of outliers [not used for now!]
        """
        if mymatches != []:
            matches = mymatches
        else:
            matches = self.a.generated_match_files

        self.pybast_files = []

        for fname, nmatch, t in matches:

            if nmatch < minmatch:
                print "skipping %s ... too few matches [%i]" % (fname, nmatch)
                continue

            print "*" * 60
            print "Working on %s" % (fname, )
            sys.stdout.flush()

            outname = "".join(fname.split(".")[0:-1]) + ".pyBAST"

            if not clobber and os.path.exists(outname):
                print " ... skipping (mapping file exists)"
                self.pybast_files.append((outname, fname, t))
                continue

            data = sdss.csv2rec(fname)
            # Parse data array into objects
            # the A objects will be the fiducial positions from the deep coadd
            # the B objects will be source positions in this epoch
            # both are given in arcseconds relative to a fiducial center
            objectsA = np.array( [ pyBA.Bivarg(mu=[x["master_dra"],x["master_ddec"]],\
                                   sigma=np.array([x["master_raerr"],x["master_decerr"]])) \
                                   for x in data ] )
            objectsB = np.array( [ pyBA.Bivarg(mu=[x["dra"],x["ddec"]], \
                                   sigma=np.array([x["raerr"],x["decerr"]])) \
                                   for x in data ] )

            # Suggest starting point for background mapping
            S = pyBA.background.suggest_mapping(objectsA, objectsB)

            # Get maximum a posteriori background mapping parameters
            P = pyBA.background.MAP(objectsA,
                                    objectsB,
                                    mu0=S.mu,
                                    prior=pyBA.Bgmap(),
                                    norm_approx=True)
            D = pyBA.Amap(P, objectsA, objectsB)
            if verbose:
                print " ... conditioning"
                sys.stdout.flush()
            D.condition()
            if verbose:
                print D.hyperparams

            if save_output:
                if clobber and os.path.exists(outname):
                    os.remove(outname)

                output = open(outname, 'wb')
                pickle.dump(D, output, protocol=-1)
                if verbose:
                    print "   ... wrote %s" % outname
                self.pybast_files.append((outname, fname, t))
예제 #2
0
파일: wd.py 프로젝트: berianjames/pyBAST
    def fit_all(self,save_output=True,clobber=False,minmatch=20,mymatches=[], \
                sigma_reject=5.0,verbose=True):
        """
        runs through all the match files and fits the astrometry
        
        clobber -- overwrite output file if it exists
        save_output -- save the output file
        minmatch  -- minimum number of required matches to perform the mapping
        mymatches -- list of files to match (instead of what gets populated in prepare)
        sigma_reject -- rejection of outliers [not used for now!]
        """
        if mymatches != []:
            matches = mymatches
        else:
            matches = self.a.generated_match_files
        
        self.pybast_files = []
        
        for fname,nmatch,t in matches:
            
            if nmatch < minmatch:
                print "skipping %s ... too few matches [%i]" % (fname,nmatch)
                continue
            
            print "*"*60
            print "Working on %s" % (fname,)
            sys.stdout.flush() 
            
            outname = "".join(fname.split(".")[0:-1]) + ".pyBAST"
            
            if not clobber and os.path.exists(outname):
                print " ... skipping (mapping file exists)"
                self.pybast_files.append((outname,fname,t))    
                continue
                
            data = sdss.csv2rec(fname)
            # Parse data array into objects
            # the A objects will be the fiducial positions from the deep coadd
            # the B objects will be source positions in this epoch
            # both are given in arcseconds relative to a fiducial center
            objectsA = np.array( [ pyBA.Bivarg(mu=[x["master_dra"],x["master_ddec"]],\
                                   sigma=np.array([x["master_raerr"],x["master_decerr"]])) \
                                   for x in data ] )
            objectsB = np.array( [ pyBA.Bivarg(mu=[x["dra"],x["ddec"]], \
                                   sigma=np.array([x["raerr"],x["decerr"]])) \
                                   for x in data ] )
            
            # Suggest starting point for background mapping
            S = pyBA.background.suggest_mapping(objectsA,objectsB)

            # Get maximum a posteriori background mapping parameters
            P = pyBA.background.MAP( objectsA, objectsB, mu0=S.mu, prior=pyBA.Bgmap(), norm_approx=True )
            D = pyBA.Amap(P,objectsA, objectsB)
            if verbose:
                print " ... conditioning"
                sys.stdout.flush()
            D.condition()
            if verbose:
                print D.hyperparams
                                   
            if save_output:
                if clobber and os.path.exists(outname):
                    os.remove(outname)
                
                output = open(outname, 'wb')
                pickle.dump(D, output, protocol=-1)
                if verbose:
                    print "   ... wrote %s" % outname
                self.pybast_files.append((outname,fname,t))
예제 #3
0
파일: sdss_demo.py 프로젝트: stefanv/pyBAST
# Demo script to analyse data from Stripe 82
#
# This is minimal version of the procedure carried out in the
#  corresponding notebook (sdss_demo.ipynb).

import pyBA
import sdss
import numpy as np

np.set_printoptions(linewidth=125, suppress=True, precision=3)

# Load data
data = sdss.csv2rec("match_astrom_342.1914_-0.90194_run4198.dat")
nties = len(data)
print nties

# Parse data array into objects
# the A objects will be the fiducial positions from the deep coadd
# the B objects will be source positions in this epoch
# both are given in arcseconds relative to a fiducial center
objectsA = np.array([
    pyBA.Bivarg(mu=[x["master_dra"], x["master_ddec"]],
                sigma=np.array([x["master_raerr"], x["master_decerr"]]))
    for x in data
])
objectsB = np.array([
    pyBA.Bivarg(mu=[x["dra"], x["ddec"]],
                sigma=np.array([x["raerr"], x["decerr"]])) for x in data
])

# Suggest starting point for background mapping
예제 #4
0
# Demo script to analyse data from Stripe 82
#
# This is minimal version of the procedure carried out in the
#  corresponding notebook (sdss_demo.ipynb).

import pyBA
import sdss
import numpy as np

np.set_printoptions(linewidth=125,suppress=True,precision=3)

# Load data
data = sdss.csv2rec("match_astrom_342.1914_-0.90194_run4198.dat")
nties = len(data)
print nties

# Parse data array into objects
# the A objects will be the fiducial positions from the deep coadd
# the B objects will be source positions in this epoch
# both are given in arcseconds relative to a fiducial center
objectsA = np.array( [ pyBA.Bivarg(mu=[x["master_dra"],x["master_ddec"]],sigma=np.array([x["master_raerr"],x["master_decerr"]])) for x in data ] )
objectsB = np.array( [ pyBA.Bivarg(mu=[x["dra"],x["ddec"]], sigma=np.array([x["raerr"],x["decerr"]])) for x in data ] )

# Suggest starting point for background mapping
S = pyBA.background.suggest_mapping(objectsA,objectsB)

# Get maximum a posteriori background mapping parameters
P = pyBA.background.MAP( objectsA, objectsB, mu0=S.mu, prior=pyBA.Bgmap(), norm_approx=True )
print P.mu

pass