DOI-USGS/ncdfgeom

getting started

Closed this issue · 7 comments

edzer commented

The "getting started" vignette gives me the following warnings:

> climdiv_centroids <- climdiv_poly %>%
+   st_transform(5070) %>% # Albers Equal Area
+   st_set_agr("constant") %>%
+   st_centroid() %>%
+   st_transform(4269) %>% #NAD83 Lat/Lon
+   st_coordinates() %>%
+   as.data.frame()
> 
> nc_file <- "climdiv_prcp.nc"
> 
> prcp_dates <- prcp_data$date
> prcp_data <- select(prcp_data, -date)
Error in -x : invalid argument to unary operator
> prcp_meta <- list(name = "climdiv_prcp_inches", 
+                   long_name = "Estimated Monthly Precipitation (Inches)")
> 
> write_timeseries_dsg(nc_file = nc_file, 
+                      instance_names = climdiv_poly$CLIMDIV, 
+                      lats = climdiv_centroids$Y, 
+                      lons = climdiv_centroids$X, 
+                      times = prcp_dates, 
+                      data = prcp_data, 
+                      data_unit = rep("inches", (ncol(prcp_data) - 1)), 
+                      data_prec = "float", 
+                      data_metadata = prcp_meta, 
+                      attributes = list(title = "Demonstation of ncdfgeom"), 
+                      add_to_existing = FALSE) -> nc_file
Error in as.POSIXct.default(times) : 
  do not know how to convert 'times' to class “POSIXct”
> 
> climdiv_poly <- st_sf(st_cast(climdiv_poly, "MULTIPOLYGON"))
> 
> write_geometry(nc_file = "climdiv_prcp.nc", 
+                geom_data = climdiv_poly,
+                variables = "climdiv_prcp_inches") -> nc_file
Error : NetCDF: Variable not found
Error : NetCDF: Variable not found

and the resulting netcdf file's ncdump does not correspond to the one in the vignette:

netcdf climdiv_prcp {
dimensions:
    instance = 344 ;
    char = 30 ;
    node = 3169875 ;
    part = 1636 ;
variables:
    char CLIMDIV(instance, char) ;
        CLIMDIV:units = "unknown" ;
        CLIMDIV:missing_value = "" ;
        CLIMDIV:grid_mapping = "grid_mapping" ;
        CLIMDIV:geometry = "geometry_container" ;
    char CLIMDIV_NAME(instance, char) ;
        CLIMDIV_NAME:units = "unknown" ;
        CLIMDIV_NAME:missing_value = "" ;
        CLIMDIV_NAME:grid_mapping = "grid_mapping" ;
        CLIMDIV_NAME:geometry = "geometry_container" ;
    double x_nodes(node) ;
        x_nodes:units = "degrees_east" ;
        x_nodes:axis = "X" ;
    double y_nodes(node) ;
        y_nodes:units = "degrees_north" ;
        y_nodes:axis = "Y" ;
    int geometry_container ;
        geometry_container:node_coordinates = "x_nodes y_nodes" ;
        geometry_container:geometry_type = "polygon" ;
        geometry_container:node_count = "node_count" ;
        geometry_container:part_node_count = "part_node_count" ;
... etc

Follow-up issues:

> prcp_data <- read_timeseries_dsg("climdiv_prcp.nc")
Error in read_timeseries_dsg("climdiv_prcp.nc") : 
  A timeseries id variable was not found in the file.
In addition: Warning message:
In read_timeseries_dsg("climdiv_prcp.nc") :
  File does not advertise use of the CF timeseries featureType, unexpected behavior may result.

but

climdiv_poly <- read_geometry("climdiv_prcp.nc")

OK.

Thanks for this, @edzer I think I should modify this vignette so it doesn't use external data. There's some hidden code you need to run to get things to work and they download data to work with. I hesitate to build the demo code into the package though so... will have to think about maybe switching to a different sample dataset.

edzer commented

What is the hesitation? Yes, having the two tibbles as part of the package would lower some boundaries.

I wanted to have a "real" demo that goes end to end -- but in retrospect, I think it distracts for the point of the point of the vignette. I think I'll put the code to create the package-data at the bottom for reproducibility but cache the result in the package to lower the barrier to entry as you say.

edzer commented

Agreed. You could put the download + create script in a demo file, and point out how to run that in the getting started vignette.

edzer commented

Looking good, and can confirm it works!

Thanks!