66# ## Extract the axes names from a Cube
77
88using YAXArrays
9- c = YAXArray (rand (10 ,10 ,5 ))
9+ c = YAXArray (rand (10 , 10 , 5 ))
1010
1111caxes (c)
1212
@@ -21,7 +21,7 @@ collect(getAxis("Dim_1", c).values)
2121collect (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
5252dsfinal
@@ -58,39 +58,39 @@ dsfinal
5858
5959# # define the time span of the cube
6060using 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
6464axes = [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
7272ctime = 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))
9494end
9595
9696# ## How do I use the CubeTable function?
102102classes = YAXArray ([getAxis (" lon" , dsfinal), getAxis (" lat" , dsfinal)], rand (1 : 3 , 10 , 15 ))
103103
104104using 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
109110t = CubeTable (values= ds1, classes= classes)
@@ -117,4 +118,4 @@ DataFrame(t[1])
117118fitcube = 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