1

I have two raster in brick format, as a result of previous operations, they have the same characteristics. When I try to make a simple subtraction between the two, it gives me a constant in all my study area. when I do other operations like multiply, add or divide it works perfectly, but not with subtraction. Anyone have any idea what might be happening?

reading the previous queries I have tried replacing NA values, with different raster formats and nothing. the input values of the subtraction are obtained by different functions.

Rtoa_B1 <- Rtoa_F(d, RadianceB1, Eo,Us)
Rsuperf_B1 <- Rsuperf_F(RadianceB1,Lr1,Tv,Eo,d,Oz,Tz,Edown)
Ratm <- Rtoa_B1 - Rsuperf_B1

the classes of the obtained files are

> Rtoa_B1
class      : RasterBrick 
dimensions : 118, 111, 13098, 1  (nrow, ncol, ncell, nlayers)
resolution : 0.004500776, 0.004518253  (x, y)
extent     : -75.7172, -75.21762, 5.978564, 6.511717  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +a=6378137 +rf=298.25722293287 +no_defs 
source     : memory
names      : B1_MOD02HKM.A2019001.1605.061.2019002013822 
min values :                                  0.08510739 
max values :                                   0.3040431 

> Rsuperf_B1
class      : RasterBrick 
dimensions : 118, 111, 13098, 1  (nrow, ncol, ncell, nlayers)
resolution : 0.004500776, 0.004518253  (x, y)
extent     : -75.7172, -75.21762, 5.978564, 6.511717  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +a=6378137 +rf=298.25722293287 +no_defs 
source     : memory
names      : B1_MOD02HKM.A2019001.1605.061.2019002013822 
min values :                                   0.0617993 
max values :                                    0.280735 

> Ratm
class      : RasterLayer 
dimensions : 118, 111, 13098  (nrow, ncol, ncell)
resolution : 0.004500776, 0.004518253  (x, y)
extent     : -75.7172, -75.21762, 5.978564, 6.511717  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +a=6378137 +rf=298.25722293287 +no_defs 
source     : memory
names      : layer 
values     : 0.02330808, 0.02330808  (min, max)

the functions

Rsuperf_F <- function(radiance,Lr,Tv,Eo,d,Oz,Tz,Edown){
  
  return((pi*(radiance-Lr)*(d**2))/(Tv*((Eo*cos(Oz)*Tz)+Edown)))
}
Rtoa_F <- function(d,radiance,Eo,Us){
  
  return(  (pi*(d**2)*radiance)/(Eo*Us)   )
}

function values are previously calculated

5
  • Not sure we can do much without either your data or some more information about the objects in your R session. What constant value are you getting? What are the values in the raster cells? Does Rtoa_B1[1,1] - Rsuperf[1,1] not equal Ratm[1,1]? – Spacedman Mar 28 at 20:41
  • thanks for answering. the constant value I get is the subtraction of the minimum values (0.0212086). raster cell values are in the range (0 - 1). No, they are not the same. what seems very strange to me is that all arithmetic operations work except subtraction. the files are of type:> class(Rtoa_B1) [1] "RasterBrick" attr(,"package") [1] "raster" – Iván Andres Mar 28 at 22:11
  • Can you use the "edit" link on your question to add the extra information - and show us the output of print(Rtoa_B1) and print(Rsuperf_B1) and print(Ratm) so we can see what the size and structure of these stacks are. Also where does the Rsuperf_F function come from? – Spacedman Mar 28 at 22:29
  • Of course, ta edit it. In theory it should give a raster of positive values between (0.1 - 0.9) – Iván Andres Mar 28 at 22:46
  • This was answered here: stackoverflow.com/questions/66844870/… – Robert Hijmans Apr 1 at 23:21
0

the raster data is different but their differences with respect to the other are the same, never imagine that because the functions are affected by some different variables. I will review the methodology. Thank you for your attention.

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.