def _main(): fm = pyfant.FileMain() fm.init_default() fm.llzero, fm.llfin = 1000., 200000. # spectral synthesis range in Angstrom ei = pyfant.Innewmarcs() ei.conf.file_main = fm ei.run() ei.clean() eh = pyfant.Hydro2() eh.conf.file_main = fm eh.run() eh.load_result() eh.clean() _plot_profiles(eh.result["profiles"])
#!/usr/bin/env python """Main configuration file editor.""" import sys import argparse import logging import a99 import pyfant a99.logging_level = logging.INFO a99.flag_log_file = True if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__, formatter_class=a99.SmartFormatter) parser.add_argument('fn', type=str, help='main configuration file name', default='main.dat', nargs='?') args = parser.parse_args() m = pyfant.FileMain() m.load(args.fn) app = a99.get_QApplication([]) form = pyfant.XFileMain() form.load(m) form.show() sys.exit(app.exec_())
def __init__(self, parent=None, file_main=None, file_abonds=None): # State variables a99.XLogMainWindow.__init__(self, parent) # XRunnableManager instance self._manager_form = None # RunnableManager instance self._rm = None self.save_dir = None self.load_dir = None # # Synchronized sequences # Used in generic operations where only certain parameters change self.tab_texts = [ "Main configuration (Alt+&1)", "Abundances (Alt+&2)", "Command-line options (Alt+&3)" ] self.flags_changed = [False, False, False] self.save_as_texts = [ "Save main configuration as...", "Save abundances as...", "Save command-line options as..." ] self.open_texts = [ "Load main configuration file", "Load abundances file", "Load command-line options file" ] self.clss = [pyfant.FileMain, pyfant.FileAbonds, pyfant.FileOptions] self.wilds = ["*.dat", "*.dat", "*.py"] # # Menu bar b = self.menuBar() m = self.menu_file = b.addMenu("&File") ac = m.addAction("&Open...") ac.setShortcut("Ctrl+O") ac.triggered.connect(self.on_open) m.addSeparator() ac = m.addAction("&Save") ac.setShortcut("Ctrl+S") ac.triggered.connect(self.on_save) ac = m.addAction("Save &as...") ac.setShortcut("Ctrl+Shift+S") ac.triggered.connect(self.on_save_as) ac = m.addAction("Save a&ll...") ac.setShortcut("Alt+Shift+S") ac.triggered.connect(self.on_save_all) m.addSeparator() ac = m.addAction("Load &default") ac.setStatusTip("Loads default") ac.setShortcut("Ctrl+D") ac.triggered.connect(self.on_reset) m.addSeparator() ac = m.addAction("&Quit") ac.setShortcut("Ctrl+Q") ac.triggered.connect(self.close) m = self.menu_view = b.addMenu("&View") ac = m.addAction("Runnables &Manager") ac.setShortcut("Ctrl+M") ac.triggered.connect(self.on_show_rm) # # It is necessary to do a little more work to create this option # ac = m.addAction("&Explorer") # ac.setShortcut("Ctrl+E") # ac.triggered.connect(self.on_show_explorer) # # Central layout cw = self.centralWidget = QWidget() self.setCentralWidget(cw) la = self.layout_main = QVBoxLayout(cw) # ## Main control bar # A layout is created and left blank for descendants to add # widgets as needed l = self.controlLayout = QHBoxLayout() la.addLayout(l) # ## Tabs # tab "File" tt = self.tabWidget = QTabWidget(self) la.addWidget(tt) tt.setFont(a99.MONO_FONT) # ### Main configuration tab w0 = self.c27272 = QWidget() tt.addTab(w0, self.tab_texts[0]) l0 = self.c12842 = QVBoxLayout(w0) # #### Main configuration file toolbar l1 = self.c29378 = QHBoxLayout() l0.addLayout(l1) w = QLabel("<b>File:<b>") l1.addWidget(w) w = self.label_fn_main = QLabel() l1.addWidget(w) l1.addSpacerItem( QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)) # #### Main file editor widget me = self.me = WFileMain() l0.addWidget(me) me.changed.connect(self.on_main_edited) # ### Abundances tab w0 = self.c10101 = QWidget() tt.addTab(w0, self.tab_texts[1]) l0 = self.c54354 = QVBoxLayout(w0) # #### Abundances file toolbar l1 = self.c65478 = QHBoxLayout() w = QLabel("<b>File:</b>") l0.addLayout(l1) l1.addWidget(w) w = self.label_fn_abonds = QLabel() l1.addWidget(w) l1.addSpacerItem( QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)) # #### Abundances editor ae = self.ae = WFileAbonds() l0.addWidget(ae) ae.changed.connect(self.on_abonds_edited) # ### Command-line options tab w0 = QWidget() tt.addTab(w0, self.tab_texts[2]) l0 = QVBoxLayout(w0) # # #### File label # l1 = self.c293wd = QHBoxLayout() # l0.addLayout(l1) # w = QLabel("<b>File:<b>") # l1.addWidget(w) # w = self.label_fn_options = QLabel() # l1.addWidget(w) # l1.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)) oe = self.oe = WOptionsEditor(self) oe.changed.connect(self.on_options_edited) l0.addWidget(oe) # tt.tabBar() # ### Final tabs setup tt.setCurrentIndex(0) # ### These sequences couldn't be set above because the widgets didn't exist yet self.editors = [self.me, self.ae, self.oe] self.labels_fn = [ self.label_fn_main, self.label_fn_abonds, self.oe.label_fn ] assert len(self.tab_texts) == len(self.flags_changed) == \ len(self.save_as_texts) == len(self.open_texts) == len(self.clss) == \ len(self.editors) == len(self.labels_fn) # # Loads default files if os.path.isfile(pyfant.FileMain.default_filename): f = pyfant.FileMain() f.load() self.me.load(f) if os.path.isfile(pyfant.FileAbonds.default_filename): f = pyfant.FileAbonds() f.load() self.ae.load(f) if os.path.isfile(pyfant.FileOptions.default_filename): f = pyfant.FileOptions() f.load() self.oe.load(f) else: self.oe.load(pyfant.FileOptions()) self._update_labels_fn()
def test_FileMain(tmpdir): os.chdir(str(tmpdir)) obj = pyfant.FileMain() obj.init_default() obj.save_as()
def synth_plot_build(ax, name=None, st_dt=None): #takes a name for the synthesis and the star data dictionary global mainfile global abondsfile global atomsfile #initialize main parameters mainfile = pf.FileMain() mainfile.load() mainfile.pas = 0.01 #setting atmospherical parameters if pflag or multiflag: mainfile.fwhm = st_dt['fwhm'] teff = st_dt['teff'] logg = st_dt['logg'] met = st_dt['met'] vt = st_dt['vt'] if fflag: mainfile.fwhm = fw if pflag or multiflag: mainfile.titrav = name mainfile.teff = teff mainfile.glog = logg mainfile.asalog = mainfile.afstar = met mainfile.vvt = [vt] mainfile.flprefix = name[:3] mainfile.nhe = 0.085 mainfile.llzero = linelambda - linerange / 2 - 3 mainfile.llfin = linelambda + linerange / 2 + 3 #initializing elemental abundance file and values #note that if there's a file "abonds.dat" in the directory, it will be used #if not, default values (solar) will be loaded #additionally, if multirun is being used, the specified abonds file will be used abondsfile = pf.FileAbonds() if multiflag: abondsfile.load(st_dt['ab_file']) else: abondsfile.load() idx = abondsfile.ele.index(pf.adjust_atomic_symbol(element)) if pf.adjust_atomic_symbol(element) != "FE": abondsfile.abol[abondsfile.ele.index("FE")] = -99.99 abondsfile.abol[idx] = -99.99 #initializing atomic data, based on filename passed or not atomsfile = pf.FileAtoms() atomsfile.load(atomdata) #setting and interpolating atmospherical model m = pf.Innewmarcs() m.conf.flag_log_console = False m.conf.file_main = mainfile m.conf.opt.allow = True m.conf.opt.absoru = True m.conf.opt.opa = False m.run() #calculating hydrogen lines h = pf.Hydro2() h.conf.flag_log_console = False h.conf.file_main = mainfile h.run() #running pfant only for atoms (except chosen element and Fe) spec_atoms = pfant_cut(no_at=False, no_mol=True, fname='only_atoms') #running pfant only for molecules spec_molecules = pfant_cut(no_at=True, no_mol=False, fname='only_mols') #running pfant for separate chosen element lines #loading back true abundances abondsfile = pf.FileAbonds() if multiflag: abondsfile.load(st_dt['ab_file']) else: abondsfile.load() if element != 'Fe': el_speclines, el_specval = el_multirun(element) #running pfant for separate iron lines fe_speclines, fe_specval = el_multirun("Fe") #running pfant for the full spectrum spec_full = pfant_cut(no_at=False, no_mol=False, fname='full') #START PLOTTING value_specat = [spec_atoms.x, spec_atoms.y] value_specmol = [spec_molecules.x, spec_molecules.y] value_total = [spec_full.x, spec_full.y] ax.plot(value_total[0], value_total[1], 'b-') ax.plot(value_specat[0], value_specat[1], 'g-') ax.plot(value_specmol[0], value_specmol[1], 'c-') if sflag or multiflag: if multiflag: global ospec ospec = np.genfromtxt(st_dt['spec'], unpack=True) obsplot = ax.plot(ospec[0]+st_dt['sp_adj'][0], ospec[1]/st_dt['sp_adj'][1], 'k--') elif rflag: ax.plot(ospec[0]+rel[0], ospec[1]/rel[1], 'k--') else: ax.plot(ospec[0], ospec[1], 'k--') for l in fe_specval: ax.plot(l[0], l[1], color='#FF8C00', ls='-.', lw=1.5) if element != 'Fe': for l in el_specval: ax.plot(l[0], l[1], 'm-', lw=1.5) if multiflag: plt.text(0.04, 0.06, name, horizontalalignment='left', verticalalignment='bottom', fontsize=16, transform=plt.gca().transAxes) plt.ylim((0., 1.05)) return [obsplot, ospec]