Exemplo n.º 1
0
 def test_applyFillvalue_withFillAndMissingValue(self):
     result = apply_fillvalue(data=np.array([1, 2, 3]),
                              attributes={
                                  'missing_value': 1,
                                  '_FillValue': 2
                              })
     self.assertArraysEqual(result,
                            ma.array([1, 2, 3], mask=[False, True, False]))
Exemplo n.º 2
0
    def _get_data_from_slices(self, dim_slices):
        """Get this variable's data as a numpy array.

        dim_slices: list of slice objects or integer indices; length of
        dim_slices should match the dimensionality of this variable
        """

        if len(dim_slices) > 0:
            vardata = self._var[dim_slices].copy()
        else:
            # Scalar data
            vardata = np.array(self._var.getValue())
        # NOTE(wjs, 2015-12-23) We do our own application of the mask, rather
        # than relying on the maskandscale argument to netcdf_file, for two
        # reasons: (1) maskandscale was added very recently, and is not yet
        # supported in any scipy release, (2) the application of the mask using
        # the maskandscale option is not ideal - for example, it allows for
        # small differences from the given _FillValue, rather than requiring an
        # exact match.
        vardata_filled = apply_fillvalue(vardata, self.get_attributes())

        return vardata_filled
Exemplo n.º 3
0
    def _get_data_from_slices(self, dim_slices):
        """Get this variable's data as a numpy array.

        dim_slices: list of slice objects or integer indices; length of
        dim_slices should match the dimensionality of this variable
        """

        if len(dim_slices) > 0:
            vardata = self._var[dim_slices].copy()
        else:
            # Scalar data
            vardata = np.array(self._var.getValue())
        # NOTE(wjs, 2015-12-23) We do our own application of the mask, rather
        # than relying on the maskandscale argument to netcdf_file, for two
        # reasons: (1) maskandscale was added very recently, and is not yet
        # supported in any scipy release, (2) the application of the mask using
        # the maskandscale option is not ideal - for example, it allows for
        # small differences from the given _FillValue, rather than requiring an
        # exact match.
        vardata_filled = apply_fillvalue(vardata, self.get_attributes())

        return vardata_filled
Exemplo n.º 4
0
 def test_applyFillvalue_withNoFill(self):
     result = apply_fillvalue(data=np.array([1, 2, 3]), attributes={})
     self.assertArraysEqual(result, ma.array([1, 2, 3]))
Exemplo n.º 5
0
 def test_applyFillvalue_withFillAndMissingValue(self):
     result = apply_fillvalue(data = np.array([1,2,3]),
                              attributes = {'missing_value':1,
                                            '_FillValue':2})
     self.assertArraysEqual(result, ma.array([1,2,3], mask=[False,True,False]))
Exemplo n.º 6
0
 def test_applyFillvalue_withNoFill(self):
     result = apply_fillvalue(data = np.array([1,2,3]),
                              attributes = {})
     self.assertArraysEqual(result, ma.array([1,2,3]))