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

How do I access a RasterStack's dimensions? #354

Closed
tomchor opened this issue Dec 22, 2022 · 3 comments
Closed

How do I access a RasterStack's dimensions? #354

tomchor opened this issue Dec 22, 2022 · 3 comments

Comments

@tomchor
Copy link

tomchor commented Dec 22, 2022

This is a bit of a silly question, but consider the raster stack below:

julia> rstack
RasterStack with dimensions: 
  Dim{:zC} Sampled{Float32} Float32[-145.75601, -137.82991, , -2.604186, -0.86806154] ForwardOrdered Irregular Points,
  Dim{:zF} Sampled{Float32} Float32[-150.0, -141.51202, , -1.7361231, 0.0] ForwardOrdered Irregular Points,
  Dim{:xC} Sampled{Float32} Float32[-196.42857, -189.28572, , 189.28572, 196.42857] ForwardOrdered Regular Points,
  Dim{:yF} Sampled{Float32} Float32[-200.0] ForwardOrdered Regular Points,
  Dim{:xF} Sampled{Float32} Float32[-200.0, -192.85715, , 185.71428, 192.85715] ForwardOrdered Regular Points,
  Dim{:yC} Sampled{Float32} Float32[-196.42857] ForwardOrdered Regular Points,
  Ti Sampled{Float64} Float64[0.0, 446.5529199252885, , 133519.3230576612, 133965.8759775865] ForwardOrdered Irregular Points
and 13 layers:
  :dbdz Union{Missing, Float32} dims: Dim{:xC}, Dim{:yC}, Dim{:zF}, Ti (56×1×65×306)
  :b    Union{Missing, Float32} dims: Dim{:xC}, Dim{:yC}, Dim{:zC}, Ti (56×1×64×306)
...

I'd like to access one of its dimensions, say, yC. The only way I figured out how to that was by doing

julia> dims(rstack)[6]
Dim{:yC} Sampled{Float32} ForwardOrdered Regular Points
wrapping: 1-element Vector{Float32}:
 -196.42857

which requires me to search for the position of yC in advance. The other "intuitive" ways that I could think of don't seem to work (like rstack.yC or rstack[:yC]).

Is there a better way?

Thanks!

@rafaqz
Copy link
Owner

rafaqz commented Dec 22, 2022

A few ways:

dims(rstack, 6)
dims(rstack, :yC)
dims(rstack, Dim{:yC}())

For multiple:

dims(rstack, (6, 7))
dims(rstack, (:zC, :yC))

You get the order you specify.

Read the DimensionalData.jl docs to understand this stuff more. Rasters simply extends DD for raster arrays.

The other things you are trying are for getting raster layers, not dimensions. It has to be one or the other.

@tomchor
Copy link
Author

tomchor commented Dec 22, 2022

Thanks! I looked for that in the docs over there but I guess I missed it... sorry

@tomchor tomchor closed this as completed Dec 22, 2022
@rafaqz
Copy link
Owner

rafaqz commented Dec 23, 2022

They can probably be improved... if you ever have time to fix anything missing docs PRs are appreciated

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

No branches or pull requests

2 participants