Skip to content
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

Revise prepraster() for more flexibility in predictors #152

Open
courtiol opened this issue Sep 25, 2022 · 1 comment
Open

Revise prepraster() for more flexibility in predictors #152

courtiol opened this issue Sep 25, 2022 · 1 comment
Assignees
Labels

Comments

@courtiol
Copy link
Owner

courtiol commented Sep 25, 2022

Goal

In the context of allowing for the construction of isoscapes with more predictors and isoscapes with no predictor (beyond spatial autocorrelation), prepraster() should be modified so as to build an adequate structural raster object for the task.

Current function

So far the function has been defined as follows:

prepraster <- function(
                       raster,
                       isofit = NULL,
                       margin_pct = 5,
                       aggregation_factor = 0L,
                       aggregation_fn = mean,
                       manual_crop = NULL,
                       values_to_zero = c(-Inf, 0),
                       verbose = interactive()
                       )

New output

The new version of prepraster() should allow one to create a structural raster (as before and backward compatible) or raster brick that will contain all information for predictions.

Inputs

The new requirement would be that the user can pass either all the rasters that need to be combined (not necessarily matching in terms of spatial range and cropping) or no raster at all.

The first argument could thus be ... or alternatively something like rasters_list.
I guess that rasters_list would present the benefit of being backward compatible due to partial matching (to check).
The drawback is that lists are always more awkward as inputs, but we already use them for other functions, so it would not be inconsistent.

We also need a new argument or set of arguments to define the resolution of the raster brick for situations for which there is no raster. Perhaps something like manual_res, where the input would be the number of cells?

In the presence of multiple rasters, the resolution could be defined based on whichever raster the user wants.
So we could have two arguments raster_template_res and raster_template_crop for the user to define the name of the raster to be used as a basis for cropping and resolution.
raster_template_crop would be overridden by isofit which could be relabelled isofit_crop for clarity.

The other arguments can stay as they are, but some of them will have to behave differently.
In particular, aggregation_fn and values_to_zero should allow for users to define different input per raster layer.
Not provided as a list, such arguments should work as they are now for a raster with a single layer or assume (at least for aggregation_fn but probably not for values_to_zero) for the case of multiple layers that the same thing applies to all layer.
The user should also be able to input named lists with names referring the raster layers to apply different setting on each layers.
aggregation_factor should apply to the raster selected via raster_template_res.

Proposal

I thus propose to revise the list of arguments as follows:

prepraster <- function(
                       rasters_list = NULL,                                     ## main input
                       manual_crop = NULL,                                      ## cropping param 1
                       isofit_crop = NULL,                                      ## cropping param 2
                       margin_pct_crop = 5,                                     ## cropping param 3
                       raster_template_crop = NULL,                             ## cropping param 4
                       manual_res = list(nb_cells_long = NA, n_cells_lat = NA), ## resolution param 1
                       raster_template_res = NULL,                              ## resolution param 2
                       aggregation_factor = 0L,                                 ## aggregation param 1
                       aggregation_fn = mean,                                   ## aggregation param 2
                       values_to_zero,                                          ## other param 1
                       verbose = interactive()                                  ## other param 2
                       )

These changes will have to be coordinated with #154 but the current issue should probably be tackled first.

NB: this issue extends and thus replaces #124, #125, #141.

@courtiol courtiol added the api label Sep 25, 2022
@courtiol courtiol added this to the version 1.0 milestone Sep 25, 2022
@courtiol courtiol self-assigned this Sep 25, 2022
@courtiol courtiol changed the title Revise prepraster() Revise prepraster() for more flexibility in predictors Sep 25, 2022
@courtiol courtiol modified the milestones: version 1.0, more_flexible_isoscapes Nov 14, 2023
@courtiol
Copy link
Owner Author

If you do think this issue matters to you, please add a thumb up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant