Skip to content

Commit

Permalink
test new example
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Jul 1, 2023
1 parent fecef94 commit 5f21916
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MakieTeX = "6d554a22-29e7-47bd-aee5-0c5f06619414"
MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Expand Down
29 changes: 15 additions & 14 deletions docs/examples/HowdoI/howdoi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ## Extract the axes names from a Cube

using YAXArrays
c = YAXArray(rand(10,10,5))
c = YAXArray(rand(10, 10, 5))

caxes(c)

Expand All @@ -21,7 +21,7 @@ collect(getAxis("Dim_1", c).values)
collect(c.axes[1].values)

## to collect data from a cube works exactly the same as doing it from an array
c[:,:,1]
c[:, :, 1]



Expand All @@ -46,7 +46,7 @@ ds2 = YAXArray(axlist, data2)

# Now we can concatenate ```ds1``` and ```ds2``` cubes:

dsfinal = concatenatecubes([ds1, ds2],
dsfinal = concatenatecubes([ds1, ds2],
CategoricalAxis("Variables", ["var1", "var2"]))

dsfinal
Expand All @@ -58,39 +58,39 @@ dsfinal

## define the time span of the cube
using Dates
t = Date("2020-01-01"):Month(1):Date("2022-12-31")
t = Date("2020-01-01"):Month(1):Date("2022-12-31")

## create cube axes
axes = [RangeAxis("Lon", 1:10), RangeAxis("Lat", 1:10), RangeAxis("Time", t)]

## assign values to a cube
c = YAXArray(axes, reshape(1:3600, (10,10,36)))
c = YAXArray(axes, reshape(1:3600, (10, 10, 36)))

# Now we subset the cube by any dimension

## subset cube by years
ctime = c[Time=2021:2022]

## subset cube by a specific date and date range
ctime2 = c[Time=Date(2021-01-05)]
ctime3 = c[Time=Date(2021-01-05)..Date(2021-01-12)]
ctime2 = c[Time=Date(2021 - 01 - 05)]
ctime3 = c[Time=Date(2021 - 01 - 05) .. Date(2021 - 01 - 12)]

## subset cube by longitude and latitude
clonlat = c[Lon=1..5, Lat=5..10] # check even numbers range, it is ommiting them
clonlat = c[Lon=1 .. 5, Lat=5 .. 10] # check even numbers range, it is ommiting them


# ## How do I apply map algebra?
# Our next step is map algebra computations. This can be done effectively using the 'map' function. For example:

## multiplying cubes with only spatio-temporal dimensions
map((x,y)->x*y, ds1, ds2)
map((x, y) -> x * y, ds1, ds2)

## cubes with more than 3 dimensions
map((x,y)->x*y, dsfinal[Variables="Var1"], dsfinal[Variables="Var2"])
map((x, y) -> x * y, dsfinal[Variables="Var1"], dsfinal[Variables="Var2"])

# To add some complexity, we will multiply each value for π and then divided for the sum of each time step. We will use the `ds1` cube for this purpose.
mapslices(ds1, dims=("Lon","Lat")) do xin
(xin*π) ./ maximum(skipmissing(xin))
mapslices(ds1, dims=("Lon", "Lat")) do xin
(xin * π) ./ maximum(skipmissing(xin))
end

# ## How do I use the CubeTable function?
Expand All @@ -102,8 +102,9 @@ end
classes = YAXArray([getAxis("lon", dsfinal), getAxis("lat", dsfinal)], rand(1:3, 10, 15))

using CairoMakie
CairoMakie.activate!()
# This is how our classification map looks like
heatmap(classes[:,:])
heatmap(classes[:, :])

# Now we define the input cubes that will be considered for the iterable table
t = CubeTable(values=ds1, classes=classes)
Expand All @@ -117,4 +118,4 @@ DataFrame(t[1])
fitcube = cubefittable(t, Mean, :values, by=(:classes))

# We can also use more than one criteria for grouping the values. In the next example, the mean is calculated for each class and timestep.
fitcube = cubefittable(t, Mean, :values, by=(:classes,:time))
fitcube = cubefittable(t, Mean, :values, by=(:classes, :time))

0 comments on commit 5f21916

Please sign in to comment.