def test_duplicates(): fname = datadir+'/linelists/lin4077new' N = 50 ll1 = LineList.read_moog(fname) ll2 = LineList.read_moog(fname) ll = table.vstack([ll1,ll2[0:N]]) duplicate_indices,duplicate_lines = ll.find_duplicates(thresh=.01) assert_equals(2*N,len(duplicate_indices))
def test_writeread(fname=datadir+'/linelists/masseron_linch.txt'): ll = LineList.read(fname) ll.write('line_list.fits',format='fits') ll2 = LineList.read('line_list.fits',format='fits') for i in range(len(ll)): for col in ll[i].colnames: if isinstance(ll[i][col], str): continue diff = np.sum(np.abs(ll[i][col] - ll2[i][col])) assert np.isnan(diff) or diff < .001, "{} {}".format(ll[i][col],ll2[i][col]) os.remove('line_list.fits')
def add_synth_list(self): if self.session is None: return None paths = self.open_file(caption="Select linelists for synths", dir="", filter="") if not paths: return None for path in paths: transitions = LineList.read(path) selectable_elements \ = list(set(transitions.unique_elements).difference(["H"])) dialog = PeriodicTableDialog( selectable_elements=selectable_elements, explanation="Please select which element(s) will be measured" " by synthesizing the transitions in {}:".format( os.path.basename(path)), multiple_select=True) dialog.exec_() if len(dialog.selected_elements) == 0: # Nothing selected. Skip this filename. continue self.session.import_linelist_as_synthesis_model(path, dialog.selected_elements) self.tableview.model().reset() self.tableview.clearSelection() return None
def test_exception(): ll = LineList.read(datadir+'/linelists/complete.list') N = len(ll) ll2 = LineList.read(datadir+'/linelists/complete.list') ll.merge(ll2,skip_equal_loggf=True) assert len(ll)==N,"{} {}".format(len(ll),N) ll2[5]['loggf'] = -3.14159 ll2[200]['loggf'] = -3.14159 try: ll.merge(ll2,skip_equal_loggf=True) except linelists.LineListConflict as e: assert len(e.conflicts1) == 2 assert len(e.conflicts2) == 2 else: raise RuntimeError("Conflicts didn't work")
def test_get_needed_isotopes(): ll = LineList.read(datadir+'/linelists/lin4554new') rproc = load_isotope_data('rproc') isotopes, missing_isotopes = get_needed_isotopes(ll,rproc) assert len(missing_isotopes) == 0, missing_isotopes validate_isotopes(isotopes) for elem in isotopes: for mass in isotopes[elem]: assert isotopes[elem][mass] == rproc[elem][mass]
def test_get_needed_isotopes2(): ll = LineList.read(datadir+'/linelists/masseron_linch.txt') asplund = load_isotope_data('asplund') asplund = add_molecules(asplund) isotopes, missing_isotopes = get_needed_isotopes(ll,asplund,include_molecules=True) assert len(missing_isotopes) == 0, missing_isotopes validate_isotopes(isotopes) for elem in isotopes: for mass in isotopes[elem]: assert isotopes[elem][mass] == asplund[elem][mass]
def test_identify_isotopes(): ll = LineList.read(datadir+'/linelists/lin4554new') isotopes = identify_isotopes(ll) for elem in isotopes: for mass in isotopes[elem]: if elem != 'Ba': assert mass == 0 assert isotopes[elem][mass] == 1 needed_isotopes = identify_needed_isotopes(ll) num_isotopes = 0 for elem in needed_isotopes: for mass in needed_isotopes[elem]: num_isotopes += 1 assert num_isotopes == 5
def test_identify_isotopes2(): ll = LineList.read(datadir+'/linelists/masseron_linch.txt') isotopes = identify_isotopes(ll,include_molecules=True) for elem in isotopes: for mass in isotopes[elem]: #print(elem,mass,isotopes[elem][mass]) if elem not in ['C','H-C','H']: assert mass == 0 elif elem == 'H': assert mass == 1 elif elem == 'C': assert mass in [12,13] elif elem == 'H-C': assert mass in [112,113] assert isotopes[elem][mass] == 1 needed_isotopes = identify_needed_isotopes(ll,include_molecules=True) num_isotopes = 0 for elem in needed_isotopes: for mass in needed_isotopes[elem]: #print(elem,mass,isotopes[elem][mass]) num_isotopes += 1 assert num_isotopes == 4, num_isotopes
return None sys.excepthook = exception_hook # Run the main application window. app.window = Ui_MainWindow(spectrum_filenames=[ datadir + "/spectra/hd122563_1blue_multi_090205_oldbutgood.fits", datadir + "/spectra/hd122563_1red_multi_090205_oldbutgood.fits" ]) # Enable all tabs for i in range(app.window.tabs.count()): app.window.tabs.setTabEnabled(i, True) session = app.window.session # TODO load a synthesis model here transitions = LineList.read(datadir + '/linelists/lin4554new') session.metadata["line_list"] = transitions synth = sm.SpectralSynthesisModel(session, transitions['hash'], 'Ba') session.metadata["spectral_models"] = [synth] with open(smh.Session._default_settings_path, "rb") as fp: defaults = yaml.load(fp) app.window.chemical_abundances_tab.new_session_loaded() app.window.tabs.setCurrentIndex(4) app.window.chemical_abundances_tab.fit_all() app.window.show() sys.exit(app.exec_())
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'])
"/spectra/hd122563_1blue_multi_090205_oldbutgood.fits", datadir + "/spectra/hd122563_1red_multi_090205_oldbutgood.fits" ]) # Enable all tabs for i in range(app.window.tabs.count()): app.window.tabs.setTabEnabled(i, True) session = app.window.session with open(smh.Session._default_settings_path, "rb") as fp: defaults = yaml.load(fp) datadir = os.path.dirname( os.path.abspath(__file__)) + '/../tests/test_data' # Load in line_list ll = LineList.read( os.path.dirname(os.path.abspath(__file__)) + '/../tests/test_data/linelists/complete.list') session.metadata['line_list'] = ll[190:200] #strong lines #session.metadata['line_list'] = ll[90:100] # Load in spectral_models from linelist #from linelist_manager import TransitionsDialog print("Loading spectral models...") start = time.time() sm = [] for hash in session.metadata["line_list"]["hash"]: sm.append(smh.spectral_models.ProfileFittingModel(session, [hash])) session.metadata['spectral_models'] = sm print("Done! {:.1f}s".format(time.time() - start)) print("Fitting lines...")
def test_not_needed_isotopes(): ll = LineList.read(datadir+'/linelists/lin4554new') isos = load_isotope_data('asplund') #Does not have Ba! found_isos, missing_isos = get_needed_isotopes(ll,isos) if len(missing_isos) != 1: raise Error("{} {}".format(found_isos,missing_isos))
def test_merge(): ll1 = lls[0] ll2 = lls[1] ll1.merge(ll2,raise_exception=False) lls[0] = LineList.read_moog(datadir+'/linelists/masseron_linch.txt')
from __future__ import (division, print_function, absolute_import, unicode_literals) import os from smh import linelists, utils from smh.linelists import LineList from nose.tools import assert_equals, assert_almost_equals, ok_ from astropy import table import numpy as np ll_filenames = ['masseron_linch.txt'] ll_filenames = ['masseron_linch.txt','lin4077new','lin4554new'] datadir = os.path.dirname(os.path.abspath(__file__))+'/test_data' lls = [LineList.read(datadir+'/linelists/'+filename) for filename in ll_filenames] moog_lls = [LineList.read(datadir+'/linelists/'+filename,moog_columns=True) for filename in ll_filenames] def test_species_converting(): # Species, elem1, isotope1, elem2, isotope2, ion tests = [(56.1, 'Ba', 0, '', 0, 2), (56.0, 'Ba', 0, '', 0, 1), (56.1152, 'Ba', 152, '', 0, 2), (106.0, 'H', 0, 'C', 0, 1), (106.00112, 'H', 1, 'C', 12, 1), (106.00113, 'H', 1, 'C', 13, 1) ] failed = False for test in tests: species, elem1, isotope1, elem2, isotope2, ion = test input = (elem1, elem2, isotope1, isotope2, ion)