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

Added regex support for startdate definition

parent afaadd63
......@@ -274,7 +274,14 @@ class ExperimentConfig(object):
members.append(int(mem))
self.members = members
self.startdates = parser.get_option('EXPERIMENT', 'STARTDATES').split()
startdates = parser.get_list_option('EXPERIMENT', 'STARTDATES')
import exrex
self.startdates = []
for startdate_pattern in startdates:
for startdate in exrex.generate(startdate_pattern):
self.startdates.append(startdate)
self.chunk_size = parser.get_int_option('EXPERIMENT', 'CHUNK_SIZE')
self.num_chunks = parser.get_int_option('EXPERIMENT', 'CHUNKS')
self.chunk_list = parser.get_int_list_option('EXPERIMENT', 'CHUNK_LIST', [])
......
......@@ -5,8 +5,9 @@ Installation script for EarthDiagnostics package
"""
from os import path
from setuptools import setup
from setuptools import find_packages
from setuptools import setup
here = path.abspath(path.dirname(__file__))
......@@ -26,7 +27,8 @@ setup(
keywords=['climate', 'weather', 'diagnostic'],
setup_requires=['pyproj'],
install_requires=['numpy', 'netCDF4', 'bscearth.utils', 'cdo>=1.3.4', 'nco>=0.0.3', 'iris>=1.12.0', 'coverage',
'pygrib', 'openpyxl', 'mock', 'futures', 'cf_units', 'cfunits', 'xxhash', 'six', 'psutil'],
'pygrib', 'openpyxl', 'mock', 'futures', 'cf_units', 'cfunits', 'xxhash', 'six', 'psutil',
'exrex'],
packages=find_packages(),
include_package_data=True,
scripts=['bin/earthdiags']
......
# coding=utf-8
from unittest import TestCase
from earthdiagnostics.statistics.daysoverpercentile import DaysOverPercentile
from mock import Mock
from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.statistics.daysoverpercentile import DaysOverPercentile
class TestDaysOverPercentile(TestCase):
......@@ -12,6 +12,7 @@ class TestDaysOverPercentile(TestCase):
def setUp(self):
self.data_manager = Mock()
self.diags = Mock()
self.diags.config.experiment.get_chunk_list.return_value = (('20011101', 0, 0), ('20011101', 0, 1))
def test_generate_jobs(self):
jobs = DaysOverPercentile.generate_jobs(self.diags, ['monpercent', 'ocean', 'var', '2000', '2001', '11'])
......@@ -27,6 +28,6 @@ class TestDaysOverPercentile(TestCase):
DaysOverPercentile.generate_jobs(self.diags, ['monpercent', 'ocean', 'var', '2000', '2001', '11', 'extra'])
def test_str(self):
diagnostic = DaysOverPercentile(self.data_manager, ModelingRealms.ocean, 'var', 2000, 2001, 2000, 11)
diagnostic = DaysOverPercentile(self.data_manager, ModelingRealms.ocean, 'var', 2000, 2001, '20001101', 11)
self.assertEquals(str(diagnostic), 'Days over percentile Startdate: 20001101 Variable: ocean:var '
'Climatology: 2000-2001')
# coding=utf-8
from unittest import TestCase
from earthdiagnostics.config import CMORConfig, ConfigException, THREDDSConfig, ReportConfig
from earthdiagnostics.config import CMORConfig, ConfigException, THREDDSConfig, ReportConfig, ExperimentConfig
from earthdiagnostics.frequency import Frequencies
from earthdiagnostics.modelingrealm import ModelingRealms
......@@ -47,16 +47,23 @@ class ParserMock(object):
def get_path_option(self, section, var, default):
return self.get_value(section, var, default)
def get_int_option(self, section, var, default):
def get_int_option(self, section, var, default=0):
return self.get_value(section, var, default)
def get_int_list_option(self, section, var, default=list(), separator=' '):
try:
return [int(val) for val in self._values[self.get_var_string(section, var)].split(separator)]
except KeyError:
return default
def get_option(self, section, var, default):
def get_list_option(self, section, var, default=list(), separator=' '):
try:
return [val for val in self._values[self.get_var_string(section, var)].split(separator)]
except KeyError:
return default
def get_option(self, section, var, default=None):
return self.get_value(section, var, default)
......@@ -268,3 +275,39 @@ class TestReportConfig(TestCase):
self.mock_parser.add_value('REPORT', 'MAXIMUM_PRIORITY', 3)
config = ReportConfig(self.mock_parser)
self.assertEquals(config.maximum_priority, 3)
class TestExperimentConfig(TestCase):
def setUp(self):
self.mock_parser = ParserMock()
def test_basic_config(self):
config = ExperimentConfig(self.mock_parser)
self.assertEquals(config.startdates, [])
self.assertEquals(config.members, [])
self.assertEquals(config.chunk_size, 0)
self.assertEquals(config.num_chunks, 0)
self.assertEquals(config.atmos_grid, '')
self.assertEquals(config.atmos_timestep, 6)
self.assertEquals(config.ocean_timestep, 6)
def test_startdates(self):
self.mock_parser.add_value('EXPERIMENT', 'STARTDATES', '20001101 20011101')
config = ExperimentConfig(self.mock_parser)
self.assertEquals(config.startdates, ['20001101', '20011101'])
self.mock_parser.add_value('EXPERIMENT', 'STARTDATES', '200(0|1)1101')
config = ExperimentConfig(self.mock_parser)
self.assertEquals(config.startdates, ['20001101', '20011101'])
self.mock_parser.add_value('EXPERIMENT', 'STARTDATES', '200[0-2](02|05|08|11)01')
config = ExperimentConfig(self.mock_parser)
print(config.startdates)
self.assertEquals(config.startdates, [u'20000201', u'20000501', u'20000801', u'20001101', u'20010201',
u'20010501', u'20010801', u'20011101', u'20020201', u'20020501',
u'20020801', u'20021101'])
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