Skip to content

Commit

Permalink
TST: Multiple time units for MFDatasets #435
Browse files Browse the repository at this point in the history
Added MFTime unit test for the netCDF4-python library
  • Loading branch information
bekozi committed Jan 27, 2017
1 parent 350dac8 commit 49c0984
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/ocgis/test/test_simple/test_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

import numpy as np
from netCDF4._netCDF4 import MFDataset, MFTime

from ocgis import CoordinateReferenceSystem
from ocgis.test.base import TestBase, attr

Expand All @@ -18,6 +21,32 @@ def test_netCDF4(self):
var = ds.variables['foo']
self.assertEqual(var.shape, (1, 1))

def test_netCDF4_MFTime(self):
value = [0, 1, 2]
units = ['days since 2000-1-1', 'days since 2001-1-1']
names = ['time_2000.nc', 'time_0001.nc']
paths = []

for unit, name in zip(units, names):
path = self.get_temporary_file_path(name)
paths.append(path)

with self.nc_scope(path, 'w', format='NETCDF4_CLASSIC') as f:
f.createDimension('time')
vtime = f.createVariable('time', np.float32, dimensions=('time',))
vtime[:] = value
vtime.calendar = 'standard'
vtime.units = unit

mfd = MFDataset(paths)
try:
mvtime = MFTime(mfd.variables['time'])
desired = [0., 1., 2., 366., 367., 368.]
actual = mvtime[:].tolist()
self.assertEqual(actual, desired)
finally:
mfd.close()

def test_osr(self):
crs = CoordinateReferenceSystem(epsg=4326)
self.assertNotEqual(crs.value, {})

0 comments on commit 49c0984

Please sign in to comment.