write_grid #1192
-
Hi! I'm trying to save grids I made through pyart.map.grid_from_radars. I've noticed that a few issues have been closed regarding writing grids and netcdf, but I have another issue. I've added a few prints inside the code and I have noticed that the netcdf variable that is saved inside write_grid through _create_ncvar() has dimensions of (720,1,720,781) for ('time', 'z', 'y', 'x'). This is incorrect, I'm expecting (1, 1, 720, 781). It's making 'time' to have 720 when it should be 1. Thank you ! |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
@vgalligani Can't reproduce the issue at the moment do you have a test file I can try out to see if I can reproduce with that? What is the shape of your grid.time['data'] array? And what is your code for writing the grids? |
Beta Was this translation helpful? Give feedback.
-
Hi! You are correct, sorry. My grid.time['data'] array is actually 720. I was certain I was working with dimension 1. |
Beta Was this translation helpful? Give feedback.
-
No worries at all, are you hard setting the grid.time['data']? If not trying to see how its being set to 720. |
Beta Was this translation helpful? Give feedback.
-
Time gets set to: Which is where the single time is being generated |
Beta Was this translation helpful? Give feedback.
-
Thanks! |
Beta Was this translation helpful? Give feedback.
-
No, I would have the single time, just was seeing how the 720 was overwriting the code I posted above. |
Beta Was this translation helpful? Give feedback.
-
The grid seems to work, it seems to get modified when I write it with pyart.io.write_grid(name, grid) data = dic['data'] has the right shape but then, towards then end ncvar = dataset.createVariable(name, dtype, dimensions, **kwargs) ncvar.shape = (720, 1, 720, 781) this is what confuses me |
Beta Was this translation helpful? Give feedback.
-
The write also outputs radar_time as well which could be the number. After writing the grid to make sure though, with your written grid, do: |
Beta Was this translation helpful? Give feedback.
-
Ok, so the grid written has the right dimensions, the problem was actually in the read_grid(name) in the lines where if field_dic['data'].shape == field_shape_with_time: with the following for the Zh in my grid: so I replaced with I think this has fixed my issue. |
Beta Was this translation helpful? Give feedback.
Ok, so the grid written has the right dimensions, the problem was actually in the read_grid(name)
in the lines where
if field_dic['data'].shape == field_shape_with_time:
field_dic['data'].shape = field_shape
fields[field] = field_dic
else:
bad_shape = field_dic['data'].shape
warnings.warn(
'Field %s skipped due to incorrect shape %s'
% (field, bad_shape))
with the following for the Zh in my grid:
field_shape_with_time = (1, 1, 720, 781)
field_dic[data].shape = (720, 1, 720, 781)
so I replaced
field_shape = tuple([len(dset.dimensions[d]) for d in [,'z', 'y', 'x']])
field_shape_with_time = (1, ) + field_shape
with
field_shape = tuple([len(dset.dimensions[d]) for d in ['time','z', 'y', 'x']])
…