Skip to content

Commit

Permalink
Merge pull request #715 from kadyb/main
Browse files Browse the repository at this point in the history
update README
  • Loading branch information
edzer authored Oct 9, 2024
2 parents ec1f849 + f6b7cc4 commit bcf0f4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 46 deletions.
17 changes: 8 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ is_online = curl::has_internet()
[![CRAN](https://www.r-pkg.org/badges/version/stars)](https://cran.r-project.org/package=stars)
[![cran checks](https://badges.cranchecks.info/worst/stars.svg)](https://cran.r-project.org/web/checks/check_results_stars.html)
[![Downloads](https://cranlogs.r-pkg.org/badges/stars?color=brightgreen)](https://www.r-pkg.org/pkg/stars)
[![status](https://tinyverse.netlify.com/badge/stars)](https://CRAN.R-project.org/package=stars)
[![status](https://tinyverse.netlify.app/badge/stars)](https://CRAN.R-project.org/package=stars)
[![Codecov test coverage](https://codecov.io/gh/r-spatial/stars/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-spatial/stars?branch=main)
<!-- badges: end -->

Expand All @@ -27,7 +27,7 @@ Spatiotemporal data often comes in the form of dense arrays, with space and time

- socio-economic or demographic data,
- environmental variables monitored at fixed stations,
- raster maps
- raster maps,
- time series of satellite images with multiple spectral bands,
- spatial simulations, and
- climate or weather model output.
Expand Down Expand Up @@ -55,8 +55,8 @@ knitr::include_graphics("https://raw.githubusercontent.com/r-spatial/stars/main/
```

or lower-dimensional cubes such as a raster image:
```{r plot1}
suppressPackageStartupMessages(library(dplyr))
```{r plot1, message=FALSE}
library(dplyr)
library(stars)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
read_stars(tif) |>
Expand Down Expand Up @@ -90,7 +90,7 @@ y = c(1, 1.5, 3, 3.5)
d = st_dimensions(x = x, y = y, .raster = c("x", "y"))
r4 = st_as_stars(r = m, dimensions = d)
grd = st_make_grid(cellsize = c(10,10), offset = c(-130,10), n= c(8,5), crs=st_crs(4326))
grd = st_make_grid(cellsize = c(10,10), offset = c(-130,10), n = c(8,5), crs = st_crs(4326))
r5 = st_transform(grd, "+proj=laea +lon_0=-70 +lat_0=35")
par(mfrow = c(2,3))
Expand Down Expand Up @@ -180,20 +180,19 @@ index, and then the corresponding time value:
```{r plot5, fig.height=3}
index_max = function(x) ifelse(all(is.na(x)), NA, which.max(x))
b = st_apply(a, "geom", index_max)
b |> mutate(when = st_get_dimension_values(a, "time")[b$index_max]) |>
b |> mutate(when = st_get_dimension_values(a, "time")[b$index_max]) |>
select(when) |>
plot(key.pos = 1, main = "time of maximum precipitation")
```

With package `cubble`, we can make a glyph map to see the magnitude and timings of county maximum precipitation:
```{r plot6, fig.height=3}
```{r plot6, fig.height=3, message=FALSE, warning=FALSE}
library(cubble)
library(ggplot2)
a |> setNames("precip") |>
st_set_dimensions(2, name = "tm") |>
units::drop_units() |>
as_cubble(key = id, index = tm) |>
suppressWarnings() -> a.cb
as_cubble(key = id, index = tm) -> a.cb
a.cb |>
face_temporal() |>
unfold(long, lat) |>
Expand Down
54 changes: 17 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![cran
checks](https://badges.cranchecks.info/worst/stars.svg)](https://cran.r-project.org/web/checks/check_results_stars.html)
[![Downloads](https://cranlogs.r-pkg.org/badges/stars?color=brightgreen)](https://www.r-pkg.org/pkg/stars)
[![status](https://tinyverse.netlify.com/badge/stars)](https://CRAN.R-project.org/package=stars)
[![status](https://tinyverse.netlify.app/badge/stars)](https://CRAN.R-project.org/package=stars)
[![Codecov test
coverage](https://codecov.io/gh/r-spatial/stars/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-spatial/stars?branch=main)
<!-- badges: end -->
Expand All @@ -18,7 +18,7 @@ and time being array dimensions. Examples include

- socio-economic or demographic data,
- environmental variables monitored at fixed stations,
- raster maps
- raster maps,
- time series of satellite images with multiple spectral bands,
- spatial simulations, and
- climate or weather model output.
Expand All @@ -44,11 +44,8 @@ spectral band and sensor form dimensions:
or lower-dimensional cubes such as a raster image:

``` r
suppressPackageStartupMessages(library(dplyr))
library(dplyr)
library(stars)
# Loading required package: abind
# Loading required package: sf
# Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
tif = system.file("tif/L7_ETMs.tif", package = "stars")
read_stars(tif) |>
slice(index = 1, along = "band") |>
Expand Down Expand Up @@ -111,12 +108,12 @@ methods(class = "stars_proxy")
# [9] coerce dim droplevels filter
# [13] hist image initialize is.na
# [17] Math merge mutate Ops
# [21] plot predict print pull
# [25] rename select show slice
# [29] slotsFromS3 split st_apply st_as_sf
# [33] st_as_stars st_crop st_dimensions<- st_downsample
# [37] st_mosaic st_normalize st_redimension st_sample
# [41] st_set_bbox transmute write_stars
# [21] plot prcomp predict print
# [25] pull rename select show
# [29] slice slotsFromS3 split st_apply
# [33] st_as_sf st_as_stars st_crop st_dimensions<-
# [37] st_downsample st_mosaic st_normalize st_redimension
# [41] st_sample st_set_bbox transmute write_stars
# see '?methods' for accessing help and source code
```

Expand All @@ -135,10 +132,10 @@ prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars")
# Max.
# Total_precipitation_surface... [kg/m^2] 163.75
# dimension(s):
# from to offset delta refsys
# x 1 87 NA NA WGS 84 (CRS84)
# y 1 118 NA NA WGS 84 (CRS84)
# time 1 23 2018-09-13 19:00:00 UTC 1 hours POSIXct
# from to offset delta refsys
# x 1 87 NA NA WGS 84
# y 1 118 NA NA WGS 84
# time 1 23 2018-09-13 19:00:00 UTC 1 hours POSIXct
# values x/y
# x [87x118] -80.61 [°],...,-74.88 [°] [x]
# y [87x118] 32.44 [°],...,37.62 [°] [y]
Expand Down Expand Up @@ -174,7 +171,7 @@ and then the corresponding time value:
``` r
index_max = function(x) ifelse(all(is.na(x)), NA, which.max(x))
b = st_apply(a, "geom", index_max)
b |> mutate(when = st_get_dimension_values(a, "time")[b$index_max]) |>
b |> mutate(when = st_get_dimension_values(a, "time")[b$index_max]) |>
select(when) |>
plot(key.pos = 1, main = "time of maximum precipitation")
```
Expand All @@ -186,17 +183,11 @@ timings of county maximum precipitation:

``` r
library(cubble)
#
# Attaching package: 'cubble'
# The following object is masked from 'package:stats':
#
# filter
library(ggplot2)
a |> setNames("precip") |>
st_set_dimensions(2, name = "tm") |>
units::drop_units() |>
as_cubble(key = id, index = tm) |>
suppressWarnings() -> a.cb
as_cubble(key = id, index = tm) -> a.cb
a.cb |>
face_temporal() |>
unfold(long, lat) |>
Expand All @@ -205,17 +196,6 @@ a.cb |>
geom_sf(data = nc, inherit.aes = FALSE) +
geom_glyph_box(width = 0.3, height = 0.1) +
geom_glyph(width = 0.3, height = 0.1)
# Warning: There were 84 warnings in `dplyr::mutate()`.
# The first warning was:
# ℹ In argument: `y = .data$y_major + rescale11(.data$y_minor) * .data$height/2`.
# ℹ In group 12: `group = 12`.
# Caused by warning in `min()`:
# ! no non-missing arguments to min; returning Inf
# ℹ Run `dplyr::last_dplyr_warnings()` to see the 83 remaining warnings.
# Warning: Removed 966 rows containing missing values or values outside the scale range
# (`geom_glyph_box()`).
# Warning: Removed 966 rows containing missing values or values outside the scale range
# (`geom_glyph()`).
```

![](man/figures/README-plot6-1.png)<!-- -->
Expand Down Expand Up @@ -266,8 +246,8 @@ A comment on the differences between `stars` and `terra` is found

- blog posts: [first](https://r-spatial.org/r/2017/11/23/stars1.html),
[second](https://r-spatial.org/r/2018/03/22/stars2.html),
[third](https://r-spatial.org/r/2018/03/23/stars3.html), and
[newer blog posts](https://r-spatial.org/)
[third](https://r-spatial.org/r/2018/03/23/stars3.html), and [newer
blog posts](https://r-spatial.org/)
- [vignettes](https://r-spatial.github.io/stars/articles/)
- the original [R Consortium
proposal](https://github.com/r-spatial/stars/blob/main/PROPOSAL.md).
Expand Down

0 comments on commit bcf0f4a

Please sign in to comment.