Example #1
0
def test_rasterio_nodata(tmpdir):
    from datacube.testutils.io import dc_read, write_gtiff
    from pathlib import Path

    roi = np.s_[10:20, 20:30]
    xx = np.zeros((64, 64), dtype='uint8')
    xx[roi] = 255

    pp = Path(str(tmpdir))

    mm = write_gtiff(pp/'absent_nodata.tiff', xx, nodata=None)

    yy = dc_read(mm.path, gbox=mm.gbox, fallback_nodata=None)
    np.testing.assert_array_equal(xx, yy)

    # fallback nodata is outside source range so it shouldn't be used
    yy = dc_read(mm.path, gbox=mm.gbox, fallback_nodata=-1, dst_nodata=-999, dtype='int16')
    np.testing.assert_array_equal(xx.astype('int16'), yy)

    # treat zeros as no-data + type conversion while reading
    yy_expect = xx.copy().astype('int16')
    yy_expect[xx == 0] = -999
    assert set(yy_expect.ravel()) == {-999, 255}

    yy = dc_read(mm.path, fallback_nodata=0, dst_nodata=-999, dtype='int16')
    np.testing.assert_array_equal(yy_expect, yy)

    # now check that file nodata is used instead of fallback
    mm = write_gtiff(pp/'with_nodata.tiff', xx, nodata=33)
    yy = dc_read(mm.path, fallback_nodata=0, dst_nodata=-999, dtype='int16')

    np.testing.assert_array_equal(xx, yy)

    yy = dc_read(mm.path)
    np.testing.assert_array_equal(xx, yy)
    def _load_medians(self, gbox):

        indices_list = [
            's6m', 's6m_std', 'mndwi', 'mndwi_std', 'msavi', 'msavi_std',
            'whi', 'whi_std'
        ]
        medians = {
            ind: dc_read('{}/{}'.format(self.median_path,
                                        self.indstr.format(ind)),
                         gbox=gbox,
                         resampling="bilinear")
            for ind in indices_list
        }
        return xr.Dataset(data_vars={
            ind: (('y', 'x'), medians[ind])
            for ind in indices_list
        },
                          coords=_to_xrds_coords(gbox),
                          attrs={'crs': gbox.crs})
Example #3
0
 def _load_dsm(self, gbox):
     # Data variable needs to be named elevation
     dsm = dc_read(self.dsm_path, gbox=gbox, resampling="bilinear")
     return xr.Dataset(data_vars={'elevation': (('y', 'x'), dsm)}, coords=_to_xrds_coords(gbox),
                       attrs={'crs': gbox.crs})