def get_state(stateID): """ Get the state with ID stateID - if this is greater than or equal to stateID_offset (ie its ID is higher than the highest already in the database), then it is a new state and we expect to find it in our states[] list. If it is less than stateID_offset, we need to retrieve it from the database. """ if stateID < stateID_offset: state = State.objects.get(pk=stateID) # map the Django State object to an instance of the appropriate # CaseClass for this state global_iso_id = state.iso_id molec_id, local_iso_id = hitran_ids[global_iso_id] CaseClass = hitran_meta.get_case_class(molec_id, local_iso_id) return CaseClass(molec_id=molec_id, local_iso_id=local_iso_id, global_iso_id=global_iso_id, E=state.energy, g=state.g, s_qns=state.s_qns) else: return states[stateID - stateID_offset]
try: this_trans.delta_air = HITRANParam(val=prms.get(name="delta_air").val, ref=int(Iref[10:12]), name='delta_air', ierr=int(Ierr[5])) except Prm.DoesNotExist: pass this_trans.Elower = trans.Elower this_trans.gp = trans.gp this_trans.gpp = trans.gpp this_trans.multipole = trans.multipole # grab the flag from the par_line this_trans.flag = trans.par_line[145] CaseClass = hitran_meta.get_case_class(this_trans.molec_id, this_trans.iso_id) this_trans.statep = CaseClass(molec_id=this_trans.molec_id, iso_id=this_trans.iso_id, E=trans.statep.energy, g=trans.statep.g, s_qns=trans.statep.s_qns) this_trans.statepp = CaseClass(molec_id=this_trans.molec_id, iso_id=this_trans.iso_id, E=trans.statepp.energy, g=trans.statepp.g, s_qns=trans.statepp.s_qns) this_trans.case_module = hitran_meta.get_case_module( this_trans.molec_id, this_trans.iso_id) if not this_trans.validate_as_par(): print this_trans.par_line, '\nfailed to validate! I produced:'
ref=int(Iref[8:10]), name='n_air', ierr=int(Ierr[4]), relative=True) try: this_trans.delta_air = HITRANParam(val=prms.get(name="delta_air").val, ref=int(Iref[10:12]), name='delta_air', ierr=int(Ierr[5])) except Prm.DoesNotExist: pass this_trans.Elower = trans.Elower this_trans.gp = trans.gp this_trans.gpp = trans.gpp this_trans.multipole = trans.multipole # grab the flag from the par_line this_trans.flag = trans.par_line[145] CaseClass = hitran_meta.get_case_class(this_trans.molec_id, this_trans.iso_id) this_trans.statep = CaseClass(molec_id=this_trans.molec_id, iso_id=this_trans.iso_id, E=trans.statep.energy, g=trans.statep.g, s_qns=trans.statep.s_qns) this_trans.statepp = CaseClass(molec_id=this_trans.molec_id, iso_id=this_trans.iso_id, E=trans.statepp.energy, g=trans.statepp.g, s_qns=trans.statepp.s_qns) this_trans.case_module = hitran_meta.get_case_module(this_trans.molec_id, this_trans.iso_id) if not this_trans.validate_as_par(): print this_trans.par_line,'\nfailed to validate! I produced:' print this_trans.get_par_str() sys.exit(1) i += 1 this_pc = float(i)/ntrans * 100
def upload_states(args, isos, cases_list): """ Read in, store, and upload the states to enter the database from the .states file. Arguments: args: the processed command line arguments with the names of files to use in uploading the data, the list of HITRAN molecule and isotopologue IDs to resolve the global_iso_id to etc... isos: a list of Iso objects, ordered by their local isotopologue ID cases_list: a list of Case objects, where the index is the case_id (ie cases_list[0] is None, cases_list[1] represents the dcs case etc... Returns: a list of the State objects uploaded. """ if args.dry_run: vprint('[DRY RUN] Uploading states...') else: vprint('Uploading states...') # the uploaded states will be stored in this list: states = [] start_time = time.time() for line in open(args.states_file, 'r'): global_iso_id = int(line[:4]) # state energy try: E = float(line[5:15]) except (TypeError, ValueError): # undefined energy for this state E = None # state degeneracy try: g = int(line[16:21]) except (TypeError, ValueError): # undefined degeneracy for this state g = None # state quantum numbers as a string of ';' separated name=value pairs s_qns = line[22:].strip() if not s_qns: # no quantum numbers resolved for this state s_qns == None # the native HITRAN IDs for molecule and isotopologue: molec_id, local_iso_id = args.hitran_ids[global_iso_id] # get the right Class to use to describe this state CaseClass = hitran_meta.get_case_class(molec_id, local_iso_id) # state is one of the hitran_case states (e.g. an HDcs object) state = CaseClass(molec_id=molec_id, local_iso_id=local_iso_id, global_iso_id=global_iso_id, E=E, g=g, s_qns=s_qns) # retrieve the correct Iso object for this isotopologue iso = isos[local_iso_id-1] # this_state is a hitranlbl.State object for the MySQL database this_state = State(iso=iso, energy=state.E, g=state.g, s_qns=state.s_qns, qns_xml=state.get_qns_xml()) if not args.dry_run: # if we're doing it for real, save the State just created this_state.save() states.append(this_state) # now create the quantum numbers entries for this state case = cases_list[state.__class__.caseID] # loop over all the possible quantum number names for this case # XXX this will fail to include all of the quantum numbers if # the case does not have the right quantum numbers in its # ordered_qn_list (e.g. asymcs currently only goes to v12...) for qn_name in state.__class__.ordered_qn_list: # get the value of this quantum number qn_val = state.get(qn_name) if qn_val is None: # if the quantum number isn't defined, move to the next one continue # get any attribute metadata for this quantum number qn_attr = state.serialize_qn_attrs(qn_name) if qn_attr: # strip the initial '#' qn_attr = qn_attr[1:] else: qn_attr = None # get the XML for this quantum number xml = state.get_qn_xml(qn_name) if not xml: xml = None # create the quantum number object ... qn = Qns(case=case, state=this_state, qn_name=qn_name, qn_val=str(qn_val), qn_attr=qn_attr, xml=xml) if not args.dry_run: # ... and save it to the database if we're not on a dry run qn.save() end_time = time.time() vprint('%d states read in (%s)' % (len(states), timed_at(end_time - start_time))) return states
corrections_file = os.path.join(DATA_DIR, '%s.corrections' % filestem) states = [] for line in open(states_file, 'r'): global_iso_id = int(line[:4]) molec_id, local_iso_id = hitran_ids[global_iso_id] try: E = float(line[5:15]) except (TypeError, ValueError): E = None try: g = int(line[16:21]) except (TypeError, ValueError): g = None s_qns = line[22:].strip() CaseClass = hitran_meta.get_case_class(molec_id, local_iso_id, s_qns[15]) states.append(CaseClass(molec_id=molec_id, local_iso_id=local_iso_id, global_iso_id=global_iso_id, E=E, g=g, s_qns=s_qns)) print '%d states read in.' % (len(states)) def get_state(stateID): """ Get the state with ID stateID - if this is greater than or equal to stateID_offset (ie its ID is higher than the highest already in the database), then it is a new state and we expect to find it in our states[] list. If it is less than stateID_offset, we need to retrieve it from the database. """ if stateID < stateID_offset: