MazamaScience / MazamaSatelliteUtils

Satellite Data Download and Utility Functions
http://mazamascience.github.io/MazamaSatelliteUtils
GNU Lesser General Public License v3.0
0 stars 0 forks source link

SPDFs from faulty scan files #84

Closed tabrasel closed 3 years ago

tabrasel commented 3 years ago

Some scan files cannot be read due to errors:

ncdf4::nc_open("~/Data/Satellite/OR_ABI-L2-AODC-M6_G17_s20202522231174_e20202522233547_c20202522235327.nc")

# Error in R_nc4_open: NetCDF: HDF error
# Error in ncdf4::nc_open("~/Data/Satellite/OR_ABI-L2-AODC-M6_G17_s20202522231174_e20202522233547_c20202522235327.nc") : 
#   Error in nc_open trying to open file /Users/Tate/Data/Satellite/OR_ABI-L2-AODC-M6_G17_s20202522231174_e20202522233547_c20202522235327.nc

This is a problem when making plots, generating movies, and averaging scans, since these all rely on scan files being converted into valid SpatialPointDataFrames by goesaodc_createScanSPDF(). What should happen when a file can't be opened? Should the scripts halt? Or should goesaodc_createScanSPDF() return something special?

I think the best option would be for goesaodc_createScanSPDF() to return an SPDF of points at the standard satellite reading locations, but have each AOD and DQF reading set to NA. This way an SPDF is still technically being created, and it can be plotted*, rasterized (the raster cells will be NA as well, which is fine), and averaged with other SPDFs with no extra code or checks. It is a more complicated solution to implement though over just returning NULL or an empty SPDF (which have their own drawbacks).

The main issue is will be that a color legend can't be drawn since all the points have NA values:

# SPDF with NAs
spdf <- sp::SpatialPointsDataFrame(
  coords = data.frame(lon = 0, lat = 0),
  data = data.frame(AOD = NA, DQF = NA)
)

# Error: Discrete value supplied to continuous scale
goesaodc_plotScanSPDF(
  spdf
)  

# Error: Binned scales only support continuous data
goesaodc_plotScanSPDF(
  spdf,
  breaks = c(-Inf, 0, 1, 2, 3, 4, 5, Inf)
)  

Legends pose an issue for animations too: How do we guarantee a consistent legend is drawn across all of the individual frames (plots)? Will requiring the user to set the limits param for ggplot2::scale/fill_color_*() do the trick? What about when a scan's AOD values are NA and the legend for that frame can't even be drawn? Is it possible to draw an invisible second ggplot2::geom_point() or ggplot2::geom_raster() layer that sets some dummy values and uses the color/fill aes() so the legend is drawn for that?