Unable to set output coordinate length
In adi_py
v3.13.0
I had written the following code block to set the coordinate values on an output coordinate variable that was previously empty. In v3.21.0
this fails with an error message Could Not Allocate Memory For Dataset Variable
.
set_output_coord_data()
# Used in the process_data hook; this is a function on the `Process` class
def set_output_coord_data(
self, datastream: str, coord_name: str, data: NDArray[Any]
) -> xr.Dataset:
"""Convenience method to update a specified coordinate's values.
The shape of the data does not need to match the existing coordinate's shape;
the coordinate dimension length will be set to the length of the data array
provided. It is recommended to call this method before modifiying any data
variables dimensioned by the coordinate, as the data values may not be preserved
if the dimension length changes.
Args:
datastream (str): The output datastream to update.
coord_name (str): The name of the coordinate to update.
data (NDArray[Any]): The new data values that should be set.
Returns:
xr.Dataset: The updated output dataset.
"""
ds_name, ds_level = datastream.split(".")
# Use core dsproc library to set the dimension length
dsid_out = dsproc.get_output_datastream_id(ds_name, ds_level) # type: ignore
out_ds = dsproc.get_output_dataset(dsid_out, 0) # type: ignore
dsproc.set_dim_length(out_ds, coord_name, len(data)) # type: ignore
# Use core dsproc library to set the coordinate data values
out_var = dsproc.get_output_var(dsid_out, coord_name, 0) # type: ignore
coord_data = dsproc.alloc_var_data_index(out_var, 0, len(data)) # type: ignore
coord_data[:] = data[:]
return self.get_output_dataset(datastream)
And the error message
Current Error Message
/home/levin/.conda/envs/mergedsmpsaps/lib/python3.9/site-packa **************** Starting process_data_hook ****************
----- LOG MESSAGE ---------------------
/home/levin/.conda/envs/mergedsmpsaps/lib/python3.9/site-packa No length set for merged_diameter_mobility, setting length to 1
----- END LOG MESSAGE -----------------
----- ERROR MESSAGE -------------------
../../src/cds_dims.c:225 Could not change dimension length for: /sgpmergedsmpsapsE13.c1/_dims_/merged_diameter_mobility
-> data has been added for a variable using this dimension
----- END ERROR MESSAGE ---------------
../../src/dsproc.c:4013 Setting status to: 'Could Not Set Dimension Length In Dataset'
----- ERROR MESSAGE -------------------
../../src/cds_var_data.c:575 Could not allocate memory for variable data: /sgpmergedsmpsapsE13.c1/_vars_/merged_diameter_mobility
-> start sample (0) + sample count (212) > dimension length (1)
----- END ERROR MESSAGE ---------------
../../src/dsproc.c:4013 Setting status to: 'Could Not Allocate Memory For Dataset Variable'
../../src/dsproc.c:4013 Setting status to: 'Hook process_data_hook failed.'
----- ERROR MESSAGE -------------------
/home/levin/.conda/envs/mergedsmpsaps/lib/python3.9/site-packa Error Message: Hook process_data_hook failed.
Error Type: TypeError
Exception Message: 'NoneType' object does not support item assignment
Stack Trace:
File "/home/levin/.conda/envs/mergedsmpsaps/lib/python3.9/site-packages/adi_py/utils.py", line 91, in wrapper_function
hook_func(*args, **kwargs)
File "/home/levin/code.arm.gov/vap/mergedsmpsaps/mergedsmpsaps/__main__.py", line 150, in process_data_hook
ds = self.set_output_coord_data(
File "/home/levin/code.arm.gov/vap/mergedsmpsaps/mergedsmpsaps/__main__.py", line 133, in set_output_coord_data
coord_data[:] = data[:]
----- END ERROR MESSAGE ---------------
What do I need to do in order to set the output coordinate data & length in this new version of adi_py?