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

Fixed bug in regionmean

parent 19b3cff9
......@@ -268,12 +268,12 @@ class DataFile(Publisher):
else:
self._update_var_with_region_data()
self._correct_metadata()
Utils.nco.ncks(input=self.local_file, output=self.local_file, options='-O --fix_rec_dmn region')
Utils.nco.ncks(input=self.local_file, output=self.local_file, options=['--fix_rec_dmn region'])
def _update_var_with_region_data(self):
temp = TempFile.get()
shutil.copyfile(self.remote_file, temp)
Utils.nco.ncks(input=temp, output=temp, options='-O --mk_rec_dmn region')
Utils.nco.ncks(input=temp, output=temp, options=['--mk_rec_dmn region'])
handler = Utils.openCdf(temp)
handler_send = Utils.openCdf(self.local_file)
value = handler_send.variables[self.final_name][:]
......
......@@ -350,12 +350,14 @@ class EarthDiags(object):
return False
if not force and os.path.exists(destiny):
if os.stat(source).st_size == os.stat(destiny).st_size:
# Small size differences can be due to the renaming of variables
delta_size = abs(os.stat(source).st_size - os.stat(destiny).st_size)
if delta_size < 512:
Log.info('File {0} already exists', destiny)
return True
Log.info('Copying file {0}', destiny)
shutil.copy(source, destiny)
shutil.copyfile(source, destiny)
Log.info('File {0} ready', destiny)
Utils.rename_variables(destiny, self.dic_variables, False, True)
return True
......
......@@ -6,8 +6,8 @@ from earthdiagnostics.box import Box
from earthdiagnostics.constants import Basins
from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticIntOption, DiagnosticDomainOption, \
DiagnosticBoolOption, DiagnosticBasinOption, DiagnosticVariableOption
from earthdiagnostics.utils import Utils, TempFile
from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.utils import Utils, TempFile
class RegionMean(Diagnostic):
......@@ -158,7 +158,7 @@ class RegionMean(Diagnostic):
levels = ''
temp2 = TempFile.get()
Utils.nco.ncks(input=mean_file, output=temp2, options=('-O -v {0},lat,lon{1}'.format(original_name, levels),))
Utils.nco.ncks(input=mean_file, output=temp2, options=('-v {0},lat,lon{1}'.format(original_name, levels),))
self.declared[final_name].set_local_file(temp2, rename_var=original_name)
def declare_var(self, var, threed, box_save):
......
# coding=utf-8
import datetime
import os
import re
import shutil
import stat
import subprocess
import sys
import tarfile
import datetime
import tempfile
from contextlib import contextmanager
import iris
import iris.exceptions
import netCDF4
import numpy as np
import os
import stat
import re
import tempfile
import six
import xxhash
from bscearth.utils.log import Log
from cdo import Cdo, CDOException
from cdo import Cdo
from cfunits import Units
from nco import Nco
from earthdiagnostics.constants import Basins
from contextlib import contextmanager
import sys
import xxhash
@contextmanager
......@@ -168,8 +169,9 @@ class Utils(object):
def check_netcdf_file(filepath):
with suppress_stdout():
try:
Utils.cdo.showvar(input=filepath)
except CDOException:
iris.FUTURE.netcdf_promote = True
iris.load(filepath)
except iris.exceptions.IrisError:
return False
return True
......
......@@ -273,7 +273,6 @@ class TestReportConfig(TestCase):
self.assertEquals(config.path, 'new_path')
def test_priority(self):
self.mock_parser.add_value('REPORT', 'MAXIMUM_PRIORITY', 3)
config = ReportConfig(self.mock_parser)
self.assertEquals(config.maximum_priority, 3)
......@@ -295,6 +294,12 @@ class TestExperimentConfig(TestCase):
self.assertEquals(config.atmos_timestep, 6)
self.assertEquals(config.ocean_timestep, 6)
def test_cmor_version_required(self):
self.mock_parser.add_value('CMOR', 'VERSION', '20001101')
self.mock_parser.add_value('EXPERIMENT', 'DATA_CONVENTION', 'Primavera')
config = ExperimentConfig(self.mock_parser)
self.assertEquals(config.path, 'new_path')
def test_startdates(self):
self.mock_parser.add_value('EXPERIMENT', 'STARTDATES', '20001101 20011101')
config = ExperimentConfig(self.mock_parser)
......
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