From 459dd04357c85c76691e42178a89ad75bfde561a Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Sun, 20 Oct 2024 13:59:03 -0600 Subject: [PATCH 01/20] add method to return variable _FillValue (get_fill_value) --- src/netCDF4/_netCDF4.pyx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 8679706ba..d7e3af767 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4638,6 +4638,27 @@ behavior is similar to Fortran or Matlab, but different than numpy. return the group that this `Variable` is a member of.""" return self._grp + def get_fill_value(self): + """ +**`get_fill_value(self)`** + +return the `_FillValue` associated with this `Variable` (None if data is not +pre-filled).""" + cdef int ierr, no_fill + with nogil: + ierr = nc_inq_var_fill(self._grpid,self._varid,&no_fill,NULL) + _ensure_nc_success(ierr) + if no_fill == 1: + return None + else: + try: + fillval = self._FillValue + except AttributeError: + if self._isprimitive: + return default_fillvals[self.dtype.str[1:]] + else: + return None + def ncattrs(self): """ **`ncattrs(self)`** From 61121e525c3ec45ec8a5665ed5e3d731446f56cf Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Sun, 20 Oct 2024 14:03:59 -0600 Subject: [PATCH 02/20] add comments --- src/netCDF4/_netCDF4.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index d7e3af767..d155600c9 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4648,15 +4648,18 @@ pre-filled).""" with nogil: ierr = nc_inq_var_fill(self._grpid,self._varid,&no_fill,NULL) _ensure_nc_success(ierr) - if no_fill == 1: + if no_fill == 1: # no filling for this variable return None else: try: fillval = self._FillValue except AttributeError: + # _FillValue attribute not set, use default _FillValue + # for primite datatypes. if self._isprimitive: - return default_fillvals[self.dtype.str[1:]] + return np.asarray(default_fillvals[self.dtype.str[1:]],self.dtype) else: + # no default filling for non-primitive datatypes. return None def ncattrs(self): From 821c74086608c03935ffe99f7099baa820cbc703 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Sun, 20 Oct 2024 14:09:50 -0600 Subject: [PATCH 03/20] update --- src/netCDF4/_netCDF4.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index d155600c9..df196d2a0 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4657,7 +4657,7 @@ pre-filled).""" # _FillValue attribute not set, use default _FillValue # for primite datatypes. if self._isprimitive: - return np.asarray(default_fillvals[self.dtype.str[1:]],self.dtype) + return np.array(default_fillvals[self.dtype.str[1:]],self.dtype) else: # no default filling for non-primitive datatypes. return None From 1668b9900867d107fcc42cba4e7dabbddfc9c483 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Sun, 20 Oct 2024 14:27:26 -0600 Subject: [PATCH 04/20] update --- src/netCDF4/_netCDF4.pyx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index df196d2a0..7e3c397a4 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4654,12 +4654,17 @@ pre-filled).""" try: fillval = self._FillValue except AttributeError: - # _FillValue attribute not set, use default _FillValue - # for primite datatypes. - if self._isprimitive: + # _FillValue attribute not set, see if we can retrieve _FillValue. + # for primitive data types. + if self._isprimitive return np.array(default_fillvals[self.dtype.str[1:]],self.dtype) + #fillval = np.array(default_fillvals[self.dtype.str[1:]],self.dtype) + #with nogil: + # ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,fillval) + #_ensure_nc_success(ierr) + #return fillval else: - # no default filling for non-primitive datatypes. + # no default filling for non-primitive data types. return None def ncattrs(self): From 365fbab2d582fcd0d88070539a98ade3d797aa2d Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Sun, 20 Oct 2024 14:32:01 -0600 Subject: [PATCH 05/20] update --- src/netCDF4/_netCDF4.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 7e3c397a4..babc6d242 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4660,7 +4660,7 @@ pre-filled).""" return np.array(default_fillvals[self.dtype.str[1:]],self.dtype) #fillval = np.array(default_fillvals[self.dtype.str[1:]],self.dtype) #with nogil: - # ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,fillval) + # ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,PyArray_DATA(fillval)) #_ensure_nc_success(ierr) #return fillval else: From 33da47badf0a10b135d586cd28cde9dfbd58f99b Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 09:57:50 -0600 Subject: [PATCH 06/20] use C API to get default fill values --- src/netCDF4/_netCDF4.pyx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index babc6d242..5f5728775 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4656,13 +4656,12 @@ pre-filled).""" except AttributeError: # _FillValue attribute not set, see if we can retrieve _FillValue. # for primitive data types. - if self._isprimitive - return np.array(default_fillvals[self.dtype.str[1:]],self.dtype) - #fillval = np.array(default_fillvals[self.dtype.str[1:]],self.dtype) - #with nogil: - # ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,PyArray_DATA(fillval)) - #_ensure_nc_success(ierr) - #return fillval + if self._isprimitive: + #return numpy.array(default_fillvals[self.dtype.str[1:]],self.dtype) + fillval = numpy.array(default_fillvals[self.dtype.str[1:]],self.dtype) + ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,PyArray_DATA(fillval)) + _ensure_nc_success(ierr) + return fillval else: # no default filling for non-primitive data types. return None From d2099dcb92f8bdddc57bcfb231f0260c637ca031 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:01:38 -0600 Subject: [PATCH 07/20] update --- src/netCDF4/_netCDF4.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 5f5728775..56cc62207 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4658,7 +4658,7 @@ pre-filled).""" # for primitive data types. if self._isprimitive: #return numpy.array(default_fillvals[self.dtype.str[1:]],self.dtype) - fillval = numpy.array(default_fillvals[self.dtype.str[1:]],self.dtype) + fillval = numpy.empty((),self.dtype) ierr=nc_inq_var_fill(self._grpid,self._varid,&no_fill,PyArray_DATA(fillval)) _ensure_nc_success(ierr) return fillval From 0deeb124e583f28f90859cab3db0eb36aa2acf57 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:14:50 -0600 Subject: [PATCH 08/20] update --- src/netCDF4/_netCDF4.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 56cc62207..2f53efdc1 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4653,6 +4653,7 @@ pre-filled).""" else: try: fillval = self._FillValue + return fillval except AttributeError: # _FillValue attribute not set, see if we can retrieve _FillValue. # for primitive data types. From 3d9b9d9323a03a87e68d6b32fbe21e480fa201a1 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:26:28 -0600 Subject: [PATCH 09/20] add test case --- test/test_get_fill_value.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/test_get_fill_value.py diff --git a/test/test_get_fill_value.py b/test/test_get_fill_value.py new file mode 100644 index 000000000..0e588c0bc --- /dev/null +++ b/test/test_get_fill_value.py @@ -0,0 +1,36 @@ +import unittest, os, tempfile +import netCDF4 +from numpy.testing import assert_array_equal +import numpy as np + +fill_val = np.array(9.9e31) + +class TestGetFillValue(unittest.TestCase): + def setUp(self): + self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name + f = netCDF4.Dataset(self.testfile, 'w') + dim = f.createDimension('x',10) + for dt in netCDF4.default_fillvals.keys(): + if not dt.startswith('c'): + v = f.createVariable(dt+'_var',dt,dim) + v = f.createVariable('float_var',np.float64,dim,fill_value=fill_val) + f.close() + + def tearDown(self): + os.remove(self.testfile) + + def runTest(self): + f = netCDF4.Dataset(self.testfile, "r") + # no _FillValue set, test that default fill value returned + for dt in netCDF4.default_fillvals.keys(): + if not dt.startswith('c'): + fillval = np.array(netCDF4.default_fillvals[dt]) + if dt == 'S1': fillval = fillval.astype(dt) + v = f[dt+'_var'] + assert_array_equal(fillval, v.get_fill_value()) + # _FillValue attribute is set. + v = f['float_var'] + assert_array_equal(fill_val, v.get_fill_value()) + +if __name__ == '__main__': + unittest.main() From b4b6eee4162dbcdd664e5179c777adeafe1e4f28 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:27:04 -0600 Subject: [PATCH 10/20] update --- test/test_get_fill_value.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_get_fill_value.py b/test/test_get_fill_value.py index 0e588c0bc..79591b803 100644 --- a/test/test_get_fill_value.py +++ b/test/test_get_fill_value.py @@ -5,6 +5,8 @@ fill_val = np.array(9.9e31) +# test Variable.get_fill_value + class TestGetFillValue(unittest.TestCase): def setUp(self): self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name From d16a91fd3f4aea30ad2194eae1e8f4ee9eda1aa7 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:34:23 -0600 Subject: [PATCH 11/20] update docstring --- src/netCDF4/_netCDF4.pyx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 2f53efdc1..f3d0a2f91 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4039,7 +4039,11 @@ behavior is similar to Fortran or Matlab, but different than numpy. value that the variable gets filled with before any data is written to it) is replaced with this value. If fill_value is set to `False`, then the variable is not pre-filled. The default netCDF fill values can be found - in the dictionary `netCDF4.default_fillvals`. + in the dictionary `netCDF4.default_fillvals`. If not set, the netCDF default + `_FillValue` will be used but no `_FillValue` attribute will be created + (this is the default behavior of the netcdf-c library). `Variable.get_fill_value` + can be used to retrieve the fill value, even if the `_FillValue` attribute is + not set. **`chunk_cache`**: If specified, sets the chunk cache size for this variable. Persists as long as Dataset is open. Use `set_var_chunk_cache` to @@ -4642,8 +4646,9 @@ return the group that this `Variable` is a member of.""" """ **`get_fill_value(self)`** -return the `_FillValue` associated with this `Variable` (None if data is not -pre-filled).""" +return the fill value associated with this `Variable` (None if data is not +pre-filled). Works even if default fill value was used, and `_FillValue` attribute +does not exist.""" cdef int ierr, no_fill with nogil: ierr = nc_inq_var_fill(self._grpid,self._varid,&no_fill,NULL) From d740b0a98430d27ae510a437e60a1d1a809e96b9 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 10:37:05 -0600 Subject: [PATCH 12/20] update --- src/netCDF4/_netCDF4.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index f3d0a2f91..5e083ea49 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4035,12 +4035,12 @@ behavior is similar to Fortran or Matlab, but different than numpy. Ignored if `significant_digts` not specified. If 'BitRound' is used, then `significant_digits` is interpreted as binary (not decimal) digits. - **`fill_value`**: If specified, the default netCDF `_FillValue` (the + **`fill_value`**: If specified, the default netCDF fill value (the value that the variable gets filled with before any data is written to it) - is replaced with this value. If fill_value is set to `False`, then - the variable is not pre-filled. The default netCDF fill values can be found - in the dictionary `netCDF4.default_fillvals`. If not set, the netCDF default - `_FillValue` will be used but no `_FillValue` attribute will be created + is replaced with this value, and the `_FillValue` attribute is set. + If fill_value is set to `False`, then the variable is not pre-filled. + The default netCDF fill values can be found in the dictionary `netCDF4.default_fillvals`. + If not set, the default fill value will be used but no `_FillValue` attribute will be created (this is the default behavior of the netcdf-c library). `Variable.get_fill_value` can be used to retrieve the fill value, even if the `_FillValue` attribute is not set. From f50a70df84be4655d2e4d0a3e70a51ef584bf2cb Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 12:41:45 -0600 Subject: [PATCH 13/20] close file --- test/test_get_fill_value.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_get_fill_value.py b/test/test_get_fill_value.py index 79591b803..f325f4456 100644 --- a/test/test_get_fill_value.py +++ b/test/test_get_fill_value.py @@ -33,6 +33,7 @@ def runTest(self): # _FillValue attribute is set. v = f['float_var'] assert_array_equal(fill_val, v.get_fill_value()) + f.close() if __name__ == '__main__': unittest.main() From 5d922e40f16109f7b1cd79b8563400b3e32ced86 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 13:29:41 -0600 Subject: [PATCH 14/20] add get_fill_value to stub --- src/netCDF4/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 1a709dd35..68e18dcae 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -465,6 +465,7 @@ class Variable(Generic[T_Datatype]): def renameAttribute(self, oldname: str, newname: str) -> None: ... def assignValue(self, val: Any) -> None: ... def getValue(self) -> Any: ... + def get_fill_value(self) -> Any: ... def set_auto_chartostring(self, chartostring: bool) -> None: ... def use_nc_get_vars(self, use_nc_get_vars: bool) -> None: ... def set_auto_maskandscale(self, maskandscale: bool) -> None: ... From 1f67c941b24a413834bee5f7ecee7c6a7597db6f Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 13:33:37 -0600 Subject: [PATCH 15/20] update --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 4015f67a1..4c635ce8f 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,8 @@ =============================== * add static type hints (PR #1302) * Expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). (PR #1348) + * Add Variable.get_fill_value (issue #1374, PR #1375). + * Fix NETCDF3 endian error (issue #1373, PR #1355). version 1.7.1 (tag v1.7.1rel) =============================== From aa9452a5f49b5098e349fcaed8975f2e1cb2b239 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 14:00:56 -0600 Subject: [PATCH 16/20] add fill_value='default' option --- src/netCDF4/_netCDF4.pyx | 13 ++++++++++--- test/test_get_fill_value.py | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 5e083ea49..341151381 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4041,9 +4041,10 @@ behavior is similar to Fortran or Matlab, but different than numpy. If fill_value is set to `False`, then the variable is not pre-filled. The default netCDF fill values can be found in the dictionary `netCDF4.default_fillvals`. If not set, the default fill value will be used but no `_FillValue` attribute will be created - (this is the default behavior of the netcdf-c library). `Variable.get_fill_value` - can be used to retrieve the fill value, even if the `_FillValue` attribute is - not set. + (this is the default behavior of the netcdf-c library). If you want to use the + default fill value, but have the `_FillValue` attribute set, use + `fill_value='default'` (note - this only works for primitive data types). ``Variable.get_fill_value` + can be used to retrieve the fill value, even if the `_FillValue` attribute is not set. **`chunk_cache`**: If specified, sets the chunk cache size for this variable. Persists as long as Dataset is open. Use `set_var_chunk_cache` to @@ -4407,6 +4408,12 @@ behavior is similar to Fortran or Matlab, but different than numpy. if ierr != NC_NOERR: if grp.data_model != 'NETCDF4': grp._enddef() _ensure_nc_success(ierr, extra_msg=error_info) + elif fill_value == 'default': + if self._isprimitive: + fillval = numpy.array(default_fillvals[self.dtype.str[1:]]) + if not fillval.dtype.isnative: fillval.byteswap(True) + _set_att(self._grp, self._varid, '_FillValue',\ + fillval, xtype=xtype) else: if self._isprimitive or self._isenum or \ (self._isvlen and self.dtype == str): diff --git a/test/test_get_fill_value.py b/test/test_get_fill_value.py index f325f4456..257a3121e 100644 --- a/test/test_get_fill_value.py +++ b/test/test_get_fill_value.py @@ -16,6 +16,8 @@ def setUp(self): if not dt.startswith('c'): v = f.createVariable(dt+'_var',dt,dim) v = f.createVariable('float_var',np.float64,dim,fill_value=fill_val) + # test fill_value='default' option (issue #1374) + v2 = f.createVariable('float_var2',np.float64,dim,fill_value='default') f.close() def tearDown(self): @@ -33,6 +35,8 @@ def runTest(self): # _FillValue attribute is set. v = f['float_var'] assert_array_equal(fill_val, v.get_fill_value()) + v = f['float_var2'] + assert_array_equal(np.array(netCDF4.default_fillvals['f8']), v._FillValue) f.close() if __name__ == '__main__': From f3eba108e29402fee10c465e5a4727fc76336646 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 14:06:32 -0600 Subject: [PATCH 17/20] update --- Changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 4c635ce8f..bc46e06ce 100644 --- a/Changelog +++ b/Changelog @@ -2,7 +2,8 @@ =============================== * add static type hints (PR #1302) * Expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). (PR #1348) - * Add Variable.get_fill_value (issue #1374, PR #1375). + * Add Variable.get_fill_value and allow `fill_value='default'` to + set `_FillValue` using default fill values. (issue #1374, PR #1375). * Fix NETCDF3 endian error (issue #1373, PR #1355). version 1.7.1 (tag v1.7.1rel) From 801e7b611f4c015552ab7681b840b359fe562846 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 14:15:52 -0600 Subject: [PATCH 18/20] add warning if fill_value='default' used for non primitive data type --- src/netCDF4/_netCDF4.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 341151381..e6d20a7db 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4414,6 +4414,11 @@ behavior is similar to Fortran or Matlab, but different than numpy. if not fillval.dtype.isnative: fillval.byteswap(True) _set_att(self._grp, self._varid, '_FillValue',\ fillval, xtype=xtype) + else: + msg = """ +WARNING: there is no default fill value for this data type, so fill_value='default' +does not do anything.""" + warnings.warn(msg) else: if self._isprimitive or self._isenum or \ (self._isvlen and self.dtype == str): From bff03a4791283076907f7515718cd3092b4ff5fe Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 17:40:03 -0600 Subject: [PATCH 19/20] fix typos in docstrings --- src/netCDF4/_netCDF4.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index e6d20a7db..7c92f09bd 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -4043,7 +4043,7 @@ behavior is similar to Fortran or Matlab, but different than numpy. If not set, the default fill value will be used but no `_FillValue` attribute will be created (this is the default behavior of the netcdf-c library). If you want to use the default fill value, but have the `_FillValue` attribute set, use - `fill_value='default'` (note - this only works for primitive data types). ``Variable.get_fill_value` + `fill_value='default'` (note - this only works for primitive data types). `Variable.get_fill_value` can be used to retrieve the fill value, even if the `_FillValue` attribute is not set. **`chunk_cache`**: If specified, sets the chunk cache size for this variable. @@ -4658,7 +4658,7 @@ return the group that this `Variable` is a member of.""" """ **`get_fill_value(self)`** -return the fill value associated with this `Variable` (None if data is not +return the fill value associated with this `Variable` (returns `None` if data is not pre-filled). Works even if default fill value was used, and `_FillValue` attribute does not exist.""" cdef int ierr, no_fill From 6e30d7bbe2d550b38cf007397b2d230ed1e8ccf2 Mon Sep 17 00:00:00 2001 From: Jeff Whitaker Date: Mon, 21 Oct 2024 17:40:31 -0600 Subject: [PATCH 20/20] update docs --- docs/index.html | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/index.html b/docs/index.html index 29e5a7c3c..8484e66d6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -289,7 +289,7 @@

Dimensions in a netCDF file

<class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144

Dimension names can be changed using the -Dataset.renameDimension method of a Dataset or +Dataset.renameDimension() method of a Dataset or Group instance.

Variables in a netCDF file

netCDF variables behave much like python multidimensional array objects @@ -2676,12 +2676,16 @@

Instance variables

Ignored if significant_digts not specified. If 'BitRound' is used, then significant_digits is interpreted as binary (not decimal) digits.

fill_value: -If specified, the default netCDF _FillValue (the +If specified, the default netCDF fill value (the value that the variable gets filled with before any data is written to it) -is replaced with this value. -If fill_value is set to False, then -the variable is not pre-filled. The default netCDF fill values can be found -in the dictionary netCDF4.default_fillvals.

+is replaced with this value, and the _FillValue attribute is set. +If fill_value is set to False, then the variable is not pre-filled. +The default netCDF fill values can be found in the dictionary netCDF4.default_fillvals. +If not set, the default fill value will be used but no _FillValue attribute will be created +(this is the default behavior of the netcdf-c library). If you want to use the +default fill value, but have the _FillValue attribute set, use +fill_value='default' (note - this only works for primitive data types). Variable.get_fill_value() +can be used to retrieve the fill value, even if the _FillValue attribute is not set.

chunk_cache: If specified, sets the chunk cache size for this variable. Persists as long as Dataset is open. Use set_var_chunk_cache to change it when Dataset is re-opened.

@@ -2806,6 +2810,15 @@

Methods

return a tuple of Dimension instances associated with this Variable.

+
+def get_fill_value(self) +
+
+

get_fill_value(self)

+

return the fill value associated with this Variable (returns None if data is not +pre-filled). Works even if default fill value was used, and _FillValue attribute +does not exist.

+
def get_var_chunk_cache(self)
@@ -3241,6 +3254,7 @@

Variablefilters
  • getValue
  • get_dims
  • +
  • get_fill_value
  • get_var_chunk_cache
  • getncattr
  • group