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

construct RasterSeries from AbstractBasicDimArray #826

Merged
merged 3 commits into from
Dec 8, 2024

Conversation

tiemvanderdeure
Copy link
Contributor

@tiemvanderdeure tiemvanderdeure commented Dec 2, 2024

Just a small quality of life improvement that makes it possible to get a RasterSeries from a DimArray using a pipe.

Things works nicely together with @d to make things like this possible

using Rasters, RasterDataSources
function get_climate_data(gcm, ssp)
    Raster(rand(X(1:10)))
end
ssps = [SSP370] |> Dim{:ssp}
gcms = [GFDL_ESM4, MRI_ESM2_0] |> Dim{:gcm}
(@d get_climate_data.(gcms, ssps)) |> RasterSeries |> Rasters.combine

which returns a Raster with dims X, ssp, and gcm

@rafaqz
Copy link
Owner

rafaqz commented Dec 2, 2024

So slick.

Especially with RDS climate types as lookups.

Comment on lines +119 to +120
RasterSeries(data::DD.AbstractBasicDimArray; kw...) =
RasterSeries(data, dims(data); kw...)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
RasterSeries(data::DD.AbstractBasicDimArray; kw...) =
RasterSeries(data, dims(data); kw...)
RasterSeries(data::DD.AbstractBasicDimArray{<:Union{AbstractRasterStack,AbstractRaster}}; kw...) = RasterSeries(data, dims(data);

Has to hold a Raster or RasterStack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to limit it to that, in principle it could hold strings (of filenames) as well. If it holds something that isn't allowed then RasterSeries(data, dims(data) will fail anyway

Copy link
Owner

Choose a reason for hiding this comment

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

Ahh right because strings will work too. Ok makes sense

@rafaqz
Copy link
Owner

rafaqz commented Dec 2, 2024

Maybe a test?

@tiemvanderdeure
Copy link
Contributor Author

We really should include an example like this in the docs somewhere. It's not a super intuitive way to use dimensions but it is just such as nice way to keep track of your data. It just gets rid of all the for-loops in the rest of your workflow.

@rafaqz
Copy link
Owner

rafaqz commented Dec 8, 2024

Did you want to add docs in this PR? Or just merge?

@tiemvanderdeure
Copy link
Contributor Author

Just merge! I'll make a docs example in a separate PR.

@rafaqz rafaqz merged commit 5aa8914 into rafaqz:main Dec 8, 2024
1 of 2 checks passed
@asinghvi17
Copy link
Collaborator

asinghvi17 commented Dec 8, 2024

Just to clarify here - is a RasterSeries essentially a lazy concatenation of multiple dimarrays of dimension n, along some dimension n+1 (and maybe also n+2 etc)?

If so, can a RasterSeries be used as a vector of dimvectors as well as a dimmatrix? That would be super interesting for some of the vector data cube stuff.

@rafaqz
Copy link
Owner

rafaqz commented Dec 8, 2024

It's basically just a Raster of Rasters or RastersStacks with some helper methods.

It's not a lazy concatenation, but using Rasters.combine will concatenate it to a single Raster/RasterStack, and for DiskArrays that will be lazy

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.

3 participants