def test_convert_v01(): fname_in = datadir + "/hd122563_v0.1.smh" fname_out = datadir + "/.converted.hd122563_v0.1.smh" legacy.convert_v0_1_to_v0_2(fname_in, fname_out, overwrite=True) session = Session.load(fname_out) session.measure_abundances()
def test_ReviewTab(session=None): if session is None: session = Session.load(datadir + "/test_G64-12_v02.smh") session.measure_abundances() window, cw = create_blank_window(width=1000, height=600) window.session = session tab = ReviewTab(window) vbox = QtGui.QVBoxLayout(cw) vbox.addWidget(tab) return window
def test_import_models_into_session(): session = Session([datadir + '/spectra/hd122563.fits']) session.import_linelist_as_profile_models(eqw_ll_fname) print("Loaded profiles into session") for fname, elem in zip(synth_ll_filenames, synth_elems): session.import_linelist_as_synthesis_model(fname, elem) print("Loaded syntheses into session")
options, args = parser.parse_args() origfname, datafname, outfname = args tmpfname = "./.tmp.pkl" while os.path.exists(tmpfname): tmpfname = tmpfname[:-4] + "p.pkl" assert os.path.exists(origfname), "input 1 {} does not exist".format( origfname) assert os.path.exists(datafname), "input 2 {} does not exist".format( datafname) assert options.force or (not os.path.exists(outfname) ), "output {} already exists".format(outfname) session1 = Session.load(origfname) session2 = Session.load(datafname) profile_keys = [ "profile", "central_weighting", "window", "continuum_order", "detection_sigma", "detection_pixels", "max_iterations", "velocity_tolerance", "mask", "antimask_flag", "elements", "species" ] synthesis_keys = [ "mask", "window", "continuum_order", "velocity_tolerance", "smoothing_kernel", "initial_abundance_bounds", "elements", "species", "manual_continuum", "manual_sigma_smooth", "manual_rv" ] new_spectral_models = [] for model in session1.spectral_models:
return None if __name__=="__main__": app = QtGui.QApplication(sys.argv) import main_ui app.window = main_ui.Ui_MainWindow() for i in range(app.window.tabs.count()): app.window.tabs.setTabEnabled(i, True) app.window.show() import yaml with open(Session._default_settings_path, "rb") as fp: defaults = yaml.load(fp) datadir = os.path.dirname(os.path.abspath(__file__))+"/../tests/test_data" session = Session([datadir+"/spectra/hd122563.fits"]) session.metadata.update(defaults) ll = LineList.read(os.path.dirname(os.path.abspath(__file__))+"/../tests/test_data/linelists/complete.list") session.metadata["line_list"] = ll import cPickle as pickle print("Loading pre-saved spectral models"); start = time.time() with open(datadir+"/ewtest.pkl","rb") as fp: session.metadata["spectral_models"] = pickle.load(fp) print("Done!",time.time()-start) app.window.session = session chemical_abundances_tab = app.window.chemical_abundances_tab abundtree = chemical_abundances_tab.abundtree model = abundtree.model() #abundtree = AbundTreeView(None)
#prefixred = prefix+"/red/Final-Products" prefix="/Users/alexji/Dropbox/Observing/2016_8/reduced_data/rproc" prefixblue=prefix prefixred=prefix #outpath = "./n3" outpath = "/Users/alexji/Dropbox/Observing/2016_8/reduced_data/rproc/summaries" rv_fix = {} #{"retii-09":60.0} specnames = [x[:-15] for x in glob.glob(prefixblue+"/*blue*")] specnames = [os.path.basename(x) for x in specnames] print(specnames) for specname in specnames: bluespec = prefixblue+"/"+specname+"blue_multi.fits" redspec = prefixred +"/"+specname+"red_multi.fits" session = Session([bluespec,redspec]) #with open(smh.Session._default_settings_path, "rb") as fp: # defaults = yaml.load(fp) #session.metadata.update(defaults) if specname in rv_fix: rv = rv_fix[specname] else: rv,rve = session.rv_measure() print("RV:",rv) session.rv_correct(rv) #session.normalize_input_spectra() for index,order in enumerate(session.input_spectra): fit_continuum(session,index) session.stitch_and_stack()
from __future__ import (division, print_function, absolute_import, unicode_literals) import numpy as np import matplotlib.pyplot as plt import time import smh from smh import Session from smh.spectral_models import (ProfileFittingModel, SpectralSynthesisModel) from smh.linelists import LineList if __name__ == "__main__": path = "/Users/alexji/lib/smhr/smh/tests/test_data/test2.smh" session = Session.load(path) # Already normalized and rv-corrected, but not stitched normalized_spectrum = session.stitch_and_stack() metadata = session.metadata line_list = metadata["line_list"] spectral_models = metadata["spectral_models"] """ # Everything is fit already, but you can run fit again print("Fitting models..."); start = time.time() for model in spectral_models: try: res = model.fit() except Exception as e: print(model.elements, model.species, model._repr_wavelength, e) print("Time to fit all models: {:.1f}".format(time.time()-start)) """
self.mpl_figure.draw() return True if __name__ == "__main__": import sys from smh import linelists, Session, specutils transitions = linelists.LineList.read( "/Users/arc/research/ges/linelist/vilnius.ew.fe") session = Session([ "/Users/arc/codes/smh/hd44007red_multi.fits", "/Users/arc/codes/smh/hd44007blue_multi.fits", ]) session.normalized_spectrum = specutils.Spectrum1D.read( "../smh/hd44007-rest.fits") session.metadata["line_list"] = transitions from smh import spectral_models as sm foo = [] for i in range(len(transitions)): if i % 2: foo.append( sm.ProfileFittingModel(session, transitions["hash"][[i]])) else: foo.append(
except RuntimeError: None # Load some spectra. spectra = [] + \ Spectrum1D.read("/Users/arc/Downloads/hd122563_1blue_multi_090205_oldbutgood.fits") + \ Spectrum1D.read("/Users/arc/Downloads/hd122563_1red_multi_090205_oldbutgood.fits") + \ [Spectrum1D.read("smh/balmer/hd122563.fits")] for spectrum in spectra[:-1]: spectrum._dispersion = (1 + +52.1 / 299792.458) * spectrum.dispersion #spectra = [Spectrum1D.read("hd140283.fits")] #spectra = [Spectrum1D.read("/Users/arc/research/fe-rich-stars/sm0342-2842.rest.fits")] sigma = 0.01 * np.ones_like(spectra[-1].dispersion) spectra[-1]._ivar = sigma**(-2) from smh import Session session = Session.load("hd122563.smh") window = BalmerLineFittingDialog(spectra, observed_spectra_labels=[ "Order {}".format(i) for i in range(1, len(spectra)) ] + ["Normalized rest-frame spectrum"], session=session) window.exec_()
def test_import_eqw_into_session(): session = Session([datadir + '/spectra/hd122563.fits']) session.import_linelist_as_profile_models( datadir + "/linelists/frebel13_HD122563.moog2", import_equivalent_widths=True) print("Loaded eqws into session")
def test_create_synthesis(): session = Session([datadir + '/spectra/hd122563.fits']) for ll, elem in zip(synth_lls, synth_elems): model = sm.SpectralSynthesisModel(session, ll, elem) print("Created synthesis models!")
def test_create_profile(): session = Session([datadir + '/spectra/hd122563.fits']) model = sm.ProfileFittingModel(session, eqw_ll[0]) model = sm.ProfileFittingModel(session, eqw_ll[0]) print("Created profile model!")
def test_load_session(): file_to_load = datadir + "/test_create_session.smh" session = Session.load(file_to_load)
def test_create_session_and_analyze(): file_to_write_to = datadir + "/.test_create_session.smh" #file_to_write_to = datadir+"/test_create_session.smh" session = Session([datadir + '/spectra/hd122563.fits']) session.import_linelist_as_profile_models(datadir + '/linelists/complete.list') #rv, e_rv = session.rv_measure() #print( rv, e_rv ) session.rv_correct(0.0) # TODO put this in somewhere nice, as well as the rest of the normalization tab session.metadata["normalization"] = { "continuum": [1.0], "normalization_kwargs": [{}] } session.stitch_and_stack() start = time.time() num_fit = 0 for model in session.spectral_models: try: res = model.fit() except (ValueError, RuntimeError, TypeError) as e: print("Fitting error", model) print(e) else: num_fit += 1 print("Time to fit {}/{} models: {:.1f}".format( num_fit, len(session.spectral_models), time.time() - start)) session.measure_abundances() session.save(file_to_write_to, overwrite=True)
self.endRemoveRows() class IsotopeLog(QtGui.QPlainTextEdit): def log(self, msg): self.appendMessage(msg) def appendMessage(self, msg): self.appendPlainText(msg) self.verticalScrollBar().setValue(self.verticalScrollBar().maximum()) if __name__ == "__main__": # For development datadir = os.path.dirname( os.path.abspath(__file__)) + '/../tests/test_data' session = Session([datadir + "/spectra/hd122563.fits"]) orig_isotopes = isoutils.load_isotope_data('rproc') ll = LineList.read( os.path.dirname(os.path.abspath(__file__)) + '/../tests/test_data/linelists/lin4554new') session.metadata['isotopes'] = orig_isotopes session.metadata['line_list'] = ll app = QtGui.QApplication(sys.argv) window = IsotopeDialog(session) #orig_isotopes=orig_isotopes, linelist=ll) window.exec_() #print(session.metadata['isotopes']) #print('U in isotopes?', 'U' in session.metadata['isotopes'])
return None if __name__ == "__main__": # This is just for development testing. app = QtGui.QApplication(sys.argv) #window = RVRegionDialog(None) #window.exec_() widget = QtGui.QWidget(None) with open(Session._default_settings_path, "rb") as fp: defaults = yaml.load(fp) datadir = os.path.dirname( os.path.abspath(__file__)) + '/../tests/test_data' session = Session([datadir + "/spectra/hd122563.fits"]) widget.session = session session.metadata.update(defaults) ll = LineList.read( os.path.dirname(os.path.abspath(__file__)) + '/../tests/test_data/linelists/lin4554new') session.metadata['line_list'] = ll rv_tab = RVTab(widget) rv_tab.update_from_new_session() rv_tab.template_path = QtGui.QLineEdit() rv_tab.template_path.setText(datadir + '/spectra/hd122563.fits') dialog = RVRegionDialog(rv_tab)
rhomat = utils._make_rhomat(rho_Tg=rho_Tg, rho_Tv=rho_Tv, rho_gv=rho_gv, rho_TM=rho_TM, rho_gM=rho_gM, rho_vM=rho_vM) version_out = "v1" # Submitted version fnames = glob.glob("smhr_errors/*_errors.smh") print(fnames) all_lines = [] all_abunds = [] for fname in fnames: name = os.path.basename(fname)[:-11] print(name) session = Session.load(fname) ## Extract line info linetab = utils.process_session_uncertainties_lines(session, rhomat) ## Manual updates to line info try: linetab = fix_ch_lines(name, linetab) except Exception as e: print("CH", e) linetab = add_ba_errors(name, linetab) linetab = add_cn_errors(name, linetab) linetab = fix_o_loggf(name, linetab) linetab = add_al_errors(name, linetab) linetab = add_hfs_errors(name, linetab) for species in [8.0, 106.0, 56.1, 607.0, 13.0] + hfs_species: ix = np.where((linetab["species"] == species)
def create_blank_window(width=800, height=400): window = QtGui.QMainWindow() window.resize(width, height) cw = QtGui.QWidget(window) window.setCentralWidget(cw) return window, cw def test_ReviewTab(session=None): if session is None: session = Session.load(datadir + "/test_G64-12_v02.smh") session.measure_abundances() window, cw = create_blank_window(width=1000, height=600) window.session = session tab = ReviewTab(window) vbox = QtGui.QVBoxLayout(cw) vbox.addWidget(tab) return window if __name__ == "__main__": session = Session.load(datadir + "/test_G64-12_v02.smh") w1 = test_ReviewTab(session) ws = [w1] for w in ws: w.show() w.raise_() sys.exit(app.exec_())