def readCloud(self,cloudFile=None,numHeaderLines=None,Cldict=None,verbose=False): """Reads in cloud data if we have it...""" if cloudFile == None: cloudFile=self.config.cloudFile if Cldict == None: Cldict = self.config.Cl if cloudFile == 'batch': self.batch = True return 0 else: self.batch = False cloudFile = os.path.join(self.config.path,cloudFile) if numHeaderLines is None: numHeaderLines = self.config.cloudFileHdr print 'Reading '+cloudFile+' (Header: '+str(numHeaderLines)+')' self.cloud = [] print '\tUsing cloud component: ', for k in Cldict: print k+' ', self.cloud.append([]) self.nParticulate = len(Cldict) try: fp = open(cloudFile,"r") except IOError: print cloudFile+' was not found - returning no clouds\n\n' raise IOError i=0 lineno = 0 pastHeader = False print ' ' for line in fp: lineno+=1 if line[0]=='!' or lineno<=numHeaderLines: if verbose: print '\tHEADER: '+line, continue pastHeader = True if len(line) < 3: if pastHeader: break else: continue data = line.split() if i==0: print '\tReading '+str(self.nParticulate)+' cloud particles (data-file: '+str(len(data))+')' for n in range(self.nParticulate): ## Initialize all of the particulates to 0.0 self.cloud[n].append(0.0) columns = Cldict.values() columns.sort() for n,v in enumerate(columns): ## ...now read in data if v < len(data): self.cloud[n][i] = float(data[v]) else: self.cloud[n][i] = 0.0 if (self.nParticulate-n)!=1: print 'line '+str(i+1)+' has incorrect number of particulates' print '['+line+']' i+=1 self.nCloud = i ###Redo the particulate dictionary for the self.cloud index positions nid,sk = utils.invertDictionary(Cldict) for i,k in enumerate(sk): Cldict[nid[k]] = i self.config.Cl = Cldict print '\tRead '+str(self.nCloud)+' lines' fp.close() self.cloud = np.array(self.cloud) ### Check that P is monotonically increasing monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']])>0.0) if not monotonic: self.cloud = np.fliplr(self.cloud) monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']])>0.0) if not monotonic: print "Error in "+cloudFile+". Pressure not monotonically increasing" self.cloud[self.config.Cl['DZ']] = np.abs(np.append(np.diff(self.cloud[self.config.Cl['Z']]),0.0)) return self.nCloud
def readGas(self,gasFile=None,numHeaderLines=None,Cdict=None,verbose=False): """Reads gas profile file as self.gas""" if gasFile is None: gasFile=self.config.gasFile if Cdict is None: Cdict = self.config.C if gasFile == 'batch': self.batch = True return 0 else: self.batch = False gasFile = os.path.join(self.config.path,gasFile) if numHeaderLines is None: numHeaderLines = self.config.gasFileHdr print 'Reading '+gasFile+' (Header: '+str(numHeaderLines)+')' self.gas = [] print '\tUsing atmsopheric component: ', for k in Cdict: print k+' ', self.gas.append([]) self.nConstituent = len(Cdict) try: fp = open(gasFile,"r") except IOError: print gasFile+' was not found - returning no gas profile\n\n' raise IOError i=0 lineno = 0 pastHeader = False print ' ' for line in fp: lineno+=1 data = line.split() skip_row = line[0]=='!' or len(data) < 4 or lineno<=numHeaderLines ######put in something to eliminate the need for numHeaderLines.......... if skip_row: if verbose: print '\tHEADER: '+line, continue pastHeader = True if len(line) < 3: if pastHeader: break else: continue if i==0: print '\tCompiling '+str(self.nConstituent)+' components (data-file: '+str(len(data))+')' for n in range(self.nConstituent): ## Initialize all of the constituents to 0.0 self.gas[n].append(0.0) columns = Cdict.values() columns.sort() for n,v in enumerate(columns): ## ...now read in data if v < len(data): self.gas[n][i] = float(data[v]) else: self.gas[n][i] = 0.0 if (self.nConstituent-n)!=1: print 'line '+str(i+1)+' has incorrect number of components' print '['+line+']' i+=1 self.nGas = i ###Redo the constituent dictionary for the self.gas index positions nid,sk = utils.invertDictionary(Cdict) for i,k in enumerate(sk): Cdict[nid[k]] = i self.config.C = Cdict print '\tRead '+str(self.nGas)+' lines' fp.close() self.gas = np.array(self.gas) ### Check that P is monotonically increasing monotonic = np.all(np.diff(self.gas[self.config.C['P']])>0.0) if not monotonic: self.gas = np.fliplr(self.gas) monotonic = np.all(np.diff(self.gas[self.config.C['P']])>0.0) if not monotonic: print "Error in "+gasFile+". Pressure not monotonically increasing" ### Renormalize so that deepest z is 0 zDeep = self.gas[self.config.C['Z']][-1] if abs(zDeep) > 1E-6: for i in range(len(self.gas[self.config.C['Z']])): self.gas[self.config.C['Z']][i]-=zDeep print 'Deepest levels set from %.1f to 0' % (zDeep) ### Set dz dz = np.abs(np.diff(self.gas[self.config.C['Z']]))*1.0E5 #convert from km to cm (so no unit checking!!!) self.gas[self.config.C['DZ']] = np.append(np.array([0.0]),dz) return self.nGas
def readCloud(self, cloudFile=None, Cldict=None): """Reads in cloud data if we have it...""" if cloudFile is None: cloudFile = self.config.cloudFile if Cldict is None: Cldict = self.config.Cl if cloudFile == 'batch': self.batch_mode = True return 0 else: self.batch_mode = False cloudFile = os.path.join(self.config.path, cloudFile) if self.verbose: print('Reading clouds from {}'.format(cloudFile)) print('\tUsing cloud components: ', end='') self.cloud = [] value_sorted_Cldict_keys = sorted(Cldict, key=lambda k: Cldict[k]) for k in value_sorted_Cldict_keys: self.cloud.append([]) if self.verbose: print(k, ' ', end='') self.nParticulate = len(Cldict.keys()) try: fp = open(cloudFile, "r") except IOError: print(cloudFile, ' was not found - returning no clouds\n\n') raise IOError if self.verbose: print(' ') expected_number = utils.get_expected_number_of_entries(fp) for line in fp: cval = utils.get_data_from(line) if cval is None or len(cval) != expected_number: continue for n in range(self.nParticulate): # Initialize all of the particulates to 0.0 if n < len(cval): self.cloud[n].append(cval[n]) else: self.cloud[n].append(0.0) self.nCloud = len(self.cloud[0]) # ##Redo the particulate dictionary for the self.cloud index positions nid, sk = utils.invertDictionary(Cldict) for i, k in enumerate(sk): Cldict[nid[k]] = i self.config.Cl = Cldict if self.verbose: print('\tRead ', str(self.nCloud), ' lines') fp.close() self.cloud = np.array(self.cloud) # ## Check that P is monotonically increasing monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']]) > 0.0) if not monotonic: self.cloud = np.fliplr(self.cloud) monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']]) > 0.0) if not monotonic: print("Error in ", cloudFile) raise ValueError("Pressure not monotonically increasing") # ## Renormalize so that deepest z is 0 and set DZ self.renorm_z('cloud') return self.nCloud
def readGas(self, gasFile=None, Cdict=None): """Reads gas profile file as self.gas""" if gasFile is None: gasFile = self.config.gasFile if Cdict is None: Cdict = self.config.C if gasFile == 'batch': self.batch_mode = True return 0 else: self.batch_mode = False gasFile = os.path.join(self.config.path, gasFile) if self.verbose: print('Reading constituents from {}'.format(gasFile)) print('\tUsing atmsopheric component: ', end='') self.gas = [] value_sorted_Cdict_keys = sorted(Cdict, key=lambda k: Cdict[k]) for k in value_sorted_Cdict_keys: self.gas.append([]) if self.verbose: print(k + ' ', end='') self.nConstituent = len(Cdict) try: fp = open(gasFile, "r") except IOError: print(gasFile + ' was not found - returning no gas profile\n\n') raise IOError if self.verbose: print(' ') expected_number = utils.get_expected_number_of_entries(fp) for line in fp: cval = utils.get_data_from(line) if cval is None or len(cval) != expected_number: continue for n in range(self.nConstituent): if n < len(cval): self.gas[n].append(cval[n]) else: self.gas[n].append(0.0) self.nGas = len(self.gas[0]) # ##Redo the constituent dictionary for the self.gas index positions nid, sk = utils.invertDictionary(Cdict) for i, k in enumerate(sk): Cdict[nid[k]] = i self.config.C = Cdict if self.verbose: print('\tRead ' + str(self.nGas) + ' lines') fp.close() self.gas = np.array(self.gas) # ## Check that P is monotonically increasing monotonic = np.all(np.diff(self.gas[self.config.C['P']]) > 0.0) if not monotonic: self.gas = np.fliplr(self.gas) monotonic = np.all(np.diff(self.gas[self.config.C['P']]) > 0.0) if not monotonic: print("Error in ", gasFile) raise ValueError("Pressure not monotonically increasing.") # ## Renormalize so that deepest z is 0 and set DZ self.renorm_z('gas') return self.nGas
def readCloud(self, cloudFile=None, Cldict=None): """Reads in cloud data if we have it...""" if cloudFile is None: cloudFile = self.config.cloudFile if Cldict is None: Cldict = self.config.Cl if cloudFile == 'batch': self.batch_mode = True return 0 else: self.batch_mode = False cloudFile = os.path.join(self.config.path, cloudFile) if self.verbose: print('Reading clouds from {}'.format(cloudFile)) print('\tUsing cloud components: ', end='') self.cloud = [] for k in Cldict: self.cloud.append([]) if self.verbose: print(k, ' ', end='') self.nParticulate = len(Cldict.keys()) try: fp = open(cloudFile, "r") except IOError: print(cloudFile, ' was not found - returning no clouds\n\n') raise IOError if self.verbose: print(' ') expected_number = utils.get_expected_number_of_entries(fp) for line in fp: cval = utils.get_data_from(line) if cval is None or len(cval) != expected_number: continue for n in range(self.nParticulate ): # Initialize all of the particulates to 0.0 if n < len(cval): self.cloud[n].append(cval[n]) else: self.cloud[n].append(0.0) self.nCloud = len(self.cloud[0]) # ##Redo the particulate dictionary for the self.cloud index positions nid, sk = utils.invertDictionary(Cldict) for i, k in enumerate(sk): Cldict[nid[k]] = i self.config.Cl = Cldict if self.verbose: print('\tRead ', str(self.nCloud), ' lines') fp.close() self.cloud = np.array(self.cloud) # ## Check that P is monotonically increasing monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']]) > 0.0) if not monotonic: self.cloud = np.fliplr(self.cloud) monotonic = np.all(np.diff(self.cloud[self.config.Cl['P']]) > 0.0) if not monotonic: print("Error in ", cloudFile) raise ValueError("Pressure not monotonically increasing") # ## Renormalize so that deepest z is 0 and set DZ self.renorm_z('cloud') return self.nCloud
def readGas(self, gasFile=None, Cdict=None): """Reads gas profile file as self.gas""" if gasFile is None: gasFile = self.config.gasFile if Cdict is None: Cdict = self.config.C if gasFile == 'batch': self.batch_mode = True return 0 else: self.batch_mode = False gasFile = os.path.join(self.config.path, gasFile) if self.verbose: print('Reading constituents from {}'.format(gasFile)) print('\tUsing atmsopheric component: ', end='') self.gas = [] for k in Cdict: self.gas.append([]) if self.verbose: print(k + ' ', end='') self.nConstituent = len(Cdict) try: fp = open(gasFile, "r") except IOError: print(gasFile + ' was not found - returning no gas profile\n\n') raise IOError if self.verbose: print(' ') expected_number = utils.get_expected_number_of_entries(fp) for line in fp: cval = utils.get_data_from(line) if cval is None or len(cval) != expected_number: continue for n in range(self.nConstituent): if n < len(cval): self.gas[n].append(cval[n]) else: self.gas[n].append(0.0) self.nGas = len(self.gas[0]) # ##Redo the constituent dictionary for the self.gas index positions nid, sk = utils.invertDictionary(Cdict) for i, k in enumerate(sk): Cdict[nid[k]] = i self.config.C = Cdict if self.verbose: print('\tRead ' + str(self.nGas) + ' lines') fp.close() self.gas = np.array(self.gas) # ## Check that P is monotonically increasing monotonic = np.all(np.diff(self.gas[self.config.C['P']]) > 0.0) if not monotonic: self.gas = np.fliplr(self.gas) monotonic = np.all(np.diff(self.gas[self.config.C['P']]) > 0.0) if not monotonic: print("Error in ", gasFile) raise ValueError("Pressure not monotonically increasing.") # ## Renormalize so that deepest z is 0 and set DZ self.renorm_z('gas') return self.nGas