Skip to content

Commit 301ea46

Browse files
authored
no more Ti (#479)
* no more Ti * go back to :time * no Ti check * use Dim{:time} * adds dims * add YAX * adds dim Variables * export it * fix tests * fix docs * fix msc * fixes doc strings * no Rasters * more docs
1 parent 718da93 commit 301ea46

26 files changed

+295
-211
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ using YAXArrays
107107
Let's assemble a `YAXArray` with 4 dimensions i.e. time, x,y and a variable dimension with two variables.
108108

109109
```julia
110-
using YAXArrays, DimensionalData
110+
using YAXArrays
111+
using YAXArrays: YAXArrays as YAX
112+
111113
axlist = (
112-
Dim{:time}(range(1, 20, length=20)),
113-
X(range(1, 10, length=10)),
114-
Y(range(1, 5, length=15)),
115-
Dim{:Variable}(["var1", "var2"]))
114+
YAX.time(range(1, 20, length=20)),
115+
lon(range(1, 10, length=10)),
116+
lat(range(1, 5, length=15)),
117+
Variables(["var1", "var2"]))
116118
```
117119
```
118120
↓ time 1.0:1.0:20.0,
119-
X 1.0:1.0:10.0,
120-
Y 1.0:0.2857142857142857:5.0,
121-
Variable ["var1", "var2"]
121+
lon 1.0:1.0:10.0,
122+
lat 1.0:0.2857142857142857:5.0,
123+
Variables ["var1", "var2"]
122124
```
123125

124126
and the corresponding data.
@@ -148,8 +150,8 @@ ds = YAXArray(axlist, data, props)
148150
│ 20×10×15×2 YAXArray{Float64,4} │
149151
├────────────────────────────────┴─────────────────────────────────────────────── dims ┐
150152
↓ time Sampled{Float64} 1.0:1.0:20.0 ForwardOrdered Regular Points,
151-
X Sampled{Float64} 1.0:1.0:10.0 ForwardOrdered Regular Points,
152-
Y Sampled{Float64} 1.0:0.2857142857142857:5.0 ForwardOrdered Regular Points,
153+
lon Sampled{Float64} 1.0:1.0:10.0 ForwardOrdered Regular Points,
154+
lat Sampled{Float64} 1.0:0.2857142857142857:5.0 ForwardOrdered Regular Points,
153155
⬔ Variable Categorical{String} ["var1", "var2"] ForwardOrdered
154156
├──────────────────────────────────────────────────────────────────────────── metadata ┤
155157
Dict{String, String} with 5 entries:
@@ -168,17 +170,17 @@ ds = YAXArray(axlist, data, props)
168170
For axis can be via `.`
169171

170172
```julia
171-
ds.X
173+
ds.lon
172174
```
173175
```
174-
X Sampled{Float64} ForwardOrdered Regular Points
176+
lon Sampled{Float64} ForwardOrdered Regular Points
175177
wrapping: 1.0:1.0:10.0
176178
```
177179

178180
or better yet via `lookup`
179181

180182
```julia
181-
lookup(ds, :X)
183+
lookup(ds, :lon)
182184
```
183185
```
184186
Sampled{Float64} ForwardOrdered Regular Points
@@ -187,7 +189,7 @@ wrapping: 1.0:1.0:10.0
187189

188190
note that also the `.data` field can be use
189191
```julia
190-
lookup(ds, :X).data
192+
lookup(ds, :lon).data
191193
```
192194
```
193195
1.0:1.0:10.0
@@ -196,15 +198,15 @@ lookup(ds, :X).data
196198
The data for one variables, i.e. `var1` can be accessed via:
197199

198200
```julia
199-
ds[Variable=At("var1")]
201+
ds[Variables=At("var1")]
200202
```
201203
```
202204
╭──────────────────────────────╮
203205
│ 20×10×15 YAXArray{Float64,3} │
204206
├──────────────────────────────┴────────────────────────────────────────────── dims ┐
205207
↓ time Sampled{Float64} 1.0:1.0:20.0 ForwardOrdered Regular Points,
206-
X Sampled{Float64} 1.0:1.0:10.0 ForwardOrdered Regular Points,
207-
Y Sampled{Float64} 1.0:0.2857142857142857:5.0 ForwardOrdered Regular Points
208+
lon Sampled{Float64} 1.0:1.0:10.0 ForwardOrdered Regular Points,
209+
lat Sampled{Float64} 1.0:0.2857142857142857:5.0 ForwardOrdered Regular Points
208210
├───────────────────────────────────────────────────────────────────────── metadata ┤
209211
Dict{String, String} with 5 entries:
210212
"var1" => "one of your variables"

docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
2424
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
2525
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
2626
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
27-
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
2827
SkipNan = "aed68c70-c8b0-4309-8cd1-d392a74f991a"
2928
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3029
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"

docs/src/UserGuide/combine.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ The resulting array `whole_year` still has one dimension, i.e. time, but with 12
1111

1212
````@example cat
1313
using YAXArrays
14+
using YAXArrays: YAXArrays as YAX
1415
15-
first_half = YAXArray((Dim{:time}(1:6),), rand(6))
16-
second_half = YAXArray((Dim{:time}(7:12),), rand(6))
16+
first_half = YAXArray((YAX.time(1:6),), rand(6))
17+
second_half = YAXArray((YAX.time(7:12),), rand(6))
1718
whole_year = cat(first_half, second_half, dims = 1)
1819
````
1920

@@ -25,10 +26,11 @@ Note that using a `Dataset` instead is a more flexible approach in handling diff
2526

2627
````@example concatenatecubes
2728
using YAXArrays
29+
using YAXArrays: YAXArrays as YAX
2830
29-
temperature = YAXArray((Dim{:time}(1:6),), rand(6))
30-
precipitation = YAXArray((Dim{:time}(1:6),), rand(6))
31+
temperature = YAXArray((YAX.time(1:6),), rand(6))
32+
precipitation = YAXArray((YAX.time(1:6),), rand(6))
3133
cubes = [temperature,precipitation]
32-
var_axis = Dim{:variable}(["temp", "prep"])
34+
var_axis = Variables(["temp", "prep"])
3335
combined = concatenatecubes(cubes, var_axis)
3436
````

docs/src/UserGuide/compute.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Let's start by creating an example dataset:
1212

1313
````@example compute
1414
using YAXArrays
15+
using YAXArrays: YAXArrays as YAX
1516
using Dates
1617
1718
axlist = (
18-
Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-30")),
19-
Dim{:lon}(range(1, 10, length=10)),
20-
Dim{:lat}(range(1, 5, length=15)),
19+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-30")),
20+
lon(range(1, 10, length=10)),
21+
lat(range(1, 5, length=15)),
2122
)
2223
data = rand(30, 10, 15)
2324
properties = Dict(:origin => "user guide")
@@ -103,6 +104,7 @@ Here, we will define a simple function, that will take as input several `YAXArra
103104

104105
````@example mapCube
105106
using YAXArrays, Zarr
107+
using YAXArrays: YAXArrays as YAX
106108
using Dates
107109
````
108110

@@ -130,23 +132,23 @@ Note the `.` after `f`, this is because we will slice across time, namely, the f
130132
Here, we do create `YAXArrays` only with the desired dimensions as
131133

132134
````@ansi mapCube
133-
lon = YAXArray(Dim{:lon}(range(1, 15)))
134-
lat = YAXArray(Dim{:lat}(range(1, 10)))
135+
lon_yax = YAXArray(lon(range(1, 15)))
136+
lat_yax = YAXArray(lat(range(1, 10)))
135137
````
136138

137139
And a time Cube's Axis
138140

139141
````@example mapCube
140142
tspan = Date("2022-01-01"):Day(1):Date("2022-01-30")
141-
time = YAXArray(Dim{:time}(tspan))
143+
time_yax = YAXArray(YAX.time(tspan))
142144
````
143145

144146
note that the following can be extended to arbitrary `YAXArrays` with additional data and dimensions.
145147

146148
Let's generate a new `cube` using `mapCube` and saving the output directly into disk.
147149

148150
````@ansi mapCube
149-
gen_cube = mapCube(g, (lon, lat, time);
151+
gen_cube = mapCube(g, (lon_yax, lat_yax, time_yax);
150152
indims = (InDims(), InDims(), InDims("time")),
151153
outdims = OutDims("time", overwrite=true, path="my_gen_cube.zarr", backend=:zarr,
152154
outtype = Float32)
@@ -170,7 +172,7 @@ gen_cube.data[1, :, :]
170172
but, we can generate a another cube with a different `output order` as follows
171173

172174
````@ansi mapCube
173-
gen_cube = mapCube(g, (lon, lat, time);
175+
gen_cube = mapCube(g, (lon_yax, lat_yax, time_yax);
174176
indims = (InDims("lon"), InDims(), InDims()),
175177
outdims = OutDims("lon", overwrite=true, path="my_gen_cube.zarr", backend=:zarr,
176178
outtype = Float32)
@@ -197,15 +199,17 @@ which outputs the same as the `gen_cube.data[1, :, :]` called above.
197199
Here, we will consider different scenarios, namely how we deal with different input cubes and how to specify the output ones. We will illustrate this with the following test example and the subsequent function definitions.
198200

199201
````@example outdims
200-
using YAXArrays, Dates
202+
using YAXArrays
203+
using YAXArrays: YAXArrays as YAX
204+
using Dates
201205
using Zarr
202206
using Random
203207
204208
axlist = (
205-
Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-05")),
206-
Dim{:lon}(range(1, 4, length=4)),
207-
Dim{:lat}(range(1, 3, length=3)),
208-
Dim{:variables}(["a", "b"])
209+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-05")),
210+
lon(range(1, 4, length=4)),
211+
lat(range(1, 3, length=3)),
212+
Variables(["a", "b"])
209213
)
210214
211215
Random.seed!(123)
@@ -308,7 +312,7 @@ Here, the goal is to operate at the pixel level (longitude, latitude), and then
308312
Random.seed!(123)
309313
data = rand(3.0:5.0, 5, 4, 3)
310314
311-
axlist = (Dim{:lon}(1:4), Dim{:lat}(1:3), Dim{:depth}(1:7),)
315+
axlist = (lon(1:4), lat(1:3), Dim{:depth}(1:7),)
312316
yax_2d = YAXArray(axlist, rand(-3.0:0.0, 4, 3, 7))
313317
````
314318

@@ -318,8 +322,8 @@ and
318322
Random.seed!(123)
319323
data = rand(3.0:5.0, 5, 4, 3)
320324
321-
axlist = (Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-05")),
322-
Dim{:lon}(1:4), Dim{:lat}(1:3),)
325+
axlist = (YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-05")),
326+
lon(1:4), lat(1:3),)
323327
324328
properties = Dict("description" => "multi dimensional test cube")
325329
yax_test = YAXArray(axlist, data, properties)
@@ -359,13 +363,14 @@ First, create the raster array:
359363

360364
````@example compute_mapcube
361365
using YAXArrays
366+
using YAXArrays: YAXArrays as YAX
362367
using DimensionalData
363368
using Dates
364369
365370
axlist = (
366-
Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-30")),
367-
Dim{:lon}(range(1, 10, length=10)),
368-
Dim{:lat}(range(1, 5, length=15)),
371+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-30")),
372+
lon(range(1, 10, length=10)),
373+
lat(range(1, 5, length=15)),
369374
)
370375
data = rand(30, 10, 15)
371376
raster_arr = YAXArray(axlist, data)
@@ -432,13 +437,14 @@ The following code does a time mean over all grid points using multiple CPUs of
432437

433438
````julia
434439
using YAXArrays
440+
using YAXArrays: YAXArrays as YAX
435441
using Dates
436442
using Distributed
437443

438444
axlist = (
439-
Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-30")),
440-
Dim{:lon}(range(1, 10, length=10)),
441-
Dim{:lat}(range(1, 5, length=15)),
445+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-30")),
446+
lon(range(1, 10, length=10)),
447+
lat(range(1, 5, length=15)),
442448
)
443449
data = rand(30, 10, 15)
444450
properties = Dict(:origin => "user guide")

docs/src/UserGuide/convert.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ m2 = collect(a.data)
3434

3535
A `Raster` as defined in [Rasters.jl](https://rafaqz.github.io/Rasters.jl/stable/) has a same supertype of a `YAXArray`, i.e. `AbstractDimArray`, allowing easy conversion between those types:
3636

37-
````@example convert
37+
````julia
3838
using Rasters
3939

4040
lon, lat = X(25:1:30), Y(25:1:30)
@@ -43,7 +43,7 @@ ras = Raster(rand(lon, lat, time))
4343
a = YAXArray(dims(ras), ras.data)
4444
````
4545

46-
````@example convert
46+
````julia
4747
ras2 = Raster(a)
4848
````
4949

docs/src/UserGuide/create.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ We can create a new YAXArray by filling the values directly:
88

99
````@example create
1010
using YAXArrays
11+
using YAXArrays: YAXArrays as YAX
12+
1113
a1 = YAXArray(rand(10, 20, 5))
1214
````
1315

@@ -18,9 +20,9 @@ We can also specify the dimensions with custom names enabling easier access:
1820
using Dates
1921
2022
axlist = (
21-
Dim{:time}(Date("2022-01-01"):Day(1):Date("2022-01-30")),
22-
Dim{:lon}(range(1, 10, length=10)),
23-
Dim{:lat}(range(1, 5, length=15)),
23+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-30")),
24+
lon(range(1, 10, length=10)),
25+
lat(range(1, 5, length=15)),
2426
)
2527
data2 = rand(30, 10, 15)
2628
properties = Dict(:origin => "user guide")

docs/src/UserGuide/faq.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ It is possible to concatenate several cubes that shared the same dimensions usin
8181
Let's create two dummy cubes
8282
````@example howdoi
8383
using YAXArrays
84+
using YAXArrays: YAXArrays as YAX
85+
8486
axlist = (
85-
Dim{:time}(range(1, 20, length=20)),
86-
Dim{:lon}(range(1, 10, length=10)),
87-
Dim{:lat}(range(1, 5, length=15))
87+
YAX.time(range(1, 20, length=20)),
88+
lon(range(1, 10, length=10)),
89+
lat(range(1, 5, length=15))
8890
)
8991
9092
data1 = rand(20, 10, 15)
@@ -125,7 +127,7 @@ t = Date("2020-01-01"):Month(1):Date("2022-12-31")
125127
create YAXArray axes
126128

127129
```@example howdoi
128-
axes = (Dim{:Lon}(1:10), Dim{:Lat}(1:10), Dim{:Time}(t))
130+
axes = (Lon(1:10), Lat(1:10), YAX.Time(t))
129131
```
130132

131133
create the YAXArray
@@ -169,7 +171,7 @@ using Dates # To generate the dates of the time axis
169171
using DimensionalData # To use the "Between" option for selecting data
170172
171173
t = Date("2020-01-01"):Month(1):Date("2022-12-31")
172-
axes = (Dim{:Lon}(1:10), Dim{:Lat}(1:10), Dim{:Time}(t))
174+
axes = (Lon(1:10), Lat(1:10), YAX.Time(t))
173175
174176
var1 = YAXArray(axes, reshape(1:3600, (10, 10, 36)))
175177
var2 = YAXArray(axes, reshape((1:3600)*5, (10, 10, 36)))
@@ -195,7 +197,7 @@ using DimensionalData # To use the "Between" selector for selecting data
195197
196198
t = Date("2020-01-01"):Month(1):Date("2022-12-31")
197199
common_axis = Dim{:points}(1:100)
198-
time_axis = Dim{:Time}(t)
200+
time_axis = YAX.Time(t)
199201
200202
# Note that longitudes and latitudes are not dimensions, but YAXArrays
201203
longitudes = YAXArray((common_axis,), rand(1:369, 100)) # 100 random values taken from 1 to 359
@@ -324,7 +326,9 @@ You will not be able to save this dataset, first you will need to rename those `
324326
In this section we will use `MarketData.jl` and `TimeSeries.jl` to simulate some stocks.
325327

326328
````@example howdoi
327-
using YAXArrays, DimensionalData
329+
using YAXArrays
330+
using YAXArrays: YAXArrays as YAX
331+
using DimensionalData
328332
using MarketData, TimeSeries
329333
330334
stocks = Dict(:Stock1 => random_ohlcv(), :Stock2 => random_ohlcv(), :Stock3 => random_ohlcv())
@@ -334,7 +338,7 @@ d_keys = keys(stocks)
334338
currently there is not direct support to obtain `dims` from a `TimeArray`, but we can code a function for it
335339

336340
````@example howdoi
337-
getTArrayAxes(ta::TimeArray) = (Dim{:time}(timestamp(ta)), Dim{:variable}(colnames(ta)), );
341+
getTArrayAxes(ta::TimeArray) = (YAX.time(timestamp(ta)), Variables(colnames(ta)), );
338342
nothing # hide
339343
````
340344
then, we create the `YAXArrays` as

0 commit comments

Comments
 (0)