From 114dd8f03cb1db4930e8d0b03f6f04c8541686b6 Mon Sep 17 00:00:00 2001 From: Rob Marty Date: Wed, 20 Dec 2023 15:32:09 -0500 Subject: [PATCH] remove fill value --- R/blackmarbler.R | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/R/blackmarbler.R b/R/blackmarbler.R index a6bb398..8ac7636 100644 --- a/R/blackmarbler.R +++ b/R/blackmarbler.R @@ -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 @@ -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 @@ -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) @@ -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)