-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate raster runif #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you did this @ToonHub 👍 !! I believe your PR addresses issue #46. raster_runif
seems fine as a name for this datasource!
I didn't yet check all code and the datasource (will try to do that in due time); I just had a quick look at the PR in GitHub, so here is some first feedback already:
- regarding the raster's extent: considering Reconstruct a full GRTSmaster_habitats grid #45 (about reconstructing full GRTS) and Construct a raster of random numbers aligned with GRTSmh_buffer #46 (random raster) I suggest to make a (2 km?) buffer around
GRTSmaster_habitats
already, when makingraster_runif
, to be on the safe side for future updates inGRTSmaster_habitats
.- regarding Reconstruct a full GRTSmaster_habitats grid #45, I cannot handle it soon, but will try to look at it in the course of this year. But you may tackle it as well.
- regarding
renv
some files are still missing (cf. Update habitatmap_stdized and habitatmap_terr #50 (review)) - best also add some checks on the data source, as in previous cases, including the checksums.
- for rasters I suggest to stick with GeoTIFFs for now, since the GDAL GPKG raster driver has less capabilities than the one for GeoTIFF. So there's no need to set the
OGR_CURRENT_DATA
env variable. - can you paste the html file in a PR comment?
Thanks!!
Below the renderded bookdown: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing the html! As said, I will look deeper into it (and maybe run the code myself), just adding some more comments in the meantime.
My previous comment:
a (2 km?) buffer around
GRTSmaster_habitats
needs a bit further clarification (also in the light of #55 (comment)): here I mean buffering the non-NA
part (Flanders + Brussels), not the rectangle as such.
- in
index.Rmd
, you can addoptions(rgdal_show_exportToProj4_warnings = "none")
to get rid of PROJ.4 warnings (they don't matter in this case).
add option rgdal not to show warning related to rproj add parameter to avoid overwriting result remove unnecessary libraries
increase extent of raster_runif mask raster_unif outside buffer around Flanders add checks for result write result to 20_processed folder checksums of result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @ToonHub ! Some minor comments.
- missing files in
src/generate_raster_runif
which should have been created byrenv
:.Rprofile
,renv/.gitignore
raster_runif
has a hole compared toGRTSmaster_habitats
, namely the Brussels Capital Region. A quick solution might be to fill the hole in the sf objectflanders_buffer
. I saw a possible approach in Filling polygon holes based on area r-spatial/sf#609 (comment)
I think we best discuss on the pattern of random numbers:
Compare:
> grts_master %>% crop(extent(5e4,52e3,18e4,182e3)) %>% spplot(scales = list(draw = TRUE))
with:
> raster_runif_buffer_mask %>% crop(extent(5e4,52e3,18e4,182e3)) %>% spplot(scales = list(draw = TRUE))
The simple random sampling results in more clumped patterns. More ideally I believe the random numbers could be spread in a spatially balanced way. Don't know how easy it can be accomplished, it may be feasible with inbo/grtsdb. I did a short experiment, but not with grtsdb.
install n2khab dev_0.5.0
use functions xxh64, md5sum, sha256sum
I added the Brussels region to the raster. As agreed with @florisvdh, we will use simple random sampling to generate the numbers. |
@@ -0,0 +1,271 @@ | |||
# Generate random number based on uniform distribution for each GRTS master cell | |||
|
|||
+ We start from the `GRTSmh_base4frac` data source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw this. I don't think this is true. Also applies to next paragraphs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exactly is not true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, in the code you actually work with GRTSmaster_habitats
, not with GRTSmh_base4frac
which you state here (and for which you verify checksums in the beginning).
See:
n2khab-preprocessing/src/generate_raster_runif/10_raster_runif.Rmd
Lines 38 to 41 in 3953047
```{r} | |
grts_master <- read_GRTSmh() | |
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
dir.create(file.path(path, "20_processed/raster_runif"), recursive = TRUE) | ||
|
||
filepath <- file.path(fileman_up("n2khab_data"), "20_processed/raster_runif/raster_runif.tif") | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should go to 10_raw
. Although you use GRTSmh for extent and resolution, the values are completely new data, so I'd still put it in 10_raw
(all those data sources are typically never 'made from scratch', so it's to be seen relative).
I suggested that before, in #55 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I tought that I changed this already. But not...
I created a raster with a random number between 0 and 1 for each 32m cell of grts master based on the uniform distribution. This random number can be used to select a equal probability sample for terrestrial habitats based on the phab values.