Skip to content

Rasterize BMTR object#230

Open
atharvashahane28 wants to merge 11 commits intomainfrom
rasterize-bmtr
Open

Rasterize BMTR object#230
atharvashahane28 wants to merge 11 commits intomainfrom
rasterize-bmtr

Conversation

@atharvashahane28
Copy link
Collaborator

This PR introduces a new function rasterize_bmtr. This function converts a BMTR object into a multi-layer SpatRaster, with each unique transition as a separate layer. This makes it easier to plot BMTR objects using terra::plot().


raster_uw <- rasterize_bmtr(bmtr_uw, bf)

expect_true(ext(bf) == ext(raster_uw))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually it's nice to have this a separate named test but in practice there's a lot of overhead to calc_bmtr() + rasterize_bmrt(). can you combine this with the prior to eliminate that?


raster_uw <- rasterize_bmtr(bmtr_uw, bf)

expect_true(bf$metadata$n_timesteps == terra::nlyr(raster_uw))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this one.


test_that("rasterization works for weighted BMTR calculation", {
local_quiet()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this test as is but add skip("Slow test. Always skipped") to the beginning. The calculation for the weighted BMTR is very different but the structure of the returned object is not so I don't think it's necessary to check raterize_bmtr() against the output of the weighted version every time.
The tests for calc_bmtr() itself should definitely test the weighted version though.

@ethanplunkett
Copy link
Contributor

ethanplunkett commented Feb 11, 2026

I don't think the failed test has anythign to do with your changes. I hope it's just a fluke and re-running will fix it. Edit: It did fix it.

I made some comments on the testing. For efficiency I want you to only call calc_bmtr() once while testing rasterize_bmtr().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants