Skip to content

Commit

Permalink
Fixed computation of the time dimension lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Dec 7, 2015
1 parent 62c8981 commit 9d7a802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/cablab/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ class CubeConfig:
:param temporal_res: The temporal resolution in days.
:param ref_time: A datetime value which defines the units in which time values are given, namely
'days since *ref_time*'.
:param start_time: The start time of the first image of any variable in the cube given as datetime value.
:param start_time: The inclusive start time of the first image of any variable in the cube given as datetime value.
``None`` means unlimited.
:param end_time: The end time of the last image of any variable in the cube given as datetime value.
:param end_time: The exclusive end time of the last image of any variable in the cube given as datetime value.
``None`` means unlimited.
:param variables: A list of variable names to be included in the cube.
:param file_format: The file format used. Must be one of 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_CLASSIC'
Expand Down Expand Up @@ -626,8 +626,13 @@ def shape(self) -> tuple:
"""
Return the shape of the data cube.
"""
# todo (nf 20151030) - retrieve correct time size
return len(self._dataset_files), 0, self._cube.config.grid_height, self._cube.config.grid_width
year_1 = self._cube.config.start_time.year
year_2 = self._cube.config.end_time.year
years = year_2 - year_1
if self._cube.config.end_time > datetime(self._cube.config.end_time.year, 1, 1):
years += 1
time_size = years * self._cube.config.num_periods_per_year
return len(self._dataset_files), time_size, self._cube.config.grid_height, self._cube.config.grid_width

@property
def variable_names(self) -> tuple:
Expand Down
5 changes: 3 additions & 2 deletions test/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def test_update(self):
self.assertEqual(cube.config.file_format, cube2.config.file_format)
self.assertEqual(cube.config.compression, cube2.config.compression)

provider = CubeSourceProviderMock(cube2.config, start_time=datetime(2006, 12, 15),
provider = CubeSourceProviderMock(cube2.config,
start_time=datetime(2006, 12, 15),
end_time=datetime(2007, 1, 15))
cube2.update(provider)
self.assertEqual([(datetime(2006, 12, 11, 0, 0), datetime(2006, 12, 19, 0, 0)), # 8 days
Expand All @@ -93,7 +94,7 @@ def test_update(self):

data = cube2.data
self.assertIsNotNone(data)
self.assertEqual((2, 0, 720, 1440), data.shape)
self.assertEqual((2, 10 * 46, 720, 1440), data.shape)
self.assertEquals({'FAPAR': 0, 'LAI': 1}, data.variable_names)

self.assertIsNotNone(data.get_variable('LAI'))
Expand Down

0 comments on commit 9d7a802

Please sign in to comment.