def QueryFun(ListOpt): #print(String) List = ListOpt.copy() List.pop(0) pathfile = os.path.realpath(__file__) pathfile = pathfile.strip('query.py') conexion = OpenDatabase(pathfile) if '--all' in List: allflag = True List.remove('--all') else: allflag = False if len(List) == 2: iEner = List[0] fEner = List[1] else: print('') return 30 try: iEner = float(iEner) fEner = float(fEner) except ValueError: print('ERROR: Argument or arguments cannot be converted to float.') return 31 if iEner > fEner: iEnerAux = iEner iEner = fEner fEner = iEnerAux del iEnerAux DBInfo = EnergyRange(conexion, iEner, fEner) print('\nThe energy range consulted is %.2f keV to %.2f keV.\n' % (iEner, fEner)) if len(DBInfo) != 0: Eg, Ig, Decay, Half, Parent = [], [], [], [], [] for Ele in DBInfo: Eg.append(str(Ele[1]) + ' (' + str(Ele[2]) + ')') Ig.append(str(Ele[3]) + ' (' + str(Ele[4]) + ')') Decay.append(Ele[5]) Half.append( str(Ele[6]) + ' ' + str(Ele[7]) + ' (' + str(Ele[8]) + ')') Parent.append(Ele[10]) pd.set_option('display.max_rows', 30) #imprime todas las filas if allflag: pd.set_option('display.max_rows', None) #imprime todas las filas else: pd.set_option('display.max_rows', len(Ele)) df = pd.DataFrame(list(zip(Eg, Ig, Decay, Half, Parent)), columns=[ 'Eg [keV]', 'Ig (%)', 'Decay mode', 'Half Life', 'Parent' ]) #crea la tabla print(df) #imprime la tabla print("\n%d results were found" % (len(DBInfo))) CloseDatabase(conexion) return 0
def isotopeFun(ListOpt): pathfile = os.path.realpath(__file__) if operatingSystem == 'Linux' or operatingSystem == 'Darwin': pathfile = pathfile.replace('/modules/isotope.py', '') elif operatingSystem == 'Windows': pathfile = pathfile.replace('\\modules\\isotope.py', '') List = ListOpt.copy() List.pop(0) try: conexion = OpenDatabase(pathfile) except: sys.stderr.write( '------------------------------------------------------\n') sys.stderr.write( 'ERROR: Database cannot be read. Please, be sure that database is in the folder myDatabase.\n' ) sys.stderr.write( '------------------------------------------------------\n') return 20 for element in List: Isotope = LookForElement(conexion, element, order='ASC') if len(Isotope) == 0: print('\nThe isotope consulted is ' + element) print('The query did not give any result.') else: Eg, Ig, Decay, Half, Parent = [], [], [], [], [] for Ele in Isotope: Eg.append(str(Ele[1]) + ' (' + str(Ele[2]) + ')') Ig.append(str(Ele[3]) + ' (' + str(Ele[4]) + ')') Decay.append(Ele[5]) Half.append( str(Ele[6]) + ' ' + str(Ele[7]) + ' (' + str(Ele[8]) + ')') Parent.append(Ele[10]) pd.set_option('display.max_rows', None) df = pd.DataFrame(list(zip(Eg, Ig, Decay, Half, Parent)), columns=[ 'Eg [keV]', 'Ig (%)', 'Decay mode', 'Half Life', 'Parent' ]) #crea la tabla print('For the isotope ' + element + ' the gamma decays found are: \n') print(df) print('\n') CloseDatabase(conexion) return 0
def NormIntensity(ListOpt): pathfile = os.path.realpath(__file__) pathfile = pathfile.strip('normintensity.py') List = ListOpt.copy() List.pop(0) try: conexion = OpenDatabase(pathfile) except: print('------------------------------------------------------') print( 'ERROR: Database cannot be read. Please, be sure that database is in the folder myDatabase.' ) print('------------------------------------------------------') return 20 for element in List: Isotope = GetIntensities2(conexion, element, order='ASC') if len(Isotope) == 0: print('\nThe isotope consulted is ' + element) print('The query did not give any result.') else: Eg, Ig, IgR, Parent = [], [], [], [] for Ele in Isotope: Eg.append(str(Ele[1]) + ' (' + str(Ele[2]) + ')') Ig.append(str(Ele[3]) + ' (' + str(Ele[4]) + ')') IgR.append(str(Ele[5])) Parent.append(Ele[6]) pd.set_option('display.max_rows', None) #imprime todas las filas df = pd.DataFrame(list(zip(Eg, Ig, IgR, Parent)), columns=[ 'Eg [keV]', 'Ig (%)', 'Normalized Intensities', 'Parent' ]) #crea la tabla print('For the isotope ' + element + ' the gamma decays found are: \n') print(df) #imprime la tabla print('\n') CloseDatabase(conexion) return 0
def Parent(ListOpt): List = ListOpt.copy() List.pop(0) if len(List) == 0: print("error: --parent option needs an argument") return 400 pathfile = os.path.realpath(__file__) pathfile = pathfile.strip('isoparent.py') conexion = OpenDatabase(pathfile) for Isotope in List: MainChainIso, Child = GetChainAndChild(conexion, Isotope) if MainChainIso == None or Child == None: print('Isotope: ' + Isotope + ' -- Parent: ' + 'None' + ' --Child: ' + 'None' + '\n') print( 'There is not enough information in the database or the isotope ' + Isotope + ' do not have Child or parents isotopes. \n') else: MainChain = GetMainChain(conexion, MainChainIso) if '+' in MainChain: AuxStr = MainChain.split('+')[1] Parentiso = AuxStr.split('#')[0] else: Parentiso = MainChain[0].split('#')[0] print('Isotope: ' + Isotope + ' -- Parent: ' + Parentiso + ' --Child: ' + Child + '\n') CloseDatabase(conexion) return 0
def Parent(ListOpt): List = ListOpt.copy() List.pop(0) if len(List) == 0: sys.stderr.write("error: --parent option needs an argument\n") return 400 pathfile = os.path.realpath(__file__) if operatingSystem == 'Linux' or operatingSystem == 'Darwin': pathfile = pathfile.replace('/modules/isoparent.py','') elif operatingSystem == 'Windows': pathfile = pathfile.replace('\\modules\\isoparent.py','') conexion = OpenDatabase(pathfile) for Isotope in List: MainChainIso,Child = GetChainAndChild(conexion,Isotope) if MainChainIso == None or Child == None: print('Isotope: ' + Isotope + ' -- Parent: ' + 'None' + ' --Child: ' + 'None' + '\n') print('There is not enough information in the database or the isotope ' + Isotope + ' do not have Child or parents isotopes. \n') else: MainChain = GetMainChain(conexion,MainChainIso) if '+' in MainChain: AuxStr = MainChain.split('+')[1] Parentiso = AuxStr.split('#')[0] else: Parentiso = MainChain[0].split('#')[0] print('Isotope: ' + Isotope + ' -- Parent: ' + Parentiso + ' --Child: ' + Child + '\n') CloseDatabase(conexion) return 0
def energyFun(ListOpt): List = ListOpt.copy() List.pop(0) if '--wof' in List: wofFlag = True List.remove('--wof') else: wofFlag = False if '--all' in List: allFlag = True List.remove('--all') else: allFlag = False if len(List) == 0: print("error: --energyRanges option needs an argument") return 0 infoFile = List[0] if not os.path.isfile(infoFile): print("error: %s does not exist, are you in the right path?" % (infoFile)) return False if not infoFile.endswith('.info'): print("error: %s needs a .info extension" % (infoFile)) return False infoDict = getDictFromInfoFile(infoFile) del infoDict['Range'] idxPairL = [] for DictEle in infoDict.values(): idxPairL.append([DictEle['start'], DictEle['end']]) #Energy range of the histogram DBInfoL = [] pathfile = os.path.realpath(__file__) pathfile = pathfile.strip('energy.py') conexion = OpenDatabase(pathfile) for idxR in idxPairL: iEner = idxR[0] fEner = idxR[1] DBInfoL.append(EnergyRange(conexion, iEner, fEner)) DBInfo = DBInfoL[-1] print( '\nThe energy range consulted is between %.2f keV and %.2f keV.\n' % (iEner, fEner)) Eg, Ig, Decay, Half, Parent = [], [], [], [], [] for Ele in DBInfo: Eg.append(str(Ele[1]) + ' (' + str(Ele[2]) + ')') Ig.append(str(Ele[3]) + ' (' + str(Ele[4]) + ')') Decay.append(Ele[5]) Half.append(halfLifeUnit(Ele)) Parent.append(Ele[10]) if allFlag: pd.set_option('display.max_rows', None) else: pd.set_option('display.max_rows', len(Ele)) df = pd.DataFrame(list(zip(Eg, Ig, Decay, Half, Parent)), columns=[ 'Eg [keV]', 'Ig (%)', 'Decay mode', 'Half Life (s)', 'Parent' ]) if allFlag: print(df) else: print(df.head(10)) if wofFlag: try: myfilename = infoFile.strip('.info') + '_energyRanges.txt' WriteOutputFileRR(myfilename, df, iEner, fEner) print('-----------------------------------------') print('The file was saved as:') print(myfilename) print('-----------------------------------------') except IOError: print( 'ERROR: An unexpected error ocurrs. Data could not be saved.' ) CloseDatabase(conexion) return 0