Skip to content

Commit

Permalink
remove fill value
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Dec 20, 2023
1 parent 668f39b commit 114dd8f
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion R/blackmarbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,46 @@ pad3 <- function(x){
}
pad3 <- Vectorize(pad3)

remove_fill_value <- function(x, variable){
# Apply scaling factor to variables according to Black Marble user guide

# https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
# * Table 3 (page 12)
# * Table 6 (page 16)
# * Table 9 (page 18)

if(variable %in% c(

# VNP46A1
"DNB_At_Sensor_Radiance",

# VNP46A2
"DNB_BRDF-Corrected_NTL",
"Gap_Filled_DNB_BRDF-Corrected_NTL",
"DNB_Lunar_Irradiance",

# VNP46A3/4
"AllAngle_Composite_Snow_Covered",
"AllAngle_Composite_Snow_Covered_Std",
"AllAngle_Composite_Snow_Free",
"AllAngle_Composite_Snow_Free_Std",
"NearNadir_Composite_Snow_Covered",
"NearNadir_Composite_Snow_Covered_Std",
"NearNadir_Composite_Snow_Free",
"NearNadir_Composite_Snow_Free_Std",
"OffNadir_Composite_Snow_Covered",
"OffNadir_Composite_Snow_Covered_Std",
"OffNadir_Composite_Snow_Free",
"OffNadir_Composite_Snow_Free_Std")
){

if(x == 65535) x <- NA

}

return(x)
}

apply_scaling_factor <- function(x, variable){
# Apply scaling factor to variables according to Black Marble user guide

Expand All @@ -73,7 +113,7 @@ apply_scaling_factor <- function(x, variable){

# VNP46A2
"DNB_BRDF-Corrected_NTL",
"Gap_Filled_DNB_BRDFCorrected_NTL",
"Gap_Filled_DNB_BRDF-Corrected_NTL",
"DNB_Lunar_Irradiance",

# VNP46A3/4
Expand All @@ -90,7 +130,9 @@ apply_scaling_factor <- function(x, variable){
"OffNadir_Composite_Snow_Free",
"OffNadir_Composite_Snow_Free_Std")
){

x <- x * 0.1

}

return(x)
Expand Down Expand Up @@ -224,6 +266,9 @@ file_to_raster <- function(f,
#assign the extents to the raster
extent(outr) <- rasExt

#set fill values to NA
outr <- remove_fill_value(outr, variable)

#apply scaling factor
outr <- apply_scaling_factor(outr, variable)

Expand Down

0 comments on commit 114dd8f

Please sign in to comment.