0

I am working with Landsat 8 satellite data. In the scene data that I am analyzing, the band 10 pixel values are:

low: 0 high: 39087

After I crop the raster, the pixel values are now:

low: 0 high: 32767

The high is curious since that is the maximum value of a signed 16 bit integer.

Here is my code:

> boundary
class       : SpatialPolygonsDataFrame 
features    : 11 
extent      : 637437.7, 785925.9, 4208959, 4380055  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 22
names       : OBJECTID_1, OBJECTID, STATEFP, COUNTYFP, COUNTYNS, GEOID,    NAME,       NAMELSAD, LSAD, CLASSFP, MTFCC, CSAFP, CBSAFP, METDIVFP, FUNCSTAT, ... 
min values  :          1,       10,      17,      013, 00424208, 17013, Calhoun, Calhoun County,   06,      C7, G4020,   476,  41180,       NA,        A, ... 
max values  :          9,        9,      29,      510, 01784865, 29510,  Warren,  Warren County,   25,      H1, G4020,   476,  41180,       NA,        F, ... 

> extent(boundary)
class       : Extent 
xmin        : 637437.7 
xmax        : 785925.9 
ymin        : 4208959 
ymax        : 4380055 

> band_10_crop <- crop(band_10, extent(boundary))

> band_10_crop
class       : RasterLayer 
dimensions  : 5703, 4950, 28229850  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 637425, 785925, 4208955, 4380045  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:/Users/xxx/AppData/Local/Temp/RtmpYvDjWO/raster/r_tmp_2019-04-24_151922_244_04468.grd 
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 32767  (min, max)

Is this a limitation of crop() or am I misusing the function?

I am running 64-bit R 3.4.4 on Windows 7.

Update I can no longer reproduce the issue. Below are the results of re-running the above statements (adding those as suggested by @Spacedman).

> band_10
class       : RasterLayer 
dimensions  : 7741, 7621, 58994161  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 580185, 808815, 4191885, 4424115  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : E:/Projects/Urban Heat Island/Source_Data/USGS/Landsat/LC08_L1TP_024033_20180707_20180717_01_T1/LC08_L1TP_024033_20180707_20180717_01_T1_B10.TIF 
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 65535  (min, max)

> boundary
class       : SpatialPolygonsDataFrame 
features    : 11 
extent      : 637437.7, 785925.9, 4208959, 4380055  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 22
names       : OBJECTID_1, OBJECTID, STATEFP, COUNTYFP, COUNTYNS, GEOID,    NAME,       NAMELSAD, LSAD, CLASSFP, MTFCC, CSAFP, CBSAFP, METDIVFP, FUNCSTAT, ... 
min values  :          1,       10,      17,      013, 00424208, 17013, Calhoun, Calhoun County,   06,      C7, G4020,   476,  41180,       NA,        A, ... 
max values  :          9,        9,      29,      510, 01784865, 29510,  Warren,  Warren County,   25,      H1, G4020,   476,  41180,       NA,        F, ... 

> extent(boundary)
class       : Extent 
xmin        : 637437.7 
xmax        : 785925.9 
ymin        : 4208959 
ymax        : 4380055 

> band_10_crop_polygon <- crop(band_10, extent(boundary))
> band_10_crop_polygon
class       : RasterLayer 
dimensions  : 5703, 4950, 28229850  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 637425, 785925, 4208955, 4380045  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 41065  (min, max)


> band_10_crop_raster <- crop(band_10, extent(band_10))
> band_10_crop_raster
class       : RasterLayer 
dimensions  : 7741, 7621, 58994161  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 580185, 808815, 4191885, 4424115  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : E:/Projects/Urban Heat Island/Source_Data/USGS/Landsat/LC08_L1TP_024033_20180707_20180717_01_T1/LC08_L1TP_024033_20180707_20180717_01_T1_B10.TIF 
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 65535  (min, max)

Update Redux The issue was due to setting maxmemory to low. The working environment in the prior update was not memory constrained and thus did not exhibit the issue.

  • Can you show us the summary of band_10? Or the metadata of the raster? What happens if you crop band_10 with its own extent (so the returned raster should be unchanged)? Maybe it is coincidence. – Spacedman Apr 24 '19 at 21:25
  • The trigger to check the values was that I had NoData cells where I wasn't expecting them. Tracing my steps, they were being introduced during the clip step. It was then that I noticed that cells with pixel values above 32767 were set to NoData after the clip. I got around crop() by performing the clip in a desktop GIS tool. I will run the band_10 self clip tomorrow and post those results at that time along with the band_10 summary. – Michael Wohlstadter Apr 24 '19 at 21:47
1

The issue was caused by setting the value of maxmemory in rasterOptions(). Setting the value to less than 1390802016 caused the pixel values to be set to NoData when they exceeded 32767.

> rasterOptions(maxmemory = 1390802016)
> band_10_crop_polygon <- crop(band_10, extent(boundary))
> band_10_crop_polygon
class       : RasterLayer 
dimensions  : 5703, 4950, 28229850  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 637425, 785925, 4208955, 4380045  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 41065  (min, max)

> rasterOptions(maxmemory = 1390802015)
> band_10_crop_polygon <- crop(band_10, extent(boundary))
> band_10_crop_polygon
class       : RasterLayer 
dimensions  : 5703, 4950, 28229850  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 637425, 785925, 4208955, 4380045  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=15 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:/Users/xxx/AppData/Local/Temp/RtmpWM5Oqw/raster/r_tmp_2019-04-25_141609_9544_50588.grd 
names       : LC08_L1TP_024033_20180707_20180717_01_T1_B10 
values      : 0, 32767  (min, max)

Notice also that when maxmemory is set too low, the data source for the raster uses a temporary file as opposed to being in memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.