def prepare_subints(subdirs, subints, baseoutdir, trimpcnt=6.25, effix=False, backend=None): """Prepare subints by - Copying them to the temporary working directory - De-weighting a percentage from each sub-band edge - Converting archive format to PSRFITS Inputs: subdirs: List of sub-band directories containing sub-ints to combine subints: List of subint files to be combined. (NOTE: These are the file name only (i.e. no path) Each file listed should appear in each of the subdirs.) baseoutdir: Directory containing the sub-directories of preprared files. trimpcnt: Percentage (ie between 0-100) of subband to trim from _each_ edge of the band. (Default: 6.25%) effix: Change observation site to eff_psrix to correct for asterix clock offsets. (Default: False) backend: Name of the backend. (Default: leave as is) Outputs: prepsubdirs: The sub-directories containing prepared files. """ devnull = open(os.devnull) tmpsubdirs = [] for subdir in utils.show_progress(subdirs, width=50): freqdir = os.path.split(os.path.abspath(subdir))[-1] freqdir = os.path.join(baseoutdir, freqdir) try: os.makedirs(freqdir) except OSError: # Directory already exists pass fns = [os.path.join(subdir, fn) for fn in subints] preproc = 'convert psrfits' if effix: preproc += ',edit site=eff_psrix' if backend: if ("," in backend) or ("=" in backend) or (' ' in backend): raise errors.UnrecognizedValueError("Backend value (%s) is " "invalid. It cannot " "contain ',' or '=' or " "' '" % backend) preproc += ',edit be:name=%s' % backend utils.execute( ['paz', '-j', preproc, '-E', '%f' % trimpcnt, '-O', freqdir] + fns, stderr=devnull) tmpsubdirs.append(freqdir) utils.print_info( "Prepared %d subint fragments in %d freq sub-dirs" % (len(subints), len(subdirs)), 3) return tmpsubdirs
def set_file_as_bad(self, reason='rfi'): if self.file_id: note = "File failed quality control." if reason == 'rfi': note += " RFI has rendered the observation unsalvageable!" elif reason == 'nondetect': note += " The observation is a non-detection." else: raise errors.UnrecognizedValueError("The reason for " "setting the file as " "bad is not " "recognized: %s" % reason) with self.db.transaction() as conn: now = datetime.datetime.now() update = self.db.files.update().\ where(self.db.files.c.file_id == self.file_id).\ values(qcpassed=False, status='failed', note=note, last_modified=now) conn.execute(update) insert = self.db.qctrl.insert().\ values(file_id=self.file_id, obs_id=self.fileinfo['obs_id'], user=os.getlogin(), qcpassed=False, note=note, added=now, last_modified=now) conn.execute(insert) if self.fileinfo['stage'] == 'calibrated': # Mark former cleaned file to be loaded ancestors = reduce_data.get_all_ancestors(self.file_id, self.db) for ancestor in ancestors: if ancestor['stage'] == 'cleaned': ancestor_file_id = ancestor['file_id'] break update = self.db.files.update().\ where((self.db.files.c.file_id == ancestor_file_id)).\ values(status='toload', note="Derived calibrated file failed quality control.", last_modified=datetime.datetime.now()) conn.execute(update) # Update observation's current file update = self.db.obs.update().\ where((self.db.obs.c.obs_id == self.fileinfo['obs_id'])).\ values(current_file_id=ancestor_file_id, last_modified=datetime.datetime.now()) conn.execute(update) self.advance_file()
def load_cleaner(cleaner_name): """Import a cleaner class and return an instance. Input: cleaner_name: The name of the cleaner. Output: clean: A cleaner instance. """ if cleaner_name not in registered_cleaners: raise errors.UnrecognizedValueError('The cleaner, %s, ' \ 'is not a registered cleaner. The following ' \ 're registered: %s' % \ (cleaner_name, "', '".join(registered_cleaners))) mod = __import__(cleaner_name, globals()) return mod.Cleaner()
def load_cleaner(cleaner_name): """Import a cleaner class and return an instance. Input: cleaner_name: The name of the cleaner. Output: clean: A cleaner instance. """ if cleaner_name not in registered_cleaners: raise errors.UnrecognizedValueError('The cleaner, %s, ' \ 'is not a registered cleaner. The following ' \ 're registered: %s' % \ (cleaner_name, "', '".join(registered_cleaners))) mod = importlib.import_module('.'+cleaner_name, 'coast_guard.cleaners') return mod.Cleaner()
def load_cleaner(cleaner_name): """Import a cleaner class and return an instance. Input: cleaner_name: The name of the cleaner. Output: clean: A cleaner instance. """ if cleaner_name not in registered_cleaners: raise errors.UnrecognizedValueError('The cleaner, %s, ' \ 'is not a registered cleaner. The following ' \ 're registered: %s' % \ (cleaner_name, "', '".join(registered_cleaners))) mod = __import__("coast_guard.cleaners.{0}".format(cleaner_name), fromlist=["None"]) return mod.Cleaner()