ninoxconsulting / PEMprepr

This sub package prepares data for Predictive Ecosystem Mapping workflow
Apache License 2.0
0 stars 0 forks source link

Add SAGA infrastructure #10

Open ateucher opened 1 month ago

ateucher commented 1 month ago
  1. I added the bare bones for the function to generate SAGA derived outputs. This is a little complex, but taps into users saga_cmd.exe file. I have it working currently but very fragile. Perhaps we can keep this as working copy and update if time permits. It uses internal dataset and additional utils files. There is an parallel version (https://github.com/bcgov/PEMprepr/blob/master/R/parallel_create_covariates.R, which I think also uses this: https://github.com/bcgov/PEMprepr/blob/master/R/preprocess_dtm.R (to chop large DTM into pieces) and https://github.com/bcgov/PEMprepr/blob/master/R/mosaic_covariates.R (to recombine tiles outputs back into one layer).

Originally posted by @ateucher in https://github.com/ninoxconsulting/PEMprepr/issues/6#issuecomment-2369394441

Started in #9

ateucher commented 1 week ago

Installation Notes:

Mac

https://sourceforge.net/p/saga-gis/wiki/Compiling%20SAGA%20on%20Mac%20OS%20X/ with a few tweaks:

brew install wxmac llvm libomp gdal postgis pdal opencv libharu cmake

mkdir ~/saga && cd ~/saga

git clone https://git.code.sf.net/p/saga-gis/code saga-code

git checkout saga-9.6.1 # Choose the tag from: https://sourceforge.net/p/saga-gis/code/ref/master/tags/

mkdir _build && cd _build

# Need to tell cmake where OpenMP is:
# https://gist.github.com/scivision/16c2ca1dc250f54d34f1a1a35596f4a0
export OpenMP_ROOT=$(brew --prefix)/opt/libomp

cmake ../saga-code/saga-gis

# this takes a while
make && sudo make install

# Tell saga where the dynamic libs are
# https://stackoverflow.com/questions/77829286/no-lc-rpaths-found
install_name_tool -add_rpath /usr/local/lib /usr/local/bin/saga_cmd
install_name_tool -add_rpath /usr/local/lib /usr/local/bin/saga_gui

Run with: saga_gui, saga_cmd, etc

OR:

Download app from https://sourceforge.net/projects/saga-gis/ and move to Applications. Try to open it, if it doesn't open (Blocked because not verified), go to System Preferences -> Privacy and Security, scroll down to Security. SAGA will be identified as being blocked, click to allow it (https://support.apple.com/en-ca/102445). Then you can access saga_cmd at: /Applications/SAGA.app/Contents/MacOS/saga_cmd, and/or run the GUI as normal

Linux

https://sourceforge.net/p/saga-gis/wiki/Binary%20Packages/

gcperk commented 1 week ago

@ateucher - if this is a user requirement, how much detail do we need to provide? ie for the user to actually do it. And also how does this impact the test infrastructure? Im not clear how to install these so Github actions can be used/test appropriately?

ateucher commented 1 week ago

I think minimal instructions are fine, probably in the documentation for find_saga_path() and check_saga() (which I think it's probably worth it to export to help users verify/debug their saga installation). Or a short vignette.

I can set up the GitHub action; just also requires a bit of work on the find_saga_path() and check_saga() functions. Is this PR blocking for you, or is it ok to wait a couple of days? I have some ideas, just a bit tight on time this week!

gcperk commented 1 week ago

Hey @ateucher - thanks for looking into this. No that's all fine it can wait til next week, I have moved onto the PEMsamplr. I might also make a few changes to the file structure in PEMr package as I work through, but these will only be the file structure so wont ask for review if thats ok. Hope the teaching goes well