[
https://issues.apache.org/jira/browse/CLIMATE-758?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15170656#comment-15170656
]
Michael Anderson commented on CLIMATE-758:
------------------------------------------
Note that first a handle is created to the variable in the file:
latitudes = netCDF_file.createVariable('latitude', 'd', ('lat_dim',))
longitudes = netCDF_file.createVariable('longitude', 'd', ('lon_dim',))
times = netCDF_file.createVariable('time', 'd', ('time_dim',))
levels = netCDF_file.createVariable('level', 'd', ('level_dim',))
values = netCDF_file.createVariable('value', 'd', ('level_dim',
'time_dim', 'lat_dim', 'lon_dim'))
But then the handle is set to some other value:
latitudes = range(0,5)
longitudes = range(200,205)
#Three months of data
#Two levels
levels = [100, 200]
#Create 150 values
values = numpy.array([i for i in range(150)])
#Reshape values to 4D array (level, time, lats, lons)
values = values.reshape(len(levels),
len(times),len(latitudes),len(longitudes))
So when it comes time to ingest the data in the file, the variables are no
longer handles to the file and the file is written empty.
#Ingest values to netCDF file
latitudes[:] = latitudes
longitudes[:] = longitudes
times[:] = numpy.array(range(3))
levels[:] = levels
values[:] = values
> Fix failing tests in test_local.py
> ----------------------------------
>
> Key: CLIMATE-758
> URL: https://issues.apache.org/jira/browse/CLIMATE-758
> Project: Apache Open Climate Workbench
> Issue Type: Sub-task
> Components: tests
> Reporter: Lewis John McGibbney
> Fix For: 1.1
>
>
> {code}
> ======================================================================
> ERROR: Test adding a custom name to a dataset
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 69, in
> test_custom_dataset_name
> ds = local.load_file(self.file_path, 'value', name='foo')
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> ======================================================================
> ERROR: test_dataset_origin (ocw.tests.test_local.test_load_file)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 73, in
> test_dataset_origin
> ds = local.load_file(self.file_path, 'value', elevation_index=1)
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> ======================================================================
> ERROR: To test load_file function for latitudes
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 48, in
> test_function_load_file_lats
> self.assertItemsEqual(local.load_file(self.file_path, "value").lats,
> self.latitudes)
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> ======================================================================
> ERROR: To test load_file function for longitudes
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 53, in
> test_function_load_file_lons
> self.assertItemsEqual(local.load_file(self.file_path, "value").lons,
> self.longitudes)
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> ======================================================================
> ERROR: To test load_file function for times
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 59, in
> test_function_load_file_times
> self.assertItemsEqual(local.load_file(self.file_path, "value").times,
> newTimes)
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> ======================================================================
> ERROR: To test load_file function for values
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/local/climate/ocw/tests/test_local.py", line 65, in
> test_function_load_file_values
> self.assertTrue(numpy.allclose(local.load_file(self.file_path,
> "value").values, new_values))
> File "/usr/local/climate/ocw/data_source/local.py", line 283, in load_file
> units=variable_unit, name=name, origin=origin)
> File "/usr/local/climate/ocw/dataset.py", line 71, in __init__
> self._validate_inputs(lats, lons, times, values)
> File "/usr/local/climate/ocw/dataset.py", line 206, in _validate_inputs
> raise ValueError(err_msg)
> ValueError: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> -------------------- >> begin captured logging << --------------------
> ocw.dataset: ERROR: Value Array must be of shape (times, lats, lons).
> Expected shape (3, 5, 5) but received (2, 5, 5)
> --------------------- >> end captured logging << ---------------------
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)