Skip to content

Commit

Permalink
add support for boolean grids
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Mather committed Sep 16, 2024
1 parent 97fcfa3 commit 78485e3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gplately/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,18 @@ def write_netcdf_grid(filename, grid, extent="global", significant_digits=None,
data_kwds['significant_digits'] = max(2, int(significant_digits))
data_kwds['quantize_mode'] = 'GranularBitRound'

# boolean arrays need to be converted to integers
# no such thing as a mask on a boolean array
if grid.dtype is np.dtype(bool):
grid = grid.astype('i1')
fill_value = None

cdf_data = cdf.createVariable('z', grid.dtype, ('lat','lon'), **data_kwds)

# netCDF4 uses the missing_value attribute as the default _FillValue
# without this, _FillValue defaults to 9.969209968386869e+36
cdf_data.missing_value = fill_value
if fill_value is not None:
cdf_data.missing_value = fill_value

cdf_data.standard_name = 'z'

Expand Down

0 comments on commit 78485e3

Please sign in to comment.