https://github.com/atsyplenkov/filtrs
Rust-boosted linear and spatial filtering in R
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (17.9%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
Rust-boosted linear and spatial filtering in R
Basic Info
- Host: GitHub
- Owner: atsyplenkov
- License: other
- Language: R
- Default Branch: master
- Size: 244 KB
Statistics
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Created over 2 years ago
· Last pushed over 2 years ago
Metadata Files
Readme
License
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dpi = 1000
)
requireNamespace("smoothr", quietly = TRUE)
requireNamespace("bench", quietly = TRUE)
```
# filtrs
[](https://github.com/atsyplenkov/filtrs/actions/workflows/R-CMD-check.yaml)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://CRAN.R-project.org/package=filtrs)


Rust-Boosted Linear and Spatial Filtering in R.
Currently, the package supports only the Whittaker-Eilers smoother as it is implemented in the `whittaker-eilers` [crate](https://crates.io/crates/whittaker-eilers). Based on that filter, a smoothing approach for spatial geometries (only single-part `LINESTRING` for now) is proposed.
## Installation
You can install the development version of `filtrs` like so:
``` r
# install.packages(remotes)
remotes::install_github("atsyplenkov/filtrs")
```
## Time-series filtering
For equally-spaced data, one can use the `fil_wt` function as an API to `whittaker_eilers::WhittakerSmoother`. It has two controls, `lambda` and `order`, and interpolates missing values by default. An extremely nice description of the smoother is written by [Andrew Bowell](https://www.anbowell.com/blog/the-perfect-way-to-smooth-your-noisy-data).
```{r timeseries}
library(filtrs)
## basic example code
data("airquality")
airquality$Ozone_smooth <-
fil_wt(as.double(airquality$Ozone), 10, 2)
plot(airquality$Ozone, type = "l", xlab = "Days", ylab = "Ozone")
lines(airquality$Ozone_smooth, col = "red", lwd = 2)
```
## Spatial filtering
Spatial data may not be equally spaced; it often has more nodes on the bends of lines and fewer on straight segments. To address this challenge, the distance between nodes—calculated using either Cartesian or Haversine methods, depending on the Coordinate Reference System (CRS)—is used as a positions vector in the background. The function `fil_wt_sf` is designed to smooth a single `LINESTRING`, proving particularly beneficial for processing high-frequency data, such as that obtained from satellite imagery.
```{r spatial}
library(sf)
library(smoothr)
file_path <- system.file("exdata/examples.gpkg", package = "filtrs")
lines <-
sf::st_read(file_path, layer = "gswe", quiet = TRUE) |>
# Increase nodes count for smoother result
smoothr::smooth("densify", max_distance = 10)
lines_wt <-
fil_wt_sf(lines, lamda = 10^-7, order = 3)
lines_smoothr <-
smoothr::smooth(lines, method = "ksmooth",
smoothness = 21)
```
Plot’s code
```{r spatial_plot, eval=T, fig.show='hide'}
par(
mar = c(0.5, 0.5, 0.2, 0.2),
mfrow = c(1, 2),
oma = c(0, 0, 0.2, 0.2)
)
plot(
sf::st_geometry(lines),
col = "grey30",
lwd = 3.5
)
plot(
sf::st_geometry(lines_wt),
col = 'firebrick3',
lwd = 2,
add = TRUE
)
# Add the legend
legend(
"bottomleft",
legend = c("Original", "{filtrs}", "{smoothr}"),
col = c("grey30", "firebrick3", "dodgerblue3"),
lwd = c(3, 3)
)
plot(
sf::st_geometry(lines),
col = "grey30",
lwd = 3.5
)
plot(
sf::st_geometry(lines_smoothr),
col = 'dodgerblue3',
lwd = 2,
add = TRUE
)
```
Similar filtering can be achieved via the [`smoothr`](https://github.com/mstrimas/smoothr) R package; however, the Rust-based approach outperforms in speed when high-order smoothing is needed. For example, `r nrow(sf::st_coordinates(lines))` nodes were filtered 30 times faster using the `filtrs` package rather than `smoothr`.
```{r benchmark}
bench::mark(
filtrs = fil_wt_sf(lines, lamda = 10^-7, order = 3),
smoothr = smoothr::smooth(lines, method = "ksmooth", smoothness = 21),
check = F,
relative = T
)
```
## Similar packages
As linear and spatial filters are pretty common, there is no shortage of analogs.
* **[smoothr](https://github.com/mstrimas/smoothr)** - Spatial feature smoothing written in base R. However, there is no Whittaker-Eilers smoother.
* **[phenofit](https://github.com/eco-hydro/phenofit)** - As part of vegetation phenology, Whittaker-Eilers and Savitzky-Golay time-series filtering is implemented using Rcpp. No spatial filtering.
* **[signal](https://cran.r-project.org/web/packages/signal/index.html)** - A set of signal processing functions originally written for 'Matlab' and 'Octave'. No spatial filtering.
Owner
- Name: Anatolii Tsyplenkov
- Login: atsyplenkov
- Kind: user
- Location: New Zealand
- Company: @manaakiwhenua
- Website: anatolii.nz
- Repositories: 80
- Profile: https://github.com/atsyplenkov
Scientist-Geomorphologist and Research Software Engineer, fond of all things geospatial
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Issues and Pull Requests
Last synced: over 1 year ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v4 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
src/rust/Cargo.lock
cargo
- alga 0.9.3
- approx 0.3.2
- approx 0.5.1
- autocfg 1.1.0
- bytemuck 1.15.0
- crossbeam-deque 0.8.5
- crossbeam-epoch 0.9.18
- crossbeam-utils 0.8.19
- either 1.10.0
- extendr-api 0.6.0
- extendr-macros 0.6.0
- hermit-abi 0.3.9
- libR-sys 0.6.0
- libc 0.2.153
- libm 0.2.8
- matrixmultiply 0.3.8
- nalgebra 0.32.4
- nalgebra-macros 0.2.1
- ndarray 0.15.6
- num-complex 0.2.4
- num-complex 0.4.5
- num-integer 0.1.46
- num-rational 0.4.1
- num-traits 0.2.18
- num_cpus 1.16.0
- once_cell 1.19.0
- paste 1.0.14
- proc-macro2 1.0.79
- quote 1.0.35
- rawpointer 0.2.1
- rayon 1.9.0
- rayon-core 1.12.1
- safe_arch 0.7.1
- simba 0.8.1
- smallvec 1.13.2
- sprs 0.11.1
- sprs-ldl 0.10.0
- syn 1.0.109
- syn 2.0.53
- typenum 1.17.0
- unicode-ident 1.0.12
- whittaker-eilers 0.1.3
- wide 0.7.15
src/rust/Cargo.toml
cargo
DESCRIPTION
cran
- testthat >= 3.0.0 suggests