Skip to content
Snippets Groups Projects
Commit 8cec38fa authored by Paolo Veglio's avatar Paolo Veglio
Browse files

changes to improve speed, pt.2

parent a5c2abc7
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,9 @@ def create_index(self):
latidx[idx] = 0
idx = np.where(lonidx < 0)
lonidx[idx] = 0
self.edges = [np.min(lonidx), np.max(lonidx),
np.min(latidx), np.max(latidx)]
# THIS PART WAS DEFINED FOR THE EQUAL_AREA PROJECTION
# WHENEVER WE BELIEVE WE ARE READY TO MOVE BACK TO IT
# WE CAN POSSIBLY START FROM HERE
......@@ -226,7 +228,7 @@ def compute_2D_histogram(self, var1, var2, binvec1, binvec2, varname, var_name_o
if (len(xx) > 0) & (len(yy) > 0):
var2Dstat[self.srt_idx[self.box_idx[i]], :, :] = (
np.histogram2d(xx, yy, (binvec1, binvec2))[0])
np.histogram2d(xx, yy, bins=(binvec1, binvec2))[0])
elif ((len(xx) == 0) | (len(yy) == 0)):
var2Dstat[self.srt_idx[self.box_idx[i]], :, :] = np.nan
else:
......
......@@ -7,7 +7,7 @@
from pkg_resources import get_distribution
import yori.ioutils as iou
import yori.new_ioutils as iou
import yori.gridtools as grid
import yori.config_reader as cfg
......@@ -134,7 +134,7 @@ def runYori(self, debug=False, compression=0):
lat = data_in[self.lat_key][:]
lon = data_in[self.lon_key][:]
myGrid = grid.ComputeVariables(lat, lon, self.grid_size, self.grid_proj, self.fv)
for i in range(len(self.ymlSet.var_settings)):
var_settings = self.ymlSet.var_settings[i]
......@@ -144,7 +144,6 @@ def runYori(self, debug=False, compression=0):
only_hist = True
masked_data_in, var_name_out = self.setVariable(var_settings, lat, data_in)
myGrid = grid.ComputeVariables(lat, lon, self.grid_size, self.grid_proj, self.fv)
if only_hist is False:
tmp_gridvar = myGrid.compute_stats(masked_data_in, var_name_out)
......@@ -172,7 +171,7 @@ def runYori(self, debug=False, compression=0):
if debug is False:
write_output(self.output_file, gridvar, compression,
self.grid_size, self.ymlSet, self.fv)
self.grid_size, self.ymlSet, self.fv, edges=myGrid.edges)
else:
for k in gridvar.keys():
......@@ -187,8 +186,8 @@ def callYori(config_file, input_file, output_file, debug=False, compression=0):
Yori.runYori(debug, compression)
def write_output(output_file, gridvar, compression, grid_size, ymlSet, fv):
outInst = iou.CreateMatchfile(output_file, gridvar, comp=compression)
def write_output(output_file, gridvar, compression, grid_size, ymlSet, fv, edges=[]):
outInst = iou.CreateMatchfile(output_file, gridvar, comp=compression, edges=edges)
outInst.createFile()
fout = nc.Dataset(output_file, mode='a')
......@@ -197,14 +196,15 @@ def write_output(output_file, gridvar, compression, grid_size, ymlSet, fv):
fout.setncattr('YAML_config', ymlSet.yaml_str)
fout.setncattr('Yori_version', str(VERSION))
fout.close()
# fout.close()
for k in list(gridvar):
if k.split('/')[-1] == 'Pixel_Counts' or gridvar[k].ndim > 2:
outInst.saveNewVar(k, fillvalue=fv, vartype='i4')
outInst.saveNewVar(fout, gridvar, k, fillvalue=fv, vartype='i4')
else:
outInst.saveNewVar(k, fillvalue=fv)
outInst.saveNewVar(fout, gridvar, k, fillvalue=fv)
fout.close()
fout = nc.Dataset(output_file, mode='a')
for settings in ymlSet.var_settings:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment