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

add multidimensional spatial means tutorial #860

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

tiemvanderdeure
Copy link
Collaborator

I've wanted to fit this into the docs somewhere for a while, maybe this is a reasonable way to do this?

Using dimensions like time period, SSP, GCM has become a standard part of my workflow and I think it's just a really neat way to work with dimensions.

It didn't become quite as slick as I'd hoped, mainly because of some inconsistencies in the worldclim data. I'm open to suggestions (either on the example itself or on where to fit it into the docs).

@rafaqz
Copy link
Owner

rafaqz commented Jan 15, 2025

Maybe update to using and merging into the breaking branch, a lot of this syntax will be simpler, like not needing replace_missing.

Otherwise I will have to fix it all in the next week 😅


As a next step, we would like to know how precipitation will change in Chile until the end of the 21st century. To do this, we can use climate model outputs. This data can come from multiple climate models (GCMs) and under different socio-economic scenarios (SSPs). We'll use additional dimensions to keep track of these.

First we define a simple function takes an SSP (socioeconomic scenario) and a GCM (climate model) as input, and downloads the appropriate climate data.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
First we define a simple function takes an SSP (socioeconomic scenario) and a GCM (climate model) as input, and downloads the appropriate climate data.
First we define a simple function which takes an SSP (socioeconomic scenario) and a GCM (climate model) as input, and downloads the appropriate climate data.

Copy link
Contributor

@felixcremer felixcremer left a comment

Choose a reason for hiding this comment

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

Nice.


We will leverage some tools from [DimensionalData](https://github.com/rafaqz/DimensionalData.jl), which is the package that underlies Rasters.jl. Rather than having a seperate Raster for each combination of GCM and SSP, `gcm` and `ssp` will be additional dimensions, and our Raster will be 4-dimensional (X-Y-gcm-ssp).

To do this, we first define two dimensions that correspond to the SSPs and GCMs we are interested in, then use the `@d` macro from [DimensionalData](https://github.com/rafaqz/DimensionalData.jl) to preserve these dimensions as we get the data, and then combine all Rasters into a single object using `Rasters.combine`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should link to the docstring of @d directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we use DocumenterInterLinks? I've never tried it but seems like this is what it's made for

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah we should try it, Rasters/DD doc links came up on slack too it might make things easier

Copy link
Collaborator

Choose a reason for hiding this comment

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

apparently, we don't support that yet in DVpress (never saw the benefit or was even aware of this, until now). I might take a look later this week.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had some code to do that in my DocumenterMarkdown PR, will see about resurrecting it

Since the format of WorldClim's datasets for future climate is slightly different from the dataset for the historical period, this actually returned a 5-dimensional raster, with a `Band` dimension that represents months. Here we'll just select the 6th month, matching the selection above. We will also replace the `NaN` missing value by the more standard `missing` using [`replace_missing`](@ref).

````@example cellarea
precip_future = precip_future[Band = 6]
Copy link
Contributor

Choose a reason for hiding this comment

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

We could keep the Band information and do the next steps for all months at the same time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could, I just wanted to keep it simple. At the end of the whole thing it just prints a 2x2 dimArray and that's easier to read than a 12x2x2 dimarray

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense and I would add this info to the tutorial:

We are restricting here to one Band for simplicity but the analysis would also work for all Bands simultaneously.

@lazarusA
Copy link
Collaborator

@rafaqz @tiemvanderdeure let's go ahead with this. We do a general fix once the Breaking release lands.

@rafaqz
Copy link
Owner

rafaqz commented Jan 18, 2025

Sure unless @tiemvanderdeure already started on it

@tiemvanderdeure
Copy link
Collaborator Author

I haven't made the fix yet - let me just make a few changes to the text and we can merge

@tiemvanderdeure
Copy link
Collaborator Author

Good to go for me. I'll fix when the next breaking release hits. (I fixed a little text thing in the first half - the precipitation per square meter in Chile is not 8 * 10^13)

@rafaqz rafaqz merged commit 916f908 into rafaqz:main Jan 20, 2025
2 checks passed
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.

5 participants