Ejemplo n.º 1
0
def getUnprocessedFlatFn(root):
    logger = logging.getLogger(__name__)
    fileContents = fs.readFileToArray(root + ".flats")
    filenames = []
    proc = fs.readFileToArray(root + ".proc")
    
    for fn in fileContents:
        if fn not in proc:
            filenames.append(fn)
    filenames.sort()
    return filenames
Ejemplo n.º 2
0
def getUnprocessedImageNames(root):
    logger = logging.getLogger(__name__)
    fileContents = fs.readFileToArray(root + ".lights")
    fileContents = [f.split(":")[0] for f in fileContents]
    filenames = []
    proc = fs.readFileToArray(root + ".proc")
    
    for fn in fileContents:
        if fn not in proc:
            filenames.append(fn)
    filenames.sort()
    return [f.split(":")[0] for f in filenames]
Ejemplo n.º 3
0
def isInField(fn, ra, dec):
    wcsList = [i.split(" ") for i in fs.readFileToArray(fn + ".center")]
    wcsDict = {}
    for key, value in wcsList:
        wcsDict[key] = value

    return areEqual(ra, wcsDict["ra_center"], 0.166) and areEqual(dec, wcsDict["dec_center"], 0.166)
Ejemplo n.º 4
0
def getExoplanetList():
    exoplanetListFn = "/home/astron/bin/atlas/exoplanetList"
    exoList = [i.split(",") for i in fs.readFileToArray(exoplanetListFn)]
    exoDic = []
    for line in exoList:
        dic = {}
        dic["name"] = line[0]
        dic["ra"] = line[1]
        dic["dec"] = line[2]
        exoDic.append(dic)
    return exoDic
Ejemplo n.º 5
0
def indexFiles(root):
    logger = logging.getLogger(__name__)
    logger.debug("Looking for all *.fit* in " + root)
    fitsFiles = [os.path.relpath(os.path.join(dirpath, f), root)
            for dirpath, dirnames, files in os.walk(root)
            for f in fnmatch.filter(files, "*.fit")]
    fitsFiles.sort()
    #print(fitsFiles)
 
    listDarks = fs.readFileToArray(root + ".darks")
    listBiass = fs.readFileToArray(root + ".biass")
    listFlats = fs.readFileToArray(root + ".flats")
    listLights = fs.readFileToArray(root + ".lights")
    listUnknowns = fs.readFileToArray(root + ".unknowns")
    listErrors = fs.readFileToArray(root + ".errors")
    index = fs.readFileToArray(root + ".index")

    for f in fitsFiles:
        if f in index:
            continue
        if "b.fit" in f or "d.fit" in f or "atlas_" in f:
            continue
        logger.debug("Indexing "+f)
        hdr = fs.getHeader(root + f)
        imgType = hdr["PICTTYPE"]
        outFile = "None"
        date = hdr["DATE-OBS"].split("T")[0]
        if isFlat(imgType):
            #logger.debug(f + " is a flat.")
            listFlats.append(f)
        elif isDark(imgType):
            #logger.debug(f + " is a dark")
            listDarks.append(f)
        elif isBias(imgType):
            #logger.debug(f + " is a bias")
            listBiass.append(f)
        elif isLight(imgType):
            #logger.debug(f + " is a light frame!")
            listLights.append(f + ":" + date)
        elif isUnknown(imgType):
            logger.warning(f + " is of unknown type?")
            listUnknowns.append(f)
        else:
            logger.error("ImgType not unknown or anything else??")
            listErrors.append(f)
        #TODO only open file once in w+ mode
        index.append(f)
    fs.writeListToFile(root+".flats", listFlats)
    fs.writeListToFile(root+".darks", listDarks)
    fs.writeListToFile(root+".biass", listBiass)
    fs.writeListToFile(root+".lights", listLights)
    fs.writeListToFile(root+".unknowns", listUnknowns)
    fs.writeListToFile(root+".errors", listErrors)
    fs.writeListToFile(root+".index", index)
    return
Ejemplo n.º 6
0
def getFlats(root, imgName):
    logger = logging.getLogger(__name__)
    hdr = fs.getHeader(root + imgName)
    dateObs = hdr["DATE-OBS"].split("T")
    flatList = []

    logger.debug("Looking for flats from date: " + dateObs[0])
    flats = fs.readFileToArray(root + ".flats")
    flatsList = []
    for flat in flats:
        flatHdr = fs.getHeader(root + flat)
        match = True
        if dateObs[0] not in flatHdr["DATE-OBS"]:
            match = False
        if match:
            #logger.debug("Found flat, matches with  " + flat)
            flatsList.append(flat)
    return flatsList
Ejemplo n.º 7
0
def getBiass(root, imgName):
    logger = logging.getLogger(__name__)
    hdr = fs.getHeader(root + imgName)
    dateObs = hdr["DATE-OBS"].split("T")
    biasList = []

    logger.debug("Looking for biass from date: " + dateObs[0])
    biass = fs.readFileToArray(root + ".biass")
    biassList = []
    for bias in biass:
        biasHdr = fs.getHeader(root + bias)
        match = True
        if dateObs[0] not in biasHdr["DATE-OBS"]:
            match = False
        if match:
            #logger.debug("Found bias, matches with  " + bias)
            biasList.append(bias)
    return biasList
Ejemplo n.º 8
0
def getDarks(root, imgName):
    logger = logging.getLogger(__name__)
    #hdu_list = pyfits.open(root + imgName)
    #hdr = hdu_list[0].header
    hdr = fs.getHeader(root + imgName)
    #expTime = hdr["EXPTIME"]
    dateObs = hdr["DATE-OBS"].split("T")
    darkList = []

    logger.debug("Looking for darks from date: " + dateObs[0]) 
    darks = fs.readFileToArray(root + ".darks")
    darkList = []
    for dark in darks:
        darkHdr = fs.getHeader(root + dark)
        match = True
        #if darkHdr["EXPTIME"] != expTime:
            #match = False
        if dateObs[0] not in darkHdr["DATE-OBS"]:
            match = False
        if match:
            #logger.debug("Found dark, matches with  " + dark)
            darkList.append(dark)

    return darkList
Ejemplo n.º 9
0
    logger.info("Indexing " + root)
    indexFiles(root)

    logger.info("Getting unprocessed images")
    unprocImgNames = getUnprocessedImageNames(root)
    if not unprocImgNames or len(unprocImgNames) == 0:
        logger.info("No unprocessed images.")
        #TODO stop the program?
    unprocImgNames.sort()

    logger.info("Processing " + str(len(unprocImgNames)) + " images")
    biassFiles = {}
    darksFiles = {}
    flatsFiles = {}
    procFiles = fs.readFileToArray(root + ".proc")

    for img in unprocImgNames:
        logger.debug("Getting calibration images for " + img)
        hdr = fs.getHeader(root + img)
        exptime = hdr['EXPTIME']
        date = hdr['DATE-OBS'].split('T')
        date = date[0]
        datexp = date + ":" + str(exptime)
        #Darks
        if date in darksFiles:
            darksFiles[date].append(img)
        else:
            darks = getDarks(root, img)
            darksFiles[date] = [img]
            if len(darks) > 0:
Ejemplo n.º 10
0
    logger = logging.getLogger(__name__)
    root = sys.argv[1] + "/"
    resFnList = [os.path.relpath(os.path.join(dirpath, f), root)
                    for dirpath, dirnames, files in os.walk(root)
                        for f in fnmatch.filter(files, "*.res")]
    resFnList.sort()

    dest = root + "graph/"
    if not os.path.exists(dest):
        os.makedirs(dest)

    for fn in resFnList:
        logger.info("Working on " + fn)

        #Parsing .res, the format is ID DATA DATA ... APP APP... TIME
        array = fs.readFileToArray(root + fn)
        split = [i.split()[:-1] for i in array]
        times = [i.split()[-1] for i in array]
        appertures = split[0][int((len(split[0])+1) / 2):]
        data = [[], []]

        #This creates an array in the format data[star][field][exp]
        #TODO try to optimize it for rapid memory?
        for line in split:
            app = line[1:int((len(line)+1)/2)]
            starId = int(line[0])
            if len(data) <= starId:
                data.append([app])
            else:
                data[starId].append(app)