Skip to content

Commit

Permalink
selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Jan 20, 2024
1 parent ad23b34 commit 8f24c04
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
Expand Down
24 changes: 13 additions & 11 deletions docs/examples/Gallery/simplemaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,29 @@ g = open_dataset(zopen(store, consolidated=true))
c = g["tas"]

# Subset, first time step
ct1 = c[Ti = Near(Date("2015-01-01"))]
lon = lookup(ct1, :lon)
lat = lookup(ct1, :lat)
data = ct1.data[:,:];
ct1_slice = c[Ti = Near(Date("2015-01-01"))]
## use lookup to get axis values
lon = lookup(ct1_slice, :lon)
lat = lookup(ct1_slice, :lat)
data = ct1_slice.data[:,:];

# ## Heatmap plot

GLMakie.activate!()
fig = Figure(resolution = (1200,600))
ax = Axis(fig[1,1]; aspect = DataAspect())
heatmap!(ax, lon, lat, data; colormap = :seaborn_icefire_gradient)

fig, ax, plt = heatmap(ct1_slice; colormap = :seaborn_icefire_gradient,
axis = (; aspect=DataAspect()),
figure = (; size = (1200,600), fontsize=24))
fig


# ## Add Coastlines via the GeoAxis, wintri Projection
# # some transformations
δlon = (lon[2]-lon[1])/2
nlon = lon .- 180 .+ δlon
ndata = circshift(data, (192,1))


fig = Figure(resolution = (1200,600))
fig = Figure(;size=(1200,600))
ax = GeoAxis(fig[1,1])
surface!(ax, nlon, lat, ndata; colormap = :seaborn_icefire_gradient, shading=false)
cl=lines!(ax, GeoMakie.coastlines(), color = :white, linewidth=0.85)
Expand All @@ -37,7 +39,7 @@ fig

# ## Moll projection

fig = Figure(resolution = (1200,600))
fig = Figure(; size=(1200,600))
ax = GeoAxis(fig[1,1]; dest = "+proj=moll")
surface!(ax, nlon, lat, ndata; colormap = :seaborn_icefire_gradient, shading=false)
cl=lines!(ax, GeoMakie.coastlines(), color = :white, linewidth=0.85)
Expand All @@ -55,7 +57,7 @@ Makie.inline!(true) # Make sure to inline plots into Documenter output!
ds = replace(ndata, missing =>NaN)
sphere = uv_normal_mesh(Tesselation(Sphere(Point3f(0), 1), 128))

fig = Figure(backgroundcolor=:grey25, resolution=(500,500))
fig = Figure(backgroundcolor=:grey25, size=(500,500))
ax = LScene(fig[1,1], show_axis=false)
mesh!(ax, sphere; color = ds'[end:-1:1,:], shading=false,
colormap = :seaborn_icefire_gradient)
Expand Down
12 changes: 4 additions & 8 deletions docs/examples/HowdoI/howdoi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ end
## cube containing a mask with classes 1, 2 and 3
classes = YAXArray((getAxis("lon", dsfinal), getAxis("lat", dsfinal)), rand(1:3, 10, 15))

using CairoMakie
CairoMakie.activate!()
using GLMakie
GLMakie.activate!()
# This is how our classification map looks like
fig, ax, obj = heatmap(classes.data[:, :];
colormap = cgrad([:black, :orange, :dodgerblue], 3, categorical=true))
fig, ax, obj = heatmap(classes;
colormap=Makie.Categorical(cgrad([:grey15, :orangered, :snow3])))
cbar = Colorbar(fig[1,2], obj)
mn, mx, N = 1,3,3
δn = (mx - mn)/N
ticks_position = [mn + δn/2 + (i-1)*δn for i in 1:N]
cbar.ticks = (ticks_position, string.(mn:mx))
fig

# Now we define the input cubes that will be considered for the iterable table
Expand Down
65 changes: 65 additions & 0 deletions docs/examples/UserGuide/indexing_subsetting.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# # Indexing, subsetting and selectors
using YAXArrays, Dates

## Define a toy cube
t = Date("2020-01-01"):Month(1):Date("2022-12-31")
axes = (Dim{:lon}(-9:10), Dim{:lat}(-5:15), Dim{:time}(t))
c = YAXArray(axes, reshape(1:20*21*36, (20, 21, 36)))

# A very convinient selector is `lookup`, getting for example the values for `lon` and `time`:
lon = lookup(c, :lon)
#
tempo = lookup(c, :time)

# ## lookup
Docs.doc(lookup) # hide

# ## `At` value

c[time = At(Date("2021-05-01"))]

# ## `At` vector of values

c[time = At([Date("2021-05-01"), Date("2021-06-01")])]

# similarly for any of the spatial dimensions:

c[lon = At([-9,-5])]

# ## `At` values with tolerance (`atol`, `rtol`)

c[lon = At([-10, 11]; atol = 1)]

# ## Between
# Altought a `Between(a,b)` function is available in DimensionalData, is recommended to use instead the `a .. b` notation:

c[lon = -9 .. -7] # close interval, all points included.

# More selectors from DimensionalData are available:

# ## DD Selectors
# ### Touches
Docs.doc(Touches) # hide

# ### Near
Docs.doc(Near) # hide

# ### Where
Docs.doc(Where) # hide

# ### Contains
Docs.doc(Contains) # hide


# ## Open/Close Intervals

using IntervalSets

c[lon = OpenInterval(-9, -7)]
#
c[lon = ClosedInterval(-9, -7)]
#
c[lon =Interval{:open,:closed}(-9,-7)]
#
c[lon =Interval{:closed,:open}(-9,-7)]

1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ nav:
- "Creating YAXArrays and Datasets" : "examples/generated/UserGuide/creating.md"
- "Saving YAXArrays and Datasets" : "examples/generated/UserGuide/saving.md"
- "Setting chunks's size": "examples/generated/UserGuide/setchuncks.md"
- "Indexing and subsetting": "examples/generated/UserGuide/indexing_subsetting.md"
- "Apply functions on YAXArrays": "examples/generated/UserGuide/applyfunctions.md"
- "Generate a cube from function": "examples/generated/UserGuide/create_from_func.md"
- "Open NetCDF" : "examples/generated/UserGuide/openNetCDF.md"
Expand Down
2 changes: 1 addition & 1 deletion src/YAXArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using YAXArrayBase: getattributes

@reexport using Dates: Date, DateTime
@reexport using IntervalSets: (..)
@reexport using DimensionalData: Dim
@reexport using DimensionalData: Dim, At, Touches, Near, Where, Contains, lookup
@reexport using .Cubes

#@reexport using .Cubes.Axes
Expand Down

0 comments on commit 8f24c04

Please sign in to comment.