solarSystemObject = False galactic = True calculateRaDec = False showMapsAfterTasks = False debug = False deglitch = True nSigmaDeglitch = 3 print " Processing the following tile: " + str(tile) """ Load the tile scans and cross scans """ fitsFile = dataDir + "smc-scan-tile" + str(tile) + "-" + cameraName + ".fits" scans = FitsArchive().load(fitsFile) fitsFile = dataDir + "smc-cscan-tile" + str(tile) + "-" + cameraName + ".fits" cscans = FitsArchive().load(fitsFile) """ Subtract the baseline of every scanleg in every pixel """ print " Initial baseline subtraction / per scanleg " scans = scanamorphosScanlegBaselineFitPerPixel(scans, nSigma=2) cscans = scanamorphosScanlegBaselineFitPerPixel(cscans, nSigma=2) if(showMapsAfterTasks): map, mi = photProject(scans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Scans after baseline subtraction / per scanleg") map, mi = photProject(cscans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Cross scans after baseline subtraction / per scanleg") """ Create the source mask. Modify nSigma until you get an optimal mask. The mask should cover only a small fraction of the map (<~30%). It's not necessary that all the faint emission is masked, only the brightest regions. """ print " Creating a source mask " scans.join(cscans) del(cscans) sourceImage, scans = scanamorphosCreateSourceMask(scans, nSigma=4.0, createMask=False, galactic=galactic, calTree=calTree, debug=debug) if(showMapsAfterTasks): d = Display(sourceImage, title="Masked sources") """ Replace the scans and cross scans by the saved ones """ print " Loading the saved scans and cross scans from the temporal pool " del(scans) fitsFile = dataDir + "smc-scan-tile" + str(tile) + "-" + cameraName + ".fits" scans = FitsArchive().load(fitsFile) fitsFile = dataDir + "smc-cscan-tile" + str(tile) + "-" + cameraName + ".fits" cscans = FitsArchive().load(fitsFile) """ Add the mask to the saved scans and cross scans """ print " Adding the source mask to the scans and cross scans " maskImage, scans = scanamorphosCreateSourceMask(scans, inputImage=sourceImage, createMask=True, calTree=calTree, debug=debug) maskImage, cscans = scanamorphosCreateSourceMask(cscans, inputImage=sourceImage, createMask=True, calTree=calTree, debug=debug) """ Align the frames to have the same background and create the no-ovelap mask """ print " Aligning the scans and cross scans background reference " scans, cscans = scanamorphosAlignFrames(scans, cscans, calTree=calTree) scans.setActive("Scanamorphos_NonOverlapMask", True) cscans.setActive("Scanamorphos_NonOverlapMask", True) """ Baseline subtraction. Here we use galactic=True, because we only want to remove an offset """ #print " Baseline subtraction " #scans = scanamorphosBaselineSubtraction(scans, galactic=True, debug=debug) #cscans = scanamorphosBaselineSubtraction(cscans, galactic=True, debug=debug) #if(showMapsAfterTasks): # map, mi = photProject(scans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) # d = Display(map, title="Scans after baseline subtraction") # map, mi = photProject(cscans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) # d = Display(map, title="Cross scans after baseline subtraction") """ Baseline pre-processing """ #print " Baseline pre-processing " #scans = scanamorphosBaselinePreprocessing(scans, debug=debug) #cscans = scanamorphosBaselinePreprocessing(cscans, debug=debug) #if(showMapsAfterTasks): # map, mi = photProject(scans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) # d = Display(map, title="Scans after baseline pre-processing") # map, mi = photProject(cscans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) # d = Display(map, title="Cross scans after baseline pre-processing") """ Baseline subtraction """ print " Baseline subtraction " scans = scanamorphosBaselineSubtraction(scans, galactic=galactic, debug=debug) cscans = scanamorphosBaselineSubtraction(cscans, galactic=galactic, debug=debug) if(showMapsAfterTasks): map, mi = photProject(scans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Scans after baseline subtraction") map, mi = photProject(cscans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Cross scans after baseline subtraction") """ Destriping """ print " Destriping " scans, cscans = scanamorphosDestriping(scans, cscans, iterations=6, calTree=calTree, debug=debug) if(showMapsAfterTasks): map, mi = photProject(scans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Scans after destriping") map, mi = photProject(cscans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Cross scans after destriping") """ Align the frames to have the same background and create the no-ovelap mask """ #print " Aligning the scans and cross scans background reference " #scans, cscans = scanamorphosAlignFrames(scans, cscans, calTree=calTree) """ Merge the scans and cross scans """ print " Merging scans and cross scans in a frame product " System.gc() mergedScans = scans mergedScans.join(cscans) del(scans, cscans) System.gc() """ Deglitch the merged scans We use nSigma=5, and not a lower value, to avoid masking signal with strong drifts that will be corrected by the scanamorphosIndividualDrifts task """ print " Deglitching the merged scans " scanamorphosDeglitch(mergedScans, nSigma=5, calTree=calTree, debug=debug) """ Remove individual drifts """ print " Removing individual drifts " mergedScans = scanamorphosIndividualDrifts(mergedScans, calTree=calTree, debug=debug) if(showMapsAfterTasks): map, mi = photProject(mergedScans, pixfrac=0, calTree=calTree, useMasterMaskForWcs=False) d = Display(map, title="Merged scans after individual drifts correction") """ Deglitch the merged scans again with the user provided nSigmaDeglitch Be careful setting nSigmaDeglitch to very small values, because it can mask bright sources. You should always check the mask called Scanamorphos_GlitchMask to make sure that the task is masking only real glitches. """ if(deglitch): print " Deglitching the merged scans " scanamorphosDeglitch(mergedScans, nSigma=nSigmaDeglitch, calTree=calTree, debug=debug) """ Write the fits files """ outputFitsFile = dataDir + "smc-mergedScans-tile" + str(tile) + "-" + cameraName + ".fits" FitsArchive().save(outputFitsFile, mergedScans) del(mergedScans) System.gc()