예제 #1
0
 def test_getrange(self):
     with SD.start(self.sdfile, SD.DFACC_READ) as sdid:
         idx = SD.nametoindex(sdid, 'Reflectivity')
         with SD.select(sdid, idx) as sds_id:
             smax, smin = SD.getrange(sds_id)
             self.assertEqual(smax, 105.0)
             self.assertEqual(smin, -5.0)
예제 #2
0
 def test_sd(self):
     with SD.start(self.sdfile, SD.DFACC_READ) as sdid:
         idx = SD.nametoindex(sdid, 'Reflectivity')
         with SD.select(sdid, idx) as sds_id:
             info = SD.getinfo(sds_id)
             self.assertEqual(info[0], 'Reflectivity')
             attr_idx = SD.findattr(sds_id, 'long_name')
             attr_name, datatype, count = SD.attrinfo(sds_id, attr_idx)
             long_name = SD.readattr(sds_id, attr_idx)
             self.assertEqual(long_name, 'Effective Surface Reflectivity')
             attr_idx = SD.findattr(sds_id, '_FillValue')
             fv = SD.readattr(sds_id, attr_idx)
             self.assertEqual(fv, 999.0)
             data = SD.readdata(sds_id)
             self.assertEqual(data[0, 0], 999.0)
             self.assertEqual(data[179, 287], 98.0)
예제 #3
0
    def test_basic(self):
        with SD.start(self.sdfile, SD.DFACC_READ) as sdid:
            idx = SD.nametoindex(sdid, 'Reflectivity')
            with SD.select(sdid, idx) as sds_id:
                data = SD.readdata(sds_id)

        driver = gdal.GetDriverByName('GTiff')
        src_ds = gdal.Open(self.sdfile)
        with tempfile.NamedTemporaryFile(suffix=".tif") as tfile:
            dst_ds = driver.Create(tfile.name, data.shape[1], data.shape[0], 1,
                                   gdal.GDT_Float32)
            dst_ds.SetProjection(src_ds.GetProjection())
            dst_ds.SetGeoTransform(src_ds.GetGeoTransform())
            if src_ds.GetGCPCount() > 0:
                dst_ds.SetGCPs(src_ds.get_GCPs(), src_ds.GetGCPProjection())
            dst_ds.GetRasterBand(1).WriteArray(data)
            dst_ds = None
예제 #4
0
    def test_basic(self):
        with SD.start(self.sdfile, SD.DFACC_READ) as sdid:
            idx = SD.nametoindex(sdid, 'Reflectivity')
            with SD.select(sdid, idx) as sds_id:
                data = SD.readdata(sds_id)

        nrows, ncols = data.shape
        with tempfile.NamedTemporaryFile(suffix=".tif") as tfile:
            with TIFF.open(tfile.name, 'w') as tifp:
                TIFF.setfield(tifp, 'ImageWidth', ncols)
                TIFF.setfield(tifp, 'ImageLength', nrows)
                TIFF.setfield(tifp, 'SamplesPerPixel', 1)
                TIFF.setfield(tifp, 'BitsPerSample', 32)
                TIFF.setfield(tifp, 'PlanarConfiguration', TIFF.PLANARCONFIG_CONTIG)
                TIFF.setfield(tifp, 'PhotometricInterpretation', TIFF.PHOTOMETRIC_MINISBLACK)
                TIFF.setfield(tifp, 'SampleFormat', TIFF.SAMPLEFORMAT_IEEEFP)
                TIFF.setfield(tifp, 'RowsPerStrip', nrows)
                TIFF.writeencodedstrip(tifp, 0, data)
            import shutil
            shutil.copyfile(tfile.name,
                            os.path.join(os.environ['HOME'], 'b.tif'))