def load_rawfile(fn, existdb=None): # Connect to the database db = existdb or database.Database() db.connect() try: # Enter information in rawfiles table notify.print_info("Working on %s (%s)" % (fn, utils.give_utc_now()), 1) # Check the file and parse the header params = datafile.prep_file(fn) # Move the File destdir = datafile.get_archive_dir(fn, params=params) newfn = datafile.archive_file(fn, destdir) notify.print_info("%s moved to %s (%s)" % (fn, newfn, utils.give_utc_now()), 1) # Register the file into the database rawfile_id = populate_rawfiles_table(db, newfn, params) notify.print_info("Successfully loaded %s - rawfile_id=%d (%s)" % (fn, rawfile_id, utils.give_utc_now()), 1) finally: if not existdb: # Close DB connection db.close() return rawfile_id
def load_template(fn, comments, is_master=False, existdb=None): # Connect to the database db = existdb or database.Database() db.connect() try: # Now load the template file into database notify.print_info("Working on %s (%s)" % (fn, utils.give_utc_now()), 1) # Check the template and parse the header params = datafile.prep_file(fn) # Move the file destdir = datafile.get_archive_dir(fn, params=params) newfn = datafile.archive_file(fn, destdir) # Register the template into the database template_id = populate_templates_table(db, newfn, params, comments=comments) mastertemp_id, tempfn = general.get_master_template(params['pulsar_id'], params['obssystem_id']) if mastertemp_id is None: # If this is the only template for this pulsar # make sure it will be set as the master is_master = True if is_master: notify.print_info("Setting %s as master template (%s)" % (newfn, utils.give_utc_now()), 1) general.set_as_master_template(template_id, db) notify.print_info("Finished with %s - template_id=%d (%s)" % (fn, template_id, utils.give_utc_now()), 1) finally: if not existdb: # Close DB connection db.close() return template_id
def _compute(self): notify.print_info("Creating composite summary plot for %s" % self.fn, 3) handle, tmpfn = tempfile.mkstemp(suffix=".png") os.close(handle) params = datafile.prep_file(self.fn) if (params["nsub"] > 1) and (params["nchan"] > 1): self.__plot_all(tmpfn, params) elif (params["nsub"] > 1) and (params["nchan"] == 1): self.__plot_nofreq(tmpfn, params) elif (params["nsub"] == 1) and (params["nchan"] > 1): self.__plot_notime(tmpfn, params) elif (params["nsub"] == 1) and (params["nchan"] == 1): self.__plot_profonly(tmpfn, params) else: raise errors.FileError( "Not sure how to plot diagnostic for file. " "(nsub: %d; nchan: %d)" % (params["nsub"], params["nchan"]) ) tmpdir = os.path.split(tmpfn)[0] archivefn = os.path.split(self.fn)[-1] pngfn = os.path.join(tmpdir, archivefn + ".composite.png") shutil.move(tmpfn, pngfn) return pngfn
def make_proc_diagnostics_dir(fn, proc_id): """Given an archive, create the appropriate diagnostics directory, and cross-references. Inputs: fn: The file to create a diagnostic directory for. proc_id: The processing ID number to create a diagnostic directory for. Outputs: diagdir: The diagnostic directory's name. """ diagnostics_location = os.path.join(config.cfg.data_archive_location, "diagnostics") params = datafile.prep_file(fn) basedir = datafile.get_archive_dir(fn, params=params, data_archive_location=diagnostics_location) diagdir = os.path.join(basedir, "procid_%d" % proc_id) # Make sure directory exists if not os.path.isdir(diagdir): # Create directory notify.print_info("Making diagnostic directory: %s" % diagdir, 2) os.makedirs(diagdir, 0770) crossrefdir = os.path.join(diagnostics_location, "processing") if not os.path.isdir(crossrefdir): # Create directory notify.print_info("Making diagnostic crossref diagdir: %s" % crossrefdir, 2) os.makedirs(crossrefdir, 0770) crossref = os.path.join(crossrefdir, "procid_%d" % proc_id) if not os.path.islink(crossref): # Create symlink notify.print_info("Making crossref to diagnostic diagdir: %s" % crossref, 2) os.symlink(diagdir, crossref) return diagdir