NIEHS / amadeus

https://niehs.github.io/amadeus/
MIT License
2 stars 2 forks source link

Return `SpatVector` or `sf` object from `calc_covariates` #86

Open mitchellmanware opened 1 week ago

mitchellmanware commented 1 week ago

Based on @eva0marques manuscript review

Add functionality for calc_covariates to return a SpatVector or sf object May be more useful than a WKT format as it can be directly used in spatial functions and retains CRS information

mitchellmanware commented 1 week ago

@eva0marques I created a new function, calc_return_locs, which:

  1. applies the calc_check_time check
  2. if geom = TRUE, converts the data.frame with geometry to SpatVector

The SpatVector -> data.frame -> SpatVector is not the most efficient way to do this, but this process at least adds the return as spatial object functionality for the manuscript. I will work on making the workflow more efficient (with calc_prepare_locs and calc_worker) in the future.

https://github.com/NIEHS/amadeus/commit/17ed941693786d8e7c49e7346d76956ada17326d (ignore the incorrect commit message)

> c <- calc_narr(
+   a,
+   wod,
+   "NAME",
+   geom = FALSE
+ )
Detected `SpatVector` (polygons) extraction locations...
Calculating air.2m covariates at  for 2018-01-01...
Calculating air.2m covariates at  for 2018-01-02...
Returning extracted covariates.
> c
    NAME       time air.2m_0
1 Orange 2018-01-01 266.8416
2 Durham 2018-01-01 267.1144
3   Wake 2018-01-01 267.2367
4 Orange 2018-01-02 263.9914
5 Durham 2018-01-02 263.7842
6   Wake 2018-01-02 263.9491
> c <- calc_narr(
+   a,
+   wod,
+   "NAME",
+   geom = TRUE
+ )
Detected `SpatVector` (polygons) extraction locations...
Calculating air.2m covariates at  for 2018-01-01...
Calculating air.2m covariates at  for 2018-01-02...
Returning extracted covariates.
> c
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 6, 3  (geometries, attributes)
 extent      : 8135619, 8239747, 3480426, 3553860  (xmin, xmax, ymin, ymax)
 coord. ref. : +proj=lcc +lat_0=50 +lon_0=-107 +lat_1=50 +lat_2=50 +x_0=5632642.22547 +y_0=4612545.65137 +datum=WGS84 +units=m +no_defs 
 names       :   NAME       time air.2m_0
 type        :  <chr>   <POSIXt>    <num>
 values      : Orange 2018-01-01    266.8
               Durham 2018-01-01    267.1
                 Wake 2018-01-01    267.2
mitchellmanware commented 6 days ago

To do: