def save_qn(qns, qn_name, qn_str): """ Store the value of qn_str to the dictionary qns under the key qn_name. If qn_str can be evaluated as an integer, do that; if not, try float, and if that fails, don't store anything. Return whatever was stored if the conversion was successful and None otherwise. """ qn = xn_utils.str_to_num(qn_str) if qn is not None: qns[qn_name] = qn return qn return None
for key, t in trans_dict.items(): try: line = lines[key] except KeyError: print 'Missing transition from input file:\n%s' % key pass #sys.exit(1) vp = 2; vpp = 0 Jpp = int(t.statepp.qns_set.get(qn_name='J').qn_val) Jp = int(t.statep.qns_set.get(qn_name='J').qn_val) vp = int(t.statep.qns_set.get(qn_name='v').qn_val) s_Wair = s_Yair = s_Wself = s_Yself = None try: s_Wair = xn_utils.str_to_num(line[91:99]) except IndexError: pass try: s_Yair = xn_utils.str_to_num(line[99:107]) except IndexError: pass try: s_Wself = xn_utils.str_to_num(line[116:124]) except IndexError: pass try: s_Yself = xn_utils.str_to_num(line[124:132]) except IndexError: pass
break branch_label = line[1] DeltaJ = branch[branch_label] Jpp = int(line[2:4]) s_qnspp = 'ElecStateLabel=X;v=0;J=%d' % Jpp Jp = Jpp + DeltaJ s_qnsp = 'ElecStateLabel=X;v=2;J=%d' % Jp statespp = State.objects.filter(iso=iso).filter(s_qns=s_qnspp) statesp = State.objects.filter(iso=iso).filter(s_qns=s_qnsp) trans = Trans.objects.filter(iso=iso).filter(valid_to='3000-01-01')\ .filter(statep__in=statesp).filter(statepp__in=statespp)\ .get() trans_id = trans.id print trans_id, trans.nu, trans.statep.s_qns, '<-', trans.statepp.s_qns # parse the line from the 12CO-file.txt file nu = HITRANParam(xn_utils.str_to_num(line[4:17]), relative=False, source_id=723) Sw = HITRANParam(xn_utils.str_to_num(line[23:32]), relative=False, source_id=723) gamma_self = HITRANParam(xn_utils.str_to_num(line[36:43]), xn_utils.str_to_num(line[45:52]), relative=True, source_id=723) gamma_self.err = xn_utils.str_to_num(line[45:52]) n_self = HITRANParam(xn_utils.str_to_num(line[52:59]), xn_utils.str_to_num(line[59:66]), relative=True, source_id=723) n_self.err = xn_utils.str_to_num(line[59:66]) delta_self = HITRANParam(xn_utils.str_to_num(line[68:77]), xn_utils.str_to_num(line[80:89]), relative=False, source_id=723)