def master_build(write=False, nsources=None, plots=True, verbose=True): """ Master loop to build the line lists Parameters ---------- check_only : bool, optional Only check to see what would be created, i.e. do not execute nsources : int, optional Mainly for step-by-step build plots : bool, optional Generate plots, if write=True too """ # Load sources sources = arcl_io.load_source_table() if nsources is not None: sources = sources[0:nsources] # Loop on sources for source in sources: print("=============================================================") print("Working on source {:s}".format(source['File'])) print("=============================================================") # Load line table ID_lines, U_lines = load_source.load(source['File'], source['Format'], source['Lines'].split(','), plot=plots, wvmnx=[source['wvmin'], source['wvmax']]) # Lines (Double check) src_lines = source['Lines'].split(',') if ID_lines is None: uions = src_lines else: # Check uions = np.unique(ID_lines['ion'].data) for src_line in src_lines: if src_line not in uions.tolist(): raise ValueError("Line {:s} not found in ID_lines".format(src_line)) # Loop on ID ions for ion in uions: # Parse idx = ID_lines['ion'] == ion sub_tbl = ID_lines[idx] # Generate? ion_file = llist_path+'{:s}_lines.dat'.format(ion) if not os.path.isfile(ion_file): if not write: print("Would generate line list:\n {:s}".format(ion_file)) else: print("Generating line list:\n {:s}".format(ion_file)) create_line_list(sub_tbl, source['File'], source['Instr'], ion_file) else: update_line_list(sub_tbl, source['File'], source['Instr'], ion_file, write=write)
def init_line_list(): """ Initialize a Table for a linelist Rigidly enforces table column formats Strings are the most annoying Returns ------- init_tbl : Table One dummy row """ # Get str lengths from defs len_line = defs.str_len()['ion'] len_src = defs.str_len()['Source'] # Load sources to check sources = arcl_io.load_source_table() src_files = sources['File'].data if len(src_files[0]) > len_src: raise ValueError( "Source filename now exceeds table. Should fix source name") dummy_src = str('#') * len_src # Arc Line name dummy_line = str('#') * len_line # # Dict for Table idict = OrderedDict() idict['ion'] = dummy_line idict['wave'] = 0. idict['NIST'] = 0 idict['Instr'] = 0 # Flag for instrument idict['amplitude'] = 0 idict['Source'] = dummy_src # Table tkeys = idict.keys() lst = [[idict[tkey]] for tkey in tkeys] init_tbl = Table(lst, names=tkeys) # Return return init_tbl
def test_load_sources(): sources = arcl_io.load_source_table() # Test assert isinstance(sources, Table)
def main(args=None): """ Run Parameters ---------- args Returns ------- """ # Grab arguments pargs = parser(options=args) import numpy as np from astropy.table import vstack from arclines import build_lists from arclines import io as arcl_io from arclines import load_source from arclines import plots as arcl_plots from arclines import utils as arcl_utils print("=============================================================") print("This script is for EXPERTS ONLY") print("Continue only if you know what you are doing") print("This script adds only the *last* source listed") print("Otherwise exit") print("=============================================================") if not pargs.skip_stop: pdb.set_trace() # Load sources sources = arcl_io.load_source_table() source = sources[-1] # Load line lists uions = arcl_utils.unique_ions(source) llist_dict = {} for ion in uions: try: llist_dict[ion] = arcl_io.load_line_list(ion, use_ion=True) except IOError: print("No linelist found for ion={:s}. Will create one".format(ion)) # IDs print("=============================================================") print("Working on adding IDs from source {:s}".format(source['File'])) print("=============================================================") llist_dict = build_lists.source_to_line_lists(source, write=pargs.write, llist_dict=llist_dict) # Create line list ll = [] for key in llist_dict.keys(): ll.append(llist_dict[key]) line_lists = vstack(ll) # Purge unknowns print("=============================================================") print("Purging UNKNOWNs") print("=============================================================") build_lists.purge_unknowns(line_lists, write=pargs.write) print("=============================================================") print("Working on adding Unknowns from source {:s}".format(source['File'])) print("=============================================================") if not pargs.no_unknowns: unknwns = build_lists.source_to_unknowns(source, write=pargs.write) unknwns.remove_column('line_flag') else: unknwns = None if unknwns is not None: ll.append(unknwns) # Loop to my loop print("=============================================================") print("Working on plot for {:s}".format(source['File'])) print("=============================================================") # Load src_dict = load_source.load(source) uions = arcl_utils.unique_ions(source, src_dict=src_dict) src_dict['uions'] = uions # Outfile iext = source['File'].rfind('.') outfile = source['File'][:iext]+'.pdf' title = source['File'][:iext] # arcl_plots.show_source(src_dict, line_lists, outfile, title=title, clobber=True)