comparison xarray_tool.py @ 2:e8650cdf092f draft

"planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
author ecology
date Sat, 31 Oct 2020 11:00:53 +0000
parents 7edbe5ae8b72
children 663268794710
comparison
equal deleted inserted replaced
1:7edbe5ae8b72 2:e8650cdf092f
82 f = open(self.outfile_summary, 'w') 82 f = open(self.outfile_summary, 'w')
83 ds = xr.open_dataset(self.infile) 83 ds = xr.open_dataset(self.infile)
84 writer = csv.writer(f, delimiter='\t') 84 writer = csv.writer(f, delimiter='\t')
85 header = ['VariableName', 'NumberOfDimensions'] 85 header = ['VariableName', 'NumberOfDimensions']
86 for idx, val in enumerate(ds.dims.items()): 86 for idx, val in enumerate(ds.dims.items()):
87 header.append('Dim'+str(idx)+'Name') 87 header.append('Dim' + str(idx) + 'Name')
88 header.append('Dim'+str(idx)+'Size') 88 header.append('Dim' + str(idx) + 'Size')
89 writer.writerow(header) 89 writer.writerow(header)
90 for name, da in ds.data_vars.items(): 90 for name, da in ds.data_vars.items():
91 line = [name] 91 line = [name]
92 line.append(len(ds[name].shape)) 92 line.append(len(ds[name].shape))
93 for d, s in zip(da.shape, da.sizes): 93 for d, s in zip(da.shape, da.sizes):
111 if (op == 'bi'): 111 if (op == 'bi'):
112 rl = float(split_filter[3]) 112 rl = float(split_filter[3])
113 if filter_varname == self.select: 113 if filter_varname == self.select:
114 # filter on values of the selected variable 114 # filter on values of the selected variable
115 if op == 'bi': 115 if op == 'bi':
116 self.dset = self.dset.where((self.dset <= rl) & 116 self.dset = self.dset.where((self.dset <= rl) & (self.dset >= ll))
117 (self.dset >= ll))
118 elif op == 'le': 117 elif op == 'le':
119 self.dset = self.dset.where(self.dset <= ll) 118 self.dset = self.dset.where(self.dset <= ll)
120 elif op == 'ge': 119 elif op == 'ge':
121 self.dset = self.dset.where(self.dset >= ll) 120 self.dset = self.dset.where(self.dset >= ll)
122 elif op == 'e': 121 elif op == 'e':
205 def selection_from_coords(self): 204 def selection_from_coords(self):
206 fcoords = pd.read_csv(self.coords, sep='\t') 205 fcoords = pd.read_csv(self.coords, sep='\t')
207 for row in fcoords.itertuples(): 206 for row in fcoords.itertuples():
208 self.latvalN = row[0] 207 self.latvalN = row[0]
209 self.lonvalE = row[1] 208 self.lonvalE = row[1]
210 self.outfile = (self.outputdir + '/' + self.select + '_' 209 self.outfile = (self.outputdir + '/' + self.select + '_' + str(row.Index) + '.tabular')
211 + str(row.Index) + '.tabular')
212 self.selection() 210 self.selection()
213 211
214 212
215 if __name__ == '__main__': 213 if __name__ == '__main__':
216 warnings.filterwarnings("ignore") 214 warnings.filterwarnings("ignore")