NIEHS / amadeus

https://niehs.github.io/amadeus/
Other
4 stars 2 forks source link

New tests #25

Closed mitchellmanware closed 5 months ago

mitchellmanware commented 5 months ago

Create additional tests for robust and integration testing.

mitchellmanware commented 5 months ago

@eva0marques I am trying to create unit tests for the manipulate spacetime object functions, but the convert_stobj_to_stdt is confusing me. If I pass the locs object into the function, why is it still not a stdt object?

> # create locations data frame
> locs <- data.frame(lon = -78.8277, lat = 35.95013)
> locs$site_id <- "3799900018810101"
> locs$time <- "2018-01-01"
> # convert to stdt
> locs_stdt <- convert_stobj_to_stdt(data.table::data.table(locs))
> class(locs_stdt)
[1] "list" "stdt"
> # is not stdt
> is_stdt(locs_stdt)
[1] FALSE
eva0marques commented 5 months ago

The crs defined by default is NA for data.table objects, which is not a character. It is a bug I should have fixed, as many other bugs. You could eventually change the NA by "EPSG:4326" as it is the most common crs for data.frames. But this function is to be deleted as soon as we are sure that we can replace everything with sftime. I am not sure you should spend time on it.

mitchellmanware commented 5 months ago

For download_ecoregion_data and download_gmted_data I removed the if(download) as a trigger for the download_unzip() and download_remove_zips() functions. The functions now rely on the unzip = and remove_commands = parameters to run/skip the functions.

Before:

  if (download) {
    #### 17. end if unzip == FALSE
    download_unzip(
      file_name = download_name,
      directory_to_unzip = directory_to_save,
      unzip = unzip
    )
    #### 19. remove zip files
    download_remove_zips(
      remove = remove_zip,
      download_name = download_name
    )
  }
}

After

  #### 18. end if unzip == FALSE
  download_unzip(
    file_name = download_name,
    directory_to_unzip = directory_to_save,
    unzip = unzip
  )
  #### 19. remove zip files
  download_remove_zips(
    remove = remove_zip,
    download_name = download_name
  )

Changes result in negligable performance differences and increased code coverage. GMTED data

> microbenchmark(
+   ## original function with if(download)
+   download_gmted_data_original(
+     statistic = "Breakline Emphasis",
+     resolution = "7.5 arc-seconds",
+     directory_to_download = d,
+     directory_to_save = d,
+     data_download_acknowledgement = TRUE,
+     download = FALSE,
+     remove_command = TRUE
+   ),
+   ## remove if(download); rely on `unzip` and `remove_zip` triggers
+   download_gmted_data(
+     statistic = "Breakline Emphasis",
+     resolution = "7.5 arc-seconds",
+     directory_to_download = d,
+     directory_to_save = d,
+     data_download_acknowledgement = TRUE,
+     download = FALSE,
+     remove_command = TRUE,
+     unzip = FALSE
+   ),
+   times = 5,
+   unit = "seconds"
+ )
      min       lq     mean   median       uq      max neval
 2.135385 2.202835 2.211150 2.203547 2.211668 2.302315     5
 2.173169 2.179900 2.279153 2.258105 2.356912 2.427681     5

Ecoregion data

> microbenchmark(
+   download_ecoregion_data_original(
+     directory_to_download = d,
+     directory_to_save = d,
+     data_download_acknowledgement = TRUE,
+     download = FALSE,
+     remove_command = TRUE
+   ),
+   download_ecoregion_data(
+     directory_to_download = d,
+     directory_to_save = d,
+     data_download_acknowledgement = TRUE,
+     download = FALSE,
+     remove_command = TRUE,
+     unzip = FALSE
+   ),
+   times = 5,
+   unit = "seconds"
+ )
      min       lq     mean   median       uq      max neval
 2.345228 2.347249 2.432835 2.414153 2.448946 2.608599     5
 2.201068 2.254072 2.311288 2.301413 2.368630 2.431258     5
mitchellmanware commented 5 months ago

New tests for calculate_covariates added in https://github.com/Spatiotemporal-Exposures-and-Toxicology/amadeus/pull/26. New tests for manipulate_spacetime skipped due to previous comment by Eva.

These new unit tests will be pulled into version 0.1.2