Created
August 22, 2018 20:40
-
-
Save dblodgett-usgs/7732ed8cb54f6b389bc88db6e7c7b998 to your computer and use it in GitHub Desktop.
Create ncdfgeom sample file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github("USGS-R/ncdfgeom") | |
# Also need jsonlite and sf but devtools should install with ncdfgeom | |
fixtureData <- jsonlite::fromJSON(system.file("extdata/fixture_wkt.json", | |
package = "ncdfgeom")) | |
polygon <- sf::st_sf(geom = sf::st_as_sfc(fixtureData$`2d`$polygon), | |
crs = "+init=epsg:4326") | |
lon_lat <- sf::st_coordinates(sf::st_centroid(polygon)) | |
data_length <- 9 | |
seed <- seq(0, 2*pi, length.out = data_length) | |
times <- seq(as.POSIXct("1970-01-01 00:00", tz = "gmt"), by = "day", length.out = data_length) | |
ts <- data.frame(i = sin(seed)) | |
dm <- list(name="sin", | |
long_name="the sin function") | |
ts2 <- data.frame(i = cos(seed)) | |
dm2 <- list(name = "cos", | |
long_name = "the cos function") | |
ncdfgeom::write_timeseries_dsg("polygon.nc", | |
instance_names = "i", | |
lats = lon_lat[,1], | |
lons = lon_lat[,2], | |
times = times, | |
data = ts, | |
data_unit = "unitless", | |
data_metadata = dm, | |
attributes = c(title = "title", | |
abstract = "very abstract", | |
provider_site = "CIDA", | |
provider_name ="The Blodg", | |
description = "A sample file")) | |
ncdfgeom::write_timeseries_dsg("polygon.nc", | |
instance_names = "i", | |
lats = lon_lat[,1], | |
lons = lon_lat[,2], | |
times = times, | |
data = ts2, | |
data_unit = "unitless", | |
data_metadata = dm2, | |
add_to_existing = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: