def main(): print '\nAscii Table test\n' a=ascii_table('c12pg.dat','ascii') initTest(a) dataTest(a) ''' keys=a.dcols.keys() for i in range(len(keys)): print keys[i] #print a.dcols[keys[i]] a.plot('upper','T9',plotType='ATable', shape='-') a.plot('upper','ado/CA88',plotType='ATable', shape='-') a.plot('CA88','ado/fit',plotType='ATable', shape='-') ''' a=ascii_table('c12.dat','ascii',sep=';') initTest(a) dataTest(a) '''
def run(self): self.cycles.extend(self.h5s[0].cycle) self.ages.extend(self.h5s[0].age) self.hattrs = self.h5s[0].hattr self.cattrs = self.h5s[0].cattr self.Tables = self.h5s[0].Table self.dcols = self.h5s[0].dcol self.cycle_header = self.h5s[ 0].cycle_header #This string handles the name of the cycle try: self.A = self.h5s[0].A[0] except IndexError: print "Sorry, there is no A vector. This can cause problems for reading abundances. Continue..." try: self.Z = self.h5s[0].Z[0] except IndexError: print "Sorry, there is no Z vector. This can cause problems for reading abundances. Continue... " try: self.isomeric_states = self.h5s[0].isomeric_state[0] except IndexError: print "Sorry, there is no isomeric state vector. Continue..." new = self.h5s[ 0].new # This boolean handles the changes to the cycle nomenclature format if self.filename.endswith(os.sep): b = str(self.filename) + str(self.preprocName) else: b = str(self.filename) + os.sep + str(self.preprocName) if self.preprocExists: preprocTable = ascii_table(self.preprocName, self.filename) if int(preprocTable.hattrs[0]) < len(self.h5files): self.preprocExists = False print 'A File was added, rewriteing preprocessor file' if self.preprocExists: for i in xrange(len(self.h5files)): if os.path.basename( self.h5files[i] ) + '-cyc' not in preprocTable.dcols and self.preprocExists: print 'A File was renamed, rewriteing preprocessor file' print preprocTable.dcols[i], os.path.basename( self.h5files[i]) + '-cyc' self.preprocExists = False if not self.preprocExists and os.path.exists(b): os.system('rm ' + b) # create list of isotopes stored in this h5 file try: for x in xrange(len(self.Tables[0])): if self.isomeric_states[x] == 1: self.isotopes.append(self.isos[int(self.Tables[1][x])] + '-' + str(int(self.Tables[0][x]))) else: self.isotopes.append(self.isos[int(self.Tables[1][x])]+'-' +str(int(self.Tables[0][x]))+\ self.isomerDelimiter+str(self.isomeric_states[x]-1)) except IndexError: print 'This file does not contain any tables. Isotopic data must be contained elsewhere.' t1 = time.time() # create list of elements stored in this h5 file asaved = '' for atmp in self.Z: if atmp != asaved: self.elements.append(self.isos[int(atmp)]) asaved = atmp thread_list = [] print(self.h5s[0].filename) for x in xrange(len(self.h5files) - 1): thread_list.append( self.h5s.append(h5File(self.h5files[x + 1], False, new))) print(self.h5s[x + 1].filename) if not self.preprocExists: self.h5s[x + 1].start() self.h5s[x + 1].join() self.h5sStarted[x + 1] = True #self.h5s[x+1].run() #print('Active '+ str(threading.active_count())) # Wait until the threads are done. #for thread in self.h5s: # print(thread) # thread.join() if not self.preprocExists: for x in xrange(len(self.h5files) - 1): self.cycles.extend(self.h5s[x + 1].cycle) self.ages.extend(self.h5s[x + 1].age) header=[str(len(self.h5files)),'This is a preprocessor file for the directory: '+str(self.filename),\ 'At the time of the creation of this file there were '+str(len(self.h5files))+\ ' h5 files.'] try: self.cycles = sorted(self.cycles, cmp=self.numeric_compare) except TypeError: print "There was a problem sorting the cycles. You may have problems later. Please consider reloading(h5T) and trying again" try: self.ages = sorted(self.ages, cmp=self.numeric_compare) except TypeError: None print 'Writeing preprocessor files' data = [] dcols = [] length = 0 for i in xrange(len(self.h5s)): print self.h5s[i].filename.rpartition('/')[2] dcols.append(os.path.basename(self.h5s[i].filename) + '-cyc') dcols.append(os.path.basename(self.h5s[i].filename) + '-age') data.append(self.h5s[i].cycle) data.append(self.h5s[i].age) if len(self.h5s[i].cycle) > length: length = len(self.h5s[i].cycle) if len(self.h5s[i].age) > length: length = len(self.h5s[i].age) for i in xrange(len(data)): for j in xrange(length - len(data[i])): data[i].append(3.14159265) write(self.preprocName, header, dcols, data, sldir=self.filename) else: print 'Reading preprocessor files' preprocTable = ascii_table(self.preprocName, self.filename) for i in xrange(len(self.h5s) - 1): dat = preprocTable.get( os.path.basename(self.h5s[i + 1].filename) + '-cyc') dat1 = [] for j in xrange(len(dat)): if dat[j] != 3.14159265: dat1.append(dat[j]) dat = dat1 for j in xrange(len(dat)): dat[j] = str(int(dat[j])) for k in xrange(10 - len(dat[j])): dat[j] = '0' + dat[j] for j in xrange(len(dat)): self.cycles.append(dat[j]) self.h5s[i + 1].cycle = dat dat = preprocTable.get( os.path.basename(self.h5s[i + 1].filename) + '-age') dat1 = [] for j in xrange(len(dat)): if dat[j] != 3.14159265: dat1.append(dat[j]) dat = dat1 self.h5s[i + 1].age = dat for j in xrange(len(dat)): self.ages.append(dat[j]) try: self.cycles = sorted(self.cycles, cmp=self.numeric_compare) except TypeError: print "There was a problem sorting the cycles. You may have problems later. Please consider reloading(h5T) and trying again" try: self.ages = sorted(self.ages, cmp=self.numeric_compare) except TypeError: None print 'File search complete.' t2 = time.time() print "Total duration is " + str(t2 - t1) + " seconds." return
def all_done(self): if debug: print "all done" if not self.preprocExists: for x in xrange(len(self.h5s)): print len(self.h5s[x].cycle) print len(self.h5s[x].age) for x in xrange(len(self.h5s)-1): self.cycles.extend(self.h5s[x+1].cycle) self.ages.extend(self.h5s[x+1].age) print len(self.ages) print len(self.cycles) header=[str(len(self.h5s)),'This is a preprocessor file for the directory: '+str(self.filepath),\ 'At the time of the creation of this file there were '+str(len(self.h5files))+\ ' h5 files.'] self.cycles = sorted(self.cycles, cmp=self.numeric_compare) #self.cycles = sorted(self.cycles, cmp=self.numeric_compare) """ for cycle in self.cycles: print cycle try: #self.ages = self.get(self.cycles,'age',1) except IndexError: print 'enountered error fetching age' """ #self.ages = sorted(self.ages, cmp=self.numeric_compare) self.textEdit.append('File search complete. You may begin plotting') print 'Writeing preprocessor files' data=[] dcols=[] length=0 for i in xrange(len(self.h5s)): dcols.append(self.h5s[i].filename+'-cyc') dcols.append(self.h5s[i].filename+'-age') data.append(self.h5s[i].cycle) data.append(self.h5s[i].age) if len(self.h5s[i].cycle)>length: length=len(self.h5s[i].cycle) if len(self.h5s[i].age)>length: length=len(self.h5s[i].age) for i in xrange(len(data)): for j in xrange(length-len(data[i])): data[i].append(3.14159265) #identifier number write(self.preprocName,header,dcols,data,sldir=self.filepath) else: print 'Reading preprocessor files' preprocTable=ascii_table(self.preprocName,self.filepath) for i in xrange(len(self.h5s)-1): print self.h5s[i+1].filename dat=preprocTable.get(self.h5s[i+1].filename+'-cyc') dat1=[] for j in xrange(len(dat)): if dat[j]!=3.14159265: dat1.append(dat[j]) dat=dat1 for j in xrange(len(dat)): dat[j]=str(int(dat[j])) for k in xrange(10-len(dat[j])): dat[j]='0'+dat[j] for j in xrange(len(dat)): self.cycles.append(dat[j]) self.h5s[i+1].cycle=dat dat=preprocTable.get(self.h5s[i+1].filename+'-age') dat1=[] for j in xrange(len(dat)): if dat[j]!=3.14159265: dat1.append(dat[j]) dat=dat1 self.h5s[i+1].age=dat for j in xrange(len(dat)): self.ages.append(dat[j]) try: self.cycles = sorted(self.cycles, cmp=self.numeric_compare) except TypeError: print "There was a problem sorting the cycles. You may have problems later. Please consider reloading(h5T) and trying again" try: self.ages = sorted(self.ages, cmp=self.numeric_compare) except TypeError: None print self.h5sStarted t2=t.time() print "Time: "+str(t2-self.t1)
def run(self): self.cycles.extend(self.h5s[0].cycle) self.ages.extend(self.h5s[0].age) self.hattrs = self.h5s[0].hattr self.cattrs = self.h5s[0].cattr self.Tables = self.h5s[0].Table self.dcols = self.h5s[0].dcol self.cycle_header = self.h5s[0].cycle_header #This string handles the name of the cycle try: self.A = self.h5s[0].A[0] except IndexError: print "Sorry, there is no A vector. This can cause problems for reading abundances. Continue..." try: self.Z = self.h5s[0].Z[0] except IndexError: print "Sorry, there is no Z vector. This can cause problems for reading abundances. Continue... " try: self.isomeric_states = self.h5s[0].isomeric_state[0] except IndexError: print "Sorry, there is no isomeric state vector. Continue..." new = self.h5s[0].new # This boolean handles the changes to the cycle nomenclature format if self.filename.endswith(os.sep): b = str(self.filename)+str(self.preprocName) else: b = str(self.filename)+os.sep+str(self.preprocName) if self.preprocExists: preprocTable=ascii_table(self.preprocName,self.filename) if int(preprocTable.hattrs[0])<len(self.h5files): self.preprocExists=False print 'A File was added, rewriteing preprocessor file' if self.preprocExists: for i in xrange(len(self.h5files)): if os.path.basename(self.h5files[i])+'-cyc' not in preprocTable.dcols and self.preprocExists: print 'A File was renamed, rewriteing preprocessor file' print preprocTable.dcols[i], os.path.basename(self.h5files[i])+'-cyc' self.preprocExists=False if not self.preprocExists and os.path.exists(b): os.system('rm '+b) # create list of isotopes stored in this h5 file try: for x in xrange(len(self.Tables[0])): if self.isomeric_states[x] ==1: self.isotopes.append(self.isos[int(self.Tables[1][x])]+'-' +str(int(self.Tables[0][x]))) else: self.isotopes.append(self.isos[int(self.Tables[1][x])]+'-' +str(int(self.Tables[0][x]))+\ self.isomerDelimiter+str(self.isomeric_states[x]-1)) except IndexError: print 'This file does not contain any tables. Isotopic data must be contained elsewhere.' t1 = time.time() # create list of elements stored in this h5 file asaved='' for atmp in self.Z: if atmp != asaved: self.elements.append(self.isos[int(atmp)]) asaved=atmp thread_list = [] print(self.h5s[0].filename) for x in xrange(len(self.h5files)-1): thread_list.append(self.h5s.append(h5File(self.h5files[x+1],False, new))) print(self.h5s[x+1].filename) if not self.preprocExists: self.h5s[x+1].start() self.h5s[x+1].join() self.h5sStarted[x+1]=True #self.h5s[x+1].run() #print('Active '+ str(threading.active_count())) # Wait until the threads are done. #for thread in self.h5s: # print(thread) # thread.join() if not self.preprocExists: for x in xrange(len(self.h5files)-1): self.cycles.extend(self.h5s[x+1].cycle) self.ages.extend(self.h5s[x+1].age) header=[str(len(self.h5files)),'This is a preprocessor file for the directory: '+str(self.filename),\ 'At the time of the creation of this file there were '+str(len(self.h5files))+\ ' h5 files.'] try: self.cycles = sorted(self.cycles, cmp=self.numeric_compare) except TypeError: print "There was a problem sorting the cycles. You may have problems later. Please consider reloading(h5T) and trying again" try: self.ages = sorted(self.ages, cmp=self.numeric_compare) except TypeError: None print 'Writeing preprocessor files' data=[] dcols=[] length=0 for i in xrange(len(self.h5s)): print self.h5s[i].filename.rpartition('/')[2] dcols.append(os.path.basename(self.h5s[i].filename)+'-cyc') dcols.append(os.path.basename(self.h5s[i].filename)+'-age') data.append(self.h5s[i].cycle) data.append(self.h5s[i].age) if len(self.h5s[i].cycle)>length: length=len(self.h5s[i].cycle) if len(self.h5s[i].age)>length: length=len(self.h5s[i].age) for i in xrange(len(data)): for j in xrange(length-len(data[i])): data[i].append(3.14159265) write(self.preprocName,header,dcols,data,sldir=self.filename) else: print 'Reading preprocessor files' preprocTable=ascii_table(self.preprocName,self.filename) for i in xrange(len(self.h5s)-1): dat=preprocTable.get(os.path.basename(self.h5s[i+1].filename)+'-cyc') dat1=[] for j in xrange(len(dat)): if dat[j]!=3.14159265: dat1.append(dat[j]) dat=dat1 for j in xrange(len(dat)): dat[j]=str(int(dat[j])) for k in xrange(10-len(dat[j])): dat[j]='0'+dat[j] for j in xrange(len(dat)): self.cycles.append(dat[j]) self.h5s[i+1].cycle=dat dat=preprocTable.get(os.path.basename(self.h5s[i+1].filename)+'-age') dat1=[] for j in xrange(len(dat)): if dat[j]!=3.14159265: dat1.append(dat[j]) dat=dat1 self.h5s[i+1].age=dat for j in xrange(len(dat)): self.ages.append(dat[j]) try: self.cycles = sorted(self.cycles, cmp=self.numeric_compare) except TypeError: print "There was a problem sorting the cycles. You may have problems later. Please consider reloading(h5T) and trying again" try: self.ages = sorted(self.ages, cmp=self.numeric_compare) except TypeError: None print 'File search complete.' t2 = time.time() print "Total duration is " + str(t2-t1) + " seconds." return
def continue_h5s(self): #tis is equivilent to the run in h5t.py if debug: print "continue_h5s" self.cycles.extend(self.h5s[0].cycle) self.ages.extend(self.h5s[0].age) self.hattrs = self.h5s[0].hattr self.cattrs = self.h5s[0].cattr self.Tables = self.h5s[0].Table self.dcols = self.h5s[0].dcol self.cycle_header = self.h5s[0].cycle_header #This string handles the name of the cycle new = self.h5s[0].new # This boolean handles the changes to the cycle nomenclature format #preproc stuff if self.filepath.endswith(os.sep): b = str(self.filepath)+self.preprocName else: b = str(self.filepath)+os.sep+self.preprocName if self.preprocExists: preprocTable=ascii_table(self.preprocName,self.filepath) if int(preprocTable.hattrs[0])<len(self.h5files): self.preprocExists=False print 'A File was added, rewriteing preprocessor file' if self.preprocExists: for i in xrange(len(self.h5files)): if self.h5files[i]+'-cyc' not in preprocTable.dcols and self.preprocExists: print 'A File was renamed, rewriteing preprocessor file' self.preprocExists=False if not self.preprocExists and os.path.exists(b): os.system('rm '+b) # create list of isotopes stored in this h5 file try: for x in xrange(len(self.Tables[0])): self.isotopes.append([self.isos[int(self.Tables[1][x])],str(int(self.Tables[0][x]))]) #print 'new file: ', new, self.isotopes except IndexError: print self.Tables, self.h5s[0].Table self.t1 = t.time() print "continueing" if len(self.filepaths) > 1: for x in range(len(self.filepaths)-1): self.h5s.append(h5File(self.filepaths[x+1],False, new)) if not self.preprocExists: self.h5sStarted[x+1]=True self.h5s[-1].start() self.connect(self.h5s[-1], qc.SIGNAL('finished()'), self.add_data) if not self.preprocExists: print "all done?" self.connect(self, qc.SIGNAL('finished()'), self.all_done) else: self.all_done()