Commit 34173698 authored by Javier Vegas-Regidor's avatar Javier Vegas-Regidor
Browse files

Fix lint

parent 79308fdf
......@@ -67,8 +67,7 @@ class Moc(Diagnostic):
def __eq__(self, other):
if self._different_type(other):
return False
return self.startdate == other.startdate and \
self.member == other.member and self.chunk == other.chunk
return self.startdate == other.startdate and self.member == other.member and self.chunk == other.chunk
@classmethod
def generate_jobs(cls, diags, options):
......@@ -136,7 +135,6 @@ class Moc(Diagnostic):
del vo, e1v, e3v
self._save_result(moc_results, mesh)
def _save_result(self, result, mesh):
temp = TempFile.get()
handler_source = Utils.open_cdf(self.variable_file.local_file)
......@@ -151,7 +149,6 @@ class Moc(Diagnostic):
handler_temp.createDimension('region', len(result))
handler_temp.createDimension('region_length', 50)
var_region = handler_temp.createVariable('region', 'S1',
('region', 'region_length'))
......
......@@ -24,6 +24,7 @@ from earthdiagnostics.utils import Utils, TempFile
import diagonals.regsum as regsum
from diagonals.mesh_helpers.nemo import Nemo
class RegionSum(Diagnostic):
"""
Computes the sum of the field (3D, weighted).
......@@ -167,7 +168,8 @@ class RegionSum(Diagnostic):
masks[basin] = Utils.get_mask(basin)
mesh = Nemo('mesh_hgr.nc', 'mask_regions.nc')
if self.box.min_lat is not -1 and self.box.max_lat is not -1 and self.box.min_lon is not -1 and self.box.max_lat is not -1:
if self.box.min_lat is not -1 and self.box.max_lat is not -1 and self.box.min_lon is not -1 and \
self.box.max_lat is not -1:
name = '{0}_{1}'.format(Box.get_lat_str(self.box), Box.get_lon_str(self.box))
masks[name] = mesh.get_region_mask(self.box.min_lat,
......@@ -179,13 +181,11 @@ class RegionSum(Diagnostic):
else:
self._sum_2d_var(data, mesh, masks)
def _sum_2d_var(self, data, mesh, masks):
areacello = mesh.get_areacello(cell_point=self.grid_point)
varsum = regsum.compute_regsum_2D(data.data, masks, areacello)
self._save_result_2D('sum', varsum, data)
def _sum_3d_variable(self, data, mesh, masks):
areacello = mesh.get_areacello(cell_point=self.grid_point)
tmask = iris.load_cube('mesh_hgr.nc', '{0}mask'.format(self.grid_point))
......@@ -206,7 +206,6 @@ class RegionSum(Diagnostic):
volcello, tmask)
self._save_result_3D('sum', varsum3d, data)
def _try_load_cube(self, number):
try:
cube = iris.load_cube('mesh_hgr.nc', 'e{0}{1}'.format(number, self.grid_point))
......@@ -239,7 +238,6 @@ class RegionSum(Diagnostic):
data = iris.load_cube(self.variable_file.local_file)
return self._rename_depth(data)
def _rename_depth(self, data):
for coord_name in ('model_level_number', 'Vertical T levels', 'lev'):
if data.coords(coord_name):
......@@ -249,7 +247,6 @@ class RegionSum(Diagnostic):
break
return data
def _fix_file_metadata(self):
handler = Utils.open_cdf(self.variable_file.local_file)
var = handler.variables[self.variable]
......@@ -272,8 +269,10 @@ class RegionSum(Diagnostic):
else:
final_name = '{1}{0}'.format(var, self.variable)
self.declared[final_name] = self.declare_chunk(ModelingRealms.ocean, final_name, self.startdate, self.member,
self.chunk, box=box_save, region=self.basins)
self.declared[final_name] = self.declare_chunk(
ModelingRealms.ocean, final_name, self.startdate, self.member,
self.chunk, box=box_save, region=self.basins
)
def _send_var(self, threed, mean_file):
var = 'sum'
......@@ -301,7 +300,9 @@ class RegionSum(Diagnostic):
if hasattr(var_handler, 'valid_max'):
del var_handler.valid_max
handler.close()
self.declared[final_name].set_local_file(temp2, diagnostic=self, rename_var=original_name, region=self.basins)
self.declared[final_name].set_local_file(
temp2, diagnostic=self, rename_var=original_name, region=self.basins
)
def _declare_var(self, var, threed, box_save):
if threed:
......@@ -311,9 +312,10 @@ class RegionSum(Diagnostic):
else:
final_name = '{1}{0}'.format(var, self.variable)
self.declared[final_name] = self.declare_chunk(ModelingRealms.ocean, final_name, self.startdate, self.member,
self.chunk, box=box_save, region=self.basins, grid=self.grid)
self.declared[final_name] = self.declare_chunk(
ModelingRealms.ocean, final_name, self.startdate, self.member,
self.chunk, box=box_save, region=self.basins, grid=self.grid
)
def _save_result_2D(self, var, result, data):
final_name = '{1}{0}'.format(var, self.variable)
......@@ -334,7 +336,6 @@ class RegionSum(Diagnostic):
handler_temp.close()
self.declared[final_name].set_local_file(temp, diagnostic=self)
def _save_result_3D(self, var, result, data):
final_name = '{1}3d{0}'.format(var, self.variable)
temp = TempFile.get()
......
......@@ -149,8 +149,11 @@ class Siasiesiv(Diagnostic):
sic_slices.append(sic_data)
mesh = Nemo('mesh_hgr.nc', 'mask_regions.nc')
areacello = mesh.get_areacello(cell_point='T')
gphit = mesh.get_grid_latitude(cell_point='T')
self.results['siextentn'], self.results['siextents'], self.results['siarean'], self.results['siareas'] = siasie.compute(gphit, areacello, sic_slices, self.masks)
results = siasie.compute(gphit, areacello, sic_slices, self.masks)
self.results['siextentn'] = results[0]
self.results['siextents'] = results[1]
self.results['siarean'] = results[2]
self.results['siareas'] = results[3]
self.save()
......@@ -165,7 +168,6 @@ class Siasiesiv(Diagnostic):
' '.join(set(coordinates) | add_coordinates)
handler.close()
def save(self):
for var in self.results.keys():
res = self.results[var]
......@@ -175,8 +177,7 @@ class Siasiesiv(Diagnostic):
Utils.copy_variable(handler_source, handler_temp, 'time', True, True)
handler_temp.createDimension('region', len(self.masks))
handler_temp.createDimension('region_length', 50)
var_region = handler_temp.createVariable('region', 'S1',
('region', 'region_length'))
var_region = handler_temp.createVariable('region', 'S1', ('region', 'region_length'))
var_res = handler_temp.createVariable('{0}'.format(var), float,
('time', 'region',))
var_res.units = 'm^2'
......@@ -185,5 +186,3 @@ class Siasiesiv(Diagnostic):
var_res[..., i] = res[i, ...]
handler_temp.close()
self.generated[var].set_local_file(temp, diagnostic=self)
......@@ -104,7 +104,7 @@ class TestRegionMean(TestCase):
jobs = RegionMean.generate_jobs(
self.diags,
['diagnostic', 'ocean', 'var', 'U', 'global', '1', '10', 'false','True']
['diagnostic', 'ocean', 'var', 'U', 'global', '1', '10', 'false', 'True']
)
self.assertEqual(len(jobs), 2)
self.assertEqual(jobs[0], RegionMean(self.data_manager, '20010101', 0, 0, ModelingRealms.ocean, 'var',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment