def __call__(self, parser, namespace, values, option_string): colour.cprint("Available Cleaners:", \ bold=True, underline=True) for name in sorted(cleaners.registered_cleaners): cleaner = cleaners.load_cleaner(name) print cleaner.get_help() sys.exit(1)
def __call__(self, parser, namespace, values, option_string): if values is None: parser.print_help() else: cleaner = cleaners.load_cleaner(values) print cleaner.get_help(full=True) sys.exit(1)
def apply_bandwagon_cleaner(ar, badchantol=0.8, badsubtol=0.8): print("Applying the bandwagon cleaner") print("\t channel threshold = {0}".format(badchantol)) print("\t subint threshold = {0}".format(badsubtol)) bandwagon_cleaner = cleaners.load_cleaner('bandwagon') bandwagon_parameters = "badchantol={0},badsubtol={1}".format( badchantol, badsubtol) bandwagon_cleaner.parse_config_string(bandwagon_parameters) bandwagon_cleaner.run(ar)
def apply_surgical_cleaner(ar, tmp, cthresh=5.0, sthresh=5.0, plot=False): print("Applying the surgical cleaner") print("\t channel threshold = {0}".format(cthresh)) print("\t subint threshold = {0}".format(sthresh)) surgical_cleaner = cleaners.load_cleaner('surgical') surgical_parameters = "chan_numpieces=1,subint_numpieces=1,chanthresh={1},subintthresh={2},template={0},plot={3}".format( tmp, cthresh, sthresh, plot) surgical_cleaner.parse_config_string(surgical_parameters) surgical_cleaner.run(ar)
def clean_archive(archive, template=None, bandwagon=0.99, channel_threshold=7, subint_threshold=5, output_directory=None): """ Cleans an archive using coast_guard """ # import necessary modules import psrchive as ps from coast_guard import cleaners # Load the archive archive = ps.Archive_load(str(archive)) archive_path, archive_name = os.path.split(archive.get_filename()) archive_name = archive_name.split('.')[0] if output_directory is None: output_directory = archive_path # Clean the archive with surgical cleaner print("Applying surgical cleaner") surgical_cleaner = cleaners.load_cleaner('surgical') surgical_parameters = 'chan_numpieces=1,subint_numpieces=1,\ chanthresh={},subintthresh={}'.format( channel_threshold, subint_threshold) surgical_cleaner.parse_config_string(surgical_parameters) surgical_cleaner.run(archive) # Apply bandwagon cleaner cleaner print("Applying bandwagon cleaner") bandwagon_cleaner = cleaners.load_cleaner('bandwagon') bandwagon_parameters = 'badchantol={},badsubtol=1.0'.format(bandwagon) bandwagon_cleaner.parse_config_string(bandwagon_parameters) bandwagon_cleaner.run(archive) # Unload cleaned archive unload_path = os.path.join(output_directory, archive_name + ".clean") print('Unloading cleaned archive as {0}'.format(unload_path)) archive.unload(unload_path) return
def run_coastguard(calname, cal_dz): #calname = sys.argv[1] #cal_dz = sys.argv[2] print calname inarf = utils.ArchiveFile(calname) config.cfg.load_configs_for_archive(inarf) outfn = utils.get_outfn(cal_dz, inarf) shutil.copy(inarf.fn, outfn) outarf = utils.ArchiveFile(outfn) ar = outarf.get_archive() cleaner = cleaners.load_cleaner('preclean') # hard coded, need to be fixed #for cfgstr in cfgstrs: # cleaner.parse_config_string(cfgstr) cleaner.run(ar) cleaner = cleaners.load_cleaner('surgical') # hard coded, need to be fixed cleaner.run(ar) print(type(outfn)) ar.unload(str(outfn)) print "Cleaned archive: %s" % outfn
def main(): print "" print " clean.py" print " Patrick Lazarus" print "" file_list = args.files + args.from_glob to_exclude = args.excluded_files + args.excluded_by_glob to_clean = utils.exclude_files(file_list, to_exclude) print "Number of input files: %d" % len(to_clean) # Read configurations for infn in to_clean: inarf = utils.ArchiveFile(infn) config.cfg.load_configs_for_archive(inarf) outfn = utils.get_outfn(args.outfn, inarf) shutil.copy(inarf.fn, outfn) outarf = utils.ArchiveFile(outfn) ar = outarf.get_archive() try: for name, cfgstrs in args.cleaner_queue: # Set up the cleaner cleaner = cleaners.load_cleaner(name) for cfgstr in cfgstrs: cleaner.parse_config_string(cfgstr) cleaner.run(ar) except: # An error prevented cleaning from being successful # Remove the output file because it may confuse the user #if os.path.exists(outfn): # os.remove(outfn) raise finally: ar.unload(outfn) print "Cleaned archive: %s" % outfn
print "nsubint Number of sub-integrations %s" % nSubint print "type Observation type %s" % obsType print "site Telescope name %s" % telescopeName print "name Source name %s" % sourceName print "coord Source coordinates %s%s" % (RA.getHMS(), Dec.getDMS()) print "freq Centre frequency (MHz) %s" % centreFrequency print "bw Bandwidth (MHz) %s" % bandwidth print "dm Dispersion measure (pc/cm^3) %s" % DM print "rm Rotation measure (rad/m^2) %s" % RM print "dmc Dispersion corrected %s" % isDedispersed print "rmc Faraday Rotation corrected %s" % isFaradayRotated print "polc Polarization calibrated %s" % isPolCalib print "scale Data units %s" % dataUnits print "state Data state %s" % dataState print "length Observation duration (s) %s" % obsDuration print "rcvr:name Receiver name %s" % receiverName print "rcvr:basis Basis of receptors %s" % receptorBasis print "be:name Name of the backend instrument %s" % backendName cleanRFI = archive.clone() cleaner = cleaners.load_cleaner("surgical") cleaner.parse_config_string("chan_numpieces=1,subint_numpieces=1,chanthresh=3,subintthresh=3") cleaner.run(cleanRFI) name=os.path.splitext(file)[0]+'.clean' print "Writing to %s" %name cleanRFI.unload(name)