Skip to content

Commit

Permalink
Update vignettes to build faster
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed Nov 25, 2016
1 parent 2332bb2 commit 4584356
Show file tree
Hide file tree
Showing 9 changed files with 928 additions and 17 deletions.
Binary file modified revdep/checks.rds
Binary file not shown.
61 changes: 51 additions & 10 deletions vignettes/Specified_stations_for_a_range_of_years.Rmd
Expand Up @@ -30,38 +30,39 @@ include:
First we retrieve data from GADM.org that will provide the provincial spatial
data for the survey area. We will then use this to find the centroid, which will
be used to find the nearest stations.
```{r, RP Data, message=FALSE, eval=FALSE}

```r
library(raster)
library(rgdal)

RP <- getData(country = "Philippines", level = 1)
```
Select the provinces involved in the survey and make a new object called
`Central_Luzon`.

```{R, Central_Luzon, eval=FALSE}

```r
Central_Luzon <- RP[RP@data$NAME_1 == "Pampanga" |
RP@data$NAME_1 == "Tarlac" |
RP@data$NAME_1 == "Pangasinan" |
RP@data$NAME_1 == "La Union" |
RP@data$NAME_1 == "Nueva Ecija" |
RP@data$NAME_1 == "Bulacan", ]
```

## Dissolve Polygons and Find Centroid of Loop Survey Area
Now that we have the provincial data imported, we will dissolve the polygons and
find the centroid.

```{r, dissolve, message=FALSE, eval=FALSE}

```r
library(rgeos)
Central_Luzon <- gUnaryUnion(Central_Luzon)
centroid <- gCentroid(Central_Luzon)
```

```{r, nearest_stations, message=FALSE, eval=FALSE}

```r
library(GSODR)
library(readr)
# Fetch station list from NCDC
Expand All @@ -82,7 +83,6 @@ loop_stations <- station_meta[station_meta$STNID %in% loop_stations, ]

loop_stations <- loop_stations[loop_stations$BEGIN <= 19591231 &
loop_stations$END >= 20151231, ]
```

## Using get_GSOD to Fetch the Requested Station Files
Expand All @@ -95,11 +95,11 @@ function. Be aware that it may result in incomplete data and error from the
server. If it does this, see the following option for using the `format_GSOD`
function.

```{r, fetch_weather, message=FALSE, eval=FALSE}

```r
get_GSOD(station = eval(parse(text = loop_stations[, 12])), years = 1960:2015,
CSV = TRUE, dsn = "~/",
filename = "Loop_Survey_Weather_1960-1969")
```

## Another Option
Expand All @@ -116,7 +116,8 @@ directory, "gsod-YYYY.tar" and untar them locally and then use R to
list the available files and select only the files for the stations of interest.
Lastly, write the data to disk as a CSV file for saving and later use.

```{r, list_local_files, eval=FALSE}

```r
years <- 1960:2015

loop_stations <- eval(parse(text = loop_stations[, 12]))
Expand All @@ -134,4 +135,44 @@ loop_data <- reformat_GSOD(file_list = local_files)
write.csv(loop_data, file = "Loop_Survey_Weather_1960-1969")
```

# Notes

## Sources

#### CHELSA climate layers
CHELSA (climatic surfaces at 1 km resolution) is based on a quasi-mechanistical
statistical downscaling of the ERA interim global circulation model
(Karger et al. 2016). ESA's CCI-LC cloud probability monthly averages are based
on the MODIS snow products (MOD10A2). <http://chelsa-climate.org/>

#### EarthEnv MODIS cloud fraction
<http://www.earthenv.org/cloud>

#### ESA's CCI-LC cloud probability
<http://maps.elie.ucl.ac.be/CCI/viewer/index.php>

#### Elevation Values

90m hole-filled SRTM digital elevation (Jarvis *et al.* 2008) was used
to identify and correct/remove elevation errors in data for station
locations between -60˚ and 60˚ latitude. This applies to cases here
where elevation was missing in the reported values as well. In case the
station reported an elevation and the DEM does not, the station reported
is taken. For stations beyond -60˚ and 60˚ latitude, the values are
station reported values in every instance. See
<https://github.com/adamhsparks/GSODR/blob/devel/data-raw/fetch_isd-history.md>
for more detail on the correction methods.

## WMO Resolution 40. NOAA Policy

*Users of these data should take into account the following (from the
[NCDC website](http://www7.ncdc.noaa.gov/CDO/cdoselect.cmd?datasetabbv=GSOD&countryabbv=&georegionabbv=)):*

> "The following data and products may have conditions placed on their
international commercial use. They can be used within the U.S. or for
non-commercial international activities without restriction. The
non-U.S. data cannot be redistributed for commercial purposes.
Re-distribution of these data by others must provide this same
notification." [WMO Resolution 40. NOAA
Policy](http://www.wmo.int/pages/about/Resolution40.html)

46 changes: 46 additions & 0 deletions vignettes/Specified_stations_for_a_range_of_years.html
Expand Up @@ -335,6 +335,52 @@ <h2>Another Option</h2>
write.csv(loop_data, file = &quot;Loop_Survey_Weather_1960-1969&quot;)
</code></pre>

<h1>Notes</h1>

<h2>Sources</h2>

<h4>CHELSA climate layers</h4>

<p>CHELSA (climatic surfaces at 1 km resolution) is based on a quasi-mechanistical
statistical downscaling of the ERA interim global circulation model
(Karger et al. 2016). ESA&#39;s CCI-LC cloud probability monthly averages are based
on the MODIS snow products (MOD10A2). <a href="http://chelsa-climate.org/">http://chelsa-climate.org/</a></p>

<h4>EarthEnv MODIS cloud fraction</h4>

<p><a href="http://www.earthenv.org/cloud">http://www.earthenv.org/cloud</a></p>

<h4>ESA&#39;s CCI-LC cloud probability</h4>

<p><a href="http://maps.elie.ucl.ac.be/CCI/viewer/index.php">http://maps.elie.ucl.ac.be/CCI/viewer/index.php</a></p>

<h4>Elevation Values</h4>

<p>90m hole-filled SRTM digital elevation (Jarvis <em>et al.</em> 2008) was used
to identify and correct/remove elevation errors in data for station
locations between -60˚ and 60˚ latitude. This applies to cases here
where elevation was missing in the reported values as well. In case the
station reported an elevation and the DEM does not, the station reported
is taken. For stations beyond -60˚ and 60˚ latitude, the values are
station reported values in every instance. See
<a href="https://github.com/adamhsparks/GSODR/blob/devel/data-raw/fetch_isd-history.md">https://github.com/adamhsparks/GSODR/blob/devel/data-raw/fetch_isd-history.md</a>
for more detail on the correction methods.</p>

<h2>WMO Resolution 40. NOAA Policy</h2>

<p><em>Users of these data should take into account the following (from the
<a href="http://www7.ncdc.noaa.gov/CDO/cdoselect.cmd?datasetabbv=GSOD&amp;countryabbv=&amp;georegionabbv=">NCDC website</a>):</em></p>

<blockquote>
<p>&ldquo;The following data and products may have conditions placed on their
international commercial use. They can be used within the U.S. or for
non-commercial international activities without restriction. The
non-U.S. data cannot be redistributed for commercial purposes.
Re-distribution of these data by others must provide this same
notification.&rdquo; <a href="http://www.wmo.int/pages/about/Resolution40.html">WMO Resolution 40. NOAA
Policy</a></p>
</blockquote>

</body>

</html>
40 changes: 40 additions & 0 deletions vignettes/Specified_stations_for_a_range_of_years.md
Expand Up @@ -135,4 +135,44 @@ loop_data <- reformat_GSOD(file_list = local_files)
write.csv(loop_data, file = "Loop_Survey_Weather_1960-1969")
```

# Notes

## Sources

#### CHELSA climate layers
CHELSA (climatic surfaces at 1 km resolution) is based on a quasi-mechanistical
statistical downscaling of the ERA interim global circulation model
(Karger et al. 2016). ESA's CCI-LC cloud probability monthly averages are based
on the MODIS snow products (MOD10A2). <http://chelsa-climate.org/>

#### EarthEnv MODIS cloud fraction
<http://www.earthenv.org/cloud>

#### ESA's CCI-LC cloud probability
<http://maps.elie.ucl.ac.be/CCI/viewer/index.php>

#### Elevation Values

90m hole-filled SRTM digital elevation (Jarvis *et al.* 2008) was used
to identify and correct/remove elevation errors in data for station
locations between -60˚ and 60˚ latitude. This applies to cases here
where elevation was missing in the reported values as well. In case the
station reported an elevation and the DEM does not, the station reported
is taken. For stations beyond -60˚ and 60˚ latitude, the values are
station reported values in every instance. See
<https://github.com/adamhsparks/GSODR/blob/devel/data-raw/fetch_isd-history.md>
for more detail on the correction methods.

## WMO Resolution 40. NOAA Policy

*Users of these data should take into account the following (from the
[NCDC website](http://www7.ncdc.noaa.gov/CDO/cdoselect.cmd?datasetabbv=GSOD&countryabbv=&georegionabbv=)):*

> "The following data and products may have conditions placed on their
international commercial use. They can be used within the U.S. or for
non-commercial international activities without restriction. The
non-U.S. data cannot be redistributed for commercial purposes.
Re-distribution of these data by others must provide this same
notification." [WMO Resolution 40. NOAA
Policy](http://www.wmo.int/pages/about/Resolution40.html)

63 changes: 63 additions & 0 deletions vignettes/Working_with_spatial_and_climate_data.R
@@ -0,0 +1,63 @@
## ----example_1, eval=TRUE, message=FALSE, results='hide'-----------------
library(GSODR)
get_GSOD(years = 2010, country = "Philippines", dsn = "~/",
filename = "PHL-2010", GPKG = TRUE, max_missing = 5)

## ----example_1.1, eval=TRUE, echo=TRUE-----------------------------------
library(rgdal)
library(spacetime)
library(plotKML)

layers <- ogrListLayers(dsn = path.expand("~/PHL-2010.gpkg"))
pnts <- readOGR(dsn = path.expand("~/PHL-2010.gpkg"), layers[1])

# Plot results in Google Earth as a spacetime object:
pnts$DATE = as.Date(paste(pnts$YEAR, pnts$MONTH, pnts$DAY, sep = "-"))
row.names(pnts) <- paste("point", 1:nrow(pnts), sep = "")

tmp_ST <- STIDF(sp = as(pnts, "SpatialPoints"),
time = pnts$DATE - 0.5,
data = pnts@data[, c("TEMP", "STNID")],
endTime = pnts$DATE + 0.5)

shape = "http://maps.google.com/mapfiles/kml/pal2/icon18.png"

kml(tmp_ST, dtime = 24 * 3600, colour = TEMP, shape = shape, labels = TEMP,
file.name = "Temperatures_PHL_2010-2010.kml", folder.name = "TEMP")

system("zip -m Temperatures_PHL_2010-2010.kmz Temperatures_PHL_2010-2010.kml")

## ----example_1.2, eval=TRUE, fig.cap="Comparison of GSOD daily values and average monthly values with CHELSA climate monthly values", fig.width=8----
library(dplyr)
library(ggplot2)
library(reshape2)

data(GSOD_clim)
cnames <- paste0("CHELSA_temp_", 1:12, "_1979-2013")
clim_temp <- GSOD_clim[GSOD_clim$STNID %in% pnts$STNID,
paste(c("STNID", cnames))]
clim_temp_df <- data.frame(STNID = rep(clim_temp$STNID, 12),
MONTHC = as.vector(sapply(1:12, rep,
times = nrow(clim_temp))),
CHELSA_TEMP = as.vector(unlist(clim_temp[, cnames])))

pnts$MONTHC <- as.numeric(paste(pnts$MONTH))
temp <- left_join(pnts@data, clim_temp_df, by = c("STNID", "MONTHC"))

temp <- temp %>%
group_by(MONTH) %>%
mutate(AVG_DAILY_TEMP = round(mean(TEMP), 1))

df_melt <- na.omit(melt(temp[, c("STNID", "DATE", "CHELSA_TEMP", "TEMP", "AVG_DAILY_TEMP")],
id = c("DATE", "STNID")))

ggplot(df_melt, aes(x = DATE, y = value)) +
geom_point(aes(color = variable), alpha = 0.2) +
scale_x_date(date_labels = "%b") +
ylab("Temperature (C)") +
xlab("Month") +
labs(colour = "") +
scale_color_brewer(palette = "Dark2") +
facet_wrap( ~ STNID)


0 comments on commit 4584356

Please sign in to comment.