Skip to content

Commit a784df5

Browse files
authored
docs: Data orientation note + merge sections (#58)
Notes how underlying data layout maps to Makie.jl when using heatmap/image/etc. Also merges the Intro and Introduction sections
1 parent 091153c commit a784df5

5 files changed

Lines changed: 115 additions & 138 deletions

File tree

docs/make.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ makedocs(;
1616
),
1717
pages = [
1818
"Home" => "index.md",
19-
"Introduction" => "intro.md",
2019
"Examples" => [
2120
"JWST" => "examples/jwst.md",
2221
"Roman" => "examples/roman.md",

docs/src/examples/jwst.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ Colorbar(fig[1, 2], hm; label = "Counts")
5353
5454
fig
5555
```
56+
57+
!!! note
58+
By default, Makie.jl places the origin in the lower left corner and transposes the data, matching the convention used in the Python workshop example. To have the plot orientation match the data orientation instead, modify the above plot command to: `heatmap(img_sci'; axis = (; yreversed = true))`. See also [`permutedims`](https://docs.julialang.org/en/v1/base/arrays/#Base.permutedims) for a more general alternative to the adjoint (conjugate transpose) operation: [`'`](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#Base.adjoint).

docs/src/examples/roman.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ Colorbar(fig[1, 2], hm; label = "Counts")
5555
5656
fig
5757
```
58+
59+
!!! note
60+
By default, Makie.jl places the origin in the lower left corner and transposes the data, matching the convention used in the Python workshop example. To have the plot orientation match the data orientation instead, modify the above plot command to: `heatmap(img_sci'; axis = (; yreversed = true))`. See also [`permutedims`](https://docs.julialang.org/en/v1/base/arrays/#Base.permutedims) for a more general alternative to the adjoint (conjugate transpose) operation: [`'`](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#Base.adjoint).

docs/src/index.md

Lines changed: 109 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,127 @@
22

33
A new [Advanced Scientific Data Format (ASDF)](https://asdf-standard.readthedocs.io/en/latest/index.html) package, written in Julia.
44

5-
## Quickstart
5+
## Introduction
66

7-
### Installation
7+
The ASDF file format is based on the human-readable [YAML](http://yaml.org/) standard, extended with efficient binary blocks to store array data. Basic arithmetic types (`Bool`, `Int`, `Float`, `Complex`) and `String` types are supported out of the box. Other types (structures) need to be declared to be supported.
8+
9+
ASDF supports arbitrary array strides, both C (Python) and Fortran (Julia) memory layouts, as well as compression. The YAML metadata can contain arbitrary information corresponding to scalars, arrays, or dictionaries.
10+
11+
The ASDF file format targets a similar audience as the [HDF5](https://www.hdfgroup.org/solutions/hdf5/) format.
12+
13+
## Installation
814

915
```julia-repl
1016
pkg> add ASDF, OrderedCollections
1117
```
1218

13-
### Usage
14-
15-
```@example quickstart
19+
```@repl intro
1620
using ASDF, OrderedCollections
21+
```
1722

18-
doc = OrderedDict(
19-
"field_1" => [5, 6, 7, 8],
20-
"field_2" => ["up", "down", "left", "right"],
21-
"field_3" => OrderedDict(
22-
"field_3a" => ["apple", "orange", "pear"],
23-
"field_3b" => [1.0, 2.0, 3.0],
24-
)
25-
)
23+
!!! note
24+
We use an `OrderedDict` from [OrderedCollections.jl](https://github.com/JuliaCollections/OrderedCollections.jl) to preserve the order of data on write and load, and to maximize compatibility with YAML.jl.
2625

27-
save("example.asdf", doc)
26+
## Getting started
27+
28+
ASDF files are initially created as a dictionary with arbitrarily nested data:
29+
30+
```@example intro
31+
af_payload = OrderedDict("field_1" => [5, 6, 7, 8], "field_2" => ["up", "down", "left", "right"], "field_3" => OrderedDict("field_3a" => ["apple", "orange", "pear"], "field_3b" => [1.0, 2.0, 3.0]))
2832
```
2933

30-
```@example quickstart
31-
af = load("example.asdf")
34+
ASDF.jl is registered with [FileIO.jl](https://juliaio.github.io/FileIO.jl/stable/), so this data can be written to the ASDF file format with the generic [`save`](@ref) function:
35+
36+
```@example intro
37+
save("intro.asdf", af_payload)
3238
```
3339

34-
```@example quickstart
40+
The saved file contains the following human-readable contents:
41+
42+
!!! details "View file"
43+
```@example intro
44+
read("intro.asdf", String) |> print
45+
```
46+
47+
which can be loaded back with FileIO.jl's generic [`load`](@ref) function:
48+
49+
```@example intro
50+
af = load("intro.asdf")
51+
```
52+
53+
This is stored as an [`ASDF.ASDFFile`](@ref). To change the number of rows shown, pass this object to [`ASDF.info`](@ref):
54+
55+
```@example intro
3556
ASDF.info(af; max_rows = 3)
3657
```
58+
59+
It contains a `metadata` field, which is a new dictionary that merges information about this library (stored under the `asdf_library` key) with the original user-defined `af_payload` dictionary. For convenience, `af.metadata[<key>]` can be accessed directly as `af[key]`. Since the underlying data is a dictionary, it can be modified in the standard way:
60+
61+
```@example intro
62+
af["field_1"] = [50, 60, 70, 80]
63+
```
64+
65+
The convenience syntax can also be used to save the modified `ASDF.ASDFFile` object directly:
66+
67+
```@example intro
68+
save("intro_modified.asdf", af)
69+
```
70+
71+
!!! details "View file"
72+
```@example intro
73+
read("intro_modified.asdf", String) |> print
74+
```
75+
76+
## Array storage
77+
78+
By default, array data is written inline as a literal to the ASDF file. This can be stored and later accessed more efficiently by wrapping your data in an [`ASDF.NDArrayWrapper`](@ref). This allows for your data to be stored as a binary via the `inline = false` keyword (default), which can be further optimized by specifying a supported [compression algorithm](@ref ASDF.Compression) to use via the `compression` keyword:
79+
80+
```@example intro
81+
af_payload = OrderedDict("meta" => OrderedDict("my" => OrderedDict("nested" => "metadata")), "data" => ASDF.NDArrayWrapper([1, 2, 3, 4]; compression = ASDF.C_Bzip2))
82+
83+
save("intro_compressed.asdf", af_payload)
84+
85+
af = load("intro_compressed.asdf")
86+
```
87+
88+
!!! details "View file"
89+
```julia-repl
90+
julia> read("intro_compressed.asdf", String) |> print
91+
#ASDF 1.0.0
92+
#ASDF_STANDARD 1.6.0
93+
# This is an ASDF file <https://asdf-standard.readthedocs.io/>
94+
%YAML 1.1
95+
%TAG ! tag:stsci.edu:asdf/
96+
---
97+
!core/asdf-1.1.0
98+
meta:
99+
my:
100+
nested: "metadata"
101+
data: !core/ndarray-1.1.0
102+
source: 0
103+
shape:
104+
- 4
105+
datatype: "int64"
106+
byteorder: "little"
107+
asdf_library: !core/software-1.0.0
108+
name: "ASDF.jl"
109+
author: "Erik Schnetter <schnetter@gmail.com>"
110+
homepage: "https://github.com/JuliaAstro/ASDF.jl"
111+
version: "2.0.0"
112+
...
113+
�BLK0 f�0xj�sq���r#ASDF BLOCK INDEX
114+
%YAML 1.1
115+
---
116+
[463,]
117+
...
118+
```
119+
120+
Using `NDArrayWrapper` allows for the wrapped data to be lazily accessed as a strided view. To access the underlying data, use the `[]` (dereference) syntax:
121+
122+
```@example intro
123+
af["data"][] == [1, 2, 3, 4]
124+
```
125+
126+
## Tagged objects
127+
128+
Come back soon to see how custom Julia objects can be handled in ASDF.jl.

docs/src/intro.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)