Skip to content

Commit 5f21916

Browse files
committed
test new example
1 parent fecef94 commit 5f21916

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
1818
MakieTeX = "6d554a22-29e7-47bd-aee5-0c5f06619414"
1919
MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
2020
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
21+
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
2122
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
2223
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
2324
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

docs/examples/HowdoI/howdoi.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ## Extract the axes names from a Cube
77

88
using YAXArrays
9-
c = YAXArray(rand(10,10,5))
9+
c = YAXArray(rand(10, 10, 5))
1010

1111
caxes(c)
1212

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

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

2626

2727

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

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

49-
dsfinal = concatenatecubes([ds1, ds2],
49+
dsfinal = concatenatecubes([ds1, ds2],
5050
CategoricalAxis("Variables", ["var1", "var2"]))
5151

5252
dsfinal
@@ -58,39 +58,39 @@ dsfinal
5858

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

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

6666
## assign values to a cube
67-
c = YAXArray(axes, reshape(1:3600, (10,10,36)))
67+
c = YAXArray(axes, reshape(1:3600, (10, 10, 36)))
6868

6969
# Now we subset the cube by any dimension
7070

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

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

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

8181

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

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

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

9191
# 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.
92-
mapslices(ds1, dims=("Lon","Lat")) do xin
93-
(xin*π) ./ maximum(skipmissing(xin))
92+
mapslices(ds1, dims=("Lon", "Lat")) do xin
93+
(xin * π) ./ maximum(skipmissing(xin))
9494
end
9595

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

104104
using CairoMakie
105+
CairoMakie.activate!()
105106
# This is how our classification map looks like
106-
heatmap(classes[:,:])
107+
heatmap(classes[:, :])
107108

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

119120
# 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.
120-
fitcube = cubefittable(t, Mean, :values, by=(:classes,:time))
121+
fitcube = cubefittable(t, Mean, :values, by=(:classes, :time))

0 commit comments

Comments
 (0)