def test_run_parallel(tmpdir): os.chdir(str(tmpdir)) pyfant.copy_star(pyfant.get_pfant_data_path('arcturus')) pyfant.link_to_data(pyfant.get_pfant_data_path("common")) cc = [] c = pyfant.Combo() c.conf.flag_output_to_dir = True cc.append(c) c = pyfant.Combo() c.conf.flag_output_to_dir = True cc.append(c) pyfant.run_parallel(cc, flag_console=False)
def el_multirun(elm): #separating each line from atom data atomtrim = pf.FileAtoms() atomtrim.load(atomdata) atomtrim.cut(mainfile.llzero, mainfile.llfin) atomel = pf.FileAtoms() atomel.atoms = [a for a in atomtrim.atoms if a.elem == pf.adjust_atomic_symbol(elm)] speclines = [] line_num_specs = [] #configuring multi-running for each line el_combos = [] for atom in atomel.atoms: for line in atom.lines: singline = pf.FileAtoms() a = copy.copy(atom) a.lines = [line] singline.atoms = [a] cm = pf.Combo([pf.FOR_PFANT, pf.FOR_NULBAD]) cm.conf.flag_output_to_dir = True cm.conf.flag_log_console = False cm.conf.opt.no_molecules = True cm.conf.opt.absoru = True cm.conf.opt.opa = False cm.conf.file_main = mainfile cm.conf.file_abonds = abondsfile cm.conf.file_atoms = singline cm.conf.file_main = mainfile cm.conf.opt.fn_cv = cm.conf.file_main.flprefix + ".norm.nulbad.%5.3f" % mainfile.fwhm el_combos.append(cm) #run pfant-multi pf.run_parallel(el_combos, flag_console=False) #load results and save spectra into lists i = 0 for atom in atomel.atoms: for line in atom.lines: pl = el_combos[i].pfant n = el_combos[i].nulbad n.load_result() n.convolved.filename = str(line.lambda_) speclines.append(n.convolved) lbdfluxpec = [n.convolved.x, n.convolved.y] line_num_specs.append(lbdfluxpec) pl.conf.sid.clean() i += 1 return speclines, line_num_specs
def get_combo(): c = pyfant.Combo(["pfant", "nulbad"]) if os.path.isfile(pyfant.FileOptions.default_filename): opt = pyfant.FileOptions() opt.load() c.conf.opt = opt c.conf.opt.no_h = True c.conf.opt.no_atoms = True c.conf.opt.allow = True c.conf.opt.fwhm = 0.14 return c
def __submit_job(self): import pyfant as pf r = pyfant.Combo() if self.checkbox_custom_id.isChecked(): custom_id = self.__get_custom_session_id() r.conf.sid.id = custom_id if _get_custom_dirname(custom_id) == custom_id: # Understands that session dirname prefix must be cleared r.sid.id_maker.session_prefix_singular = "" r.conf.opt = copy.copy(self.oe.f) r.conf.file_main = self.me.f r.conf.file_abonds = self.ae.f r.conf.file_dissoc = self.ae.f.get_file_dissoc() r.conf.flag_output_to_dir = True self._rm.add_runnables([r])
a99.logging_level = logging.INFO a99.flag_log_file = True if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__, formatter_class=a99.SmartFormatter) names = pyfant.Conf().opt.get_names() # option names for name in names: # name = name.replace('_', '-') parser.add_argument("--" + name, type=str, help='') args = parser.parse_args() # Configuration for Python logging messages. logger = a99.get_python_logger() c = pyfant.Combo() c.conf.flag_log_file = True # Configuration for Fortran messages c.conf.flag_log_console = True # " c.conf.flag_output_to_dir = False # Will generate outputs in current directory for name in names: x = args.__getattribute__(name) if x is not None: c.conf.opt.__setattr__(name, x) c.run() logger.info("Session directory: %s" % c.conf.sid.dir)
"""Runs synthesis over large wavelength range, then plots continuum""" import pyfant import f311 import matplotlib.pyplot as plt import a99 if __name__ == "__main__": # Copies files main.dat and abonds.dat to local directory (for given star) pyfant.copy_star(starname="sun-grevesse-1996") # Creates symbolic links to all non-star-specific files, such as atomic & molecular lines, # partition functions, etc. pyfant.link_to_data() # Creates object that will run the four Fortran executables (innewmarcs, hydro2, pfant, nulbad) obj = pyfant.Combo() oo = obj.conf.opt # synthesis interval start (angstrom) oo.llzero = 2500 # synthesis interval end (angstrom) oo.llfin = 30000 # savelength step (angstrom) oo.pas = 1. # Turns off hydrogen lines oo.no_h = True # Turns off atomic lines oo.no_atoms = True # Turns off molecular lines oo.no_molecules = True obj.run()
pyfant.copy_star(starname="sun-grevesse-1996") pyfant.link_to_data() # Loads full atomic lines file fatoms = pyfant.FileAtoms() fatoms.load() runnables = [] for elem_ioni in MY_SPECIES: atom = fatoms.find_atom(elem_ioni) # Creates atomic lines file object containing only one atom fatoms2 = pyfant.FileAtoms() fatoms2.atoms = [atom] ecombo = pyfant.Combo() # Overrides file "atoms.dat" with in-memory object ecombo.conf.file_atoms = fatoms2 ecombo.conf.flag_output_to_dir = True oo = ecombo.conf.opt # Assigns synthesis range to match atomic lines range oo.llzero, oo.llfin = fatoms2.llzero, fatoms2.llfin # Turns off hydrogen lines oo.no_h = True # Turns off molecular lines oo.no_molecules = True runnables.append(ecombo) pyfant.run_parallel(runnables)
def test_run_combo(tmpdir): os.chdir(str(tmpdir)) pyfant.copy_star(pyfant.get_pfant_data_path('arcturus')) pyfant.link_to_data(pyfant.get_pfant_data_path("common")) c = pyfant.Combo() c.run()
# logger.info("%d abundance(s) changed" % cnt) # ## Creates the Runnable instances PAS = 0.04 logger.info("Calculation step will be set to %g" % PAS) logger.info("Preparing pfant's...") combos, ll, i = [], [], 0 ii = 0 n = file_atoms.num_lines for atom in file_atoms.atoms: for line in atom.lines: a = copy.copy(atom) # shallow copy a.lines = [line] f = pyfant.FileAtoms() f.atoms = [a] combo = pyfant.Combo([pyfant.FOR_PFANT]) # Fortran messages will not be displayed in terminal combo.conf.flag_log_console = False combo.conf.sid.flag_split_dirs = True # Forces pfant to run one single iteration (ikeytot will be =1) combo.conf.opt.aint = args.max + 10 combo.conf.file_atoms = f combo.conf.file_abonds = fa combo.conf.opt.logging_level = "warning" combo.conf.opt.pas = PAS combo.conf.flag_output_to_dir = True combo.conf.opt.zinf = args.max combo.conf.opt.no_molecules = True combo.conf.opt.opa = False combo.conf.opt.no_h = True # Note that half of the line (needs to)/(will be) calculated
def __run(self): # Called from run() to lower one indentation lever. # **Note** If something is not right here: *raise*. # # **Note** It plays around with Conf, SID, IdMaker objects import pyfant as pf # # Preparation self.__status.stage = "preparing" if self.__custom_id: self.__sid.id = self.__custom_id else: self.__sid.make_id() # This id maker will create directories inside the # multi-session directory. # It will replace the Pfant's default id maker custom_id_maker = pyfant.IdMaker() custom_id_maker.session_prefix_singular = os.path.join( self.__sid.dir, "session-") # # Runs innewmarcs and hydro2 ih = pyfant.Combo([pyfant.FOR_INNEWMARCS, pyfant.FOR_HYDRO2]) ih.conf.flag_output_to_dir = True ih.conf.logger = self.__logger ih.conf.opt = copy.copy(self.__options) ih.conf.sid = self.__sid ih.conf.file_main = copy.copy(self.__file_main) # Runs innewmarcs and hydro2; # it is also expected to create the "multi-session" directory ih.run() #### # # Runs pfant, pfant creates several .norm files self.__status.stage = "pfant stage" self.__logger.info("+++ pfant stage...") pfant_list = [] symbols = list(self.__file_abxfwhm.ab.keys()) abdiffss = list(self.__file_abxfwhm.ab.values()) n_abdif = len(abdiffss[0]) fwhms = self.__file_abxfwhm.get_fwhms() for fwhm in fwhms: if fwhm > 9.99: raise RuntimeError("fhwm maximum is 9.99") for j in range(n_abdif): file_abonds_ = copy.deepcopy(self.__file_abonds) for i, symbol in enumerate(symbols): found = False for k in range(len(file_abonds_.ele)): if file_abonds_.ele[k] == symbol: abdif = abdiffss[i][j] file_abonds_.abol[k] += abdif self.__logger.debug(j, " - ", symbol, "with abundance", file_abonds_.abol[k]) found = True if not found: raise RuntimeError("Atom '%s' not found" % symbol) pfant_name = self.__file_abxfwhm.pfant_names[j] \ if self.__file_abxfwhm.pfant_names \ else "%02d" % j flprefix = "%s_%s" % (self.__file_main.titrav, pfant_name) pfant = pyfant.Pfant() pfant.conf.flag_output_to_dir = False pfant.conf.opt = copy.copy(self.__options) pfant.conf.rename_outputs( [pyfant.FOR_INNEWMARCS, pyfant.FOR_HYDRO2], sid=self.sid) pfant.conf.sid.id_maker = custom_id_maker pfant.conf.sid.id = flprefix pfant.conf.opt.flprefix = self.__sid.join_with_session_dir( flprefix) pfant.conf.file_main = copy.copy(self.__file_main) pfant.conf.file_abonds = file_abonds_ pfant.conf.file_dissoc = file_abonds_.get_file_dissoc() self.__logger.debug("LOOK FLPREFIX " + str(pfant.conf.opt.flprefix)) pfant_list.append(pfant) rm = self.__runnable_manager = pyfant.RunnableManager() pyfant.run_parallel(pfant_list, flag_console=False, runnable_manager=rm) if self._flag_killed: return if not rm.flag_success: raise RuntimeError("Not all pfant's succeeded running.") #### # # Runs nulbad, saves .sp and .spl files # function to convert given FWHM to string to use as part of a file name fmt_fwhm = lambda x: "%03d" % round(x * 100) # ## Prepares nulbad's nulbad_list = [] sp_filenames_by_fwhm = { } # dictionary containing a list of .sp filenames for each FWHM for pfant in pfant_list: # prefix is sth like: multi-session-1/Sun_00 prefix = pfant.conf.opt.flprefix for fwhm in fwhms: nulbad = pyfant.Nulbad() nulbad.conf.flag_output_to_dir = False nulbad.conf.sid.id_maker = custom_id_maker nulbad.conf.opt = copy.copy(self.__options) nulbad.conf.opt.fn_flux = pfant.conf.opt.flprefix + ".norm" nulbad.conf.opt.fwhm = fwhm nulbad.conf.opt.fn_cv = "%s_%s.sp" % (prefix, fmt_fwhm(fwhm)) nulbad_list.append(nulbad) if not fwhm in sp_filenames_by_fwhm: sp_filenames_by_fwhm[fwhm] = [] sp_filenames_by_fwhm[fwhm].append(nulbad.conf.opt.fn_cv) # ## Saves files for lineplot.py (lists of spectra) # Each item of each list is a full path to a spectrum file for fwhm, sp_filenames in list(sp_filenames_by_fwhm.items()): spl_filename = os.path.join(self.__sid.dir, "cv_%s.spl" % fmt_fwhm(fwhm)) with open(spl_filename, "w") as h: for sp_filename in sp_filenames: h.write( os.path.abspath( os.path.join(self.__sid.dir, os.path.basename(sp_filename) + "\n"))) # ## Runs nulbads self.__status.stage = "nulbad stage" self.__logger.info("+++ nulbad stage...") rm = self.__runnable_manager = pyfant.RunnableManager() pyfant.run_parallel(nulbad_list, flag_console=False, runnable_manager=rm) if self._flag_killed: return if not rm.flag_success: raise RuntimeError("Not all nulbad's succeeded running.") #### # # Deletes session-* directories if successful FLAG_CLEAN = True if FLAG_CLEAN: self.__logger.info("+++ Cleaning up...") for pfant in pfant_list: pfant.sid.clean() for nulbad in nulbad_list: nulbad.sid.clean() else: self.__logger.info("+++ NOT cleaning up...")