Skip to content

Commit a4c0efe

Browse files
committed
add quickstart guide
1 parent 3ebabce commit a4c0efe

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

docs/content/user/quickstart.rst

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,100 @@
44
Quickstart Guide
55
################
66

7-
Under development.
7+
Installation
8+
------------
9+
10+
**obsarray** is installable via pip.
11+
12+
.. code-block::
13+
14+
pip install obsarray
15+
16+
17+
Dependencies
18+
------------
19+
20+
**obsarray** is an extension to `xarray <https://docs.xarray.dev/en/stable/>`_ to support defining, storing and interfacing with measurement data. It is designed to work well with `netCDF <https://www.unidata.ucar.edu/software/netcdf/>`_ files, using the `netcdf4 <https://unidata.github.io/netcdf4-python/>`_ library.
21+
22+
The pip installation will also automatically install any dependencies.
23+
24+
25+
Example Usage
26+
-------------
27+
28+
First we build an example dataset that represents a time series of temperatures (for more on how do this see the `xarray <https://docs.xarray.dev/en/stable/>`_ documentation).
29+
30+
.. ipython:: python
31+
32+
import numpy as np
33+
import xarray as xr
34+
import obsarray
35+
36+
# build an xarray to represents a time series of temperatures
37+
temps = np.array([20.2, 21.1, 20.8])
38+
times = np.array([0, 30, 60])
39+
ds = xr.Dataset(
40+
{"temperature": (["time"], temps, {"units": "degC"})},
41+
coords = {"time": (["time"], times, {"units": "s"})}
42+
)
43+
44+
Uncertainty and error-covariance information for observation variables can be defined using the dataset's ``unc`` accessor, which is provided by **obsarray**.
45+
46+
.. ipython:: python
47+
48+
# add random component uncertainty
49+
ds.unc["temperature"]["u_r_temperature"] = (
50+
["time"],
51+
np.array([0.5, 0.5, 0.6]),
52+
{"err_corr": [{"dim": "time", "form": "random"}]}
53+
)
54+
# add systematic component uncertainty
55+
ds.unc["temperature"]["u_s_temperature"] = (
56+
["time"],
57+
np.array([0.3, 0.3, 0.3]),
58+
{"err_corr": [{"dim": "time", "form": "systematic"}]}
59+
)
60+
61+
Dataset structures can be defined separately using **obsarray**'s :ref:`templating <template>` functionality. This is helpful for processing chains where you want to write files to a defined format.
62+
63+
The defined uncertainty information then can be interfaced with, for example:
64+
65+
.. ipython:: python
66+
67+
# get total combined uncertainty of all components
68+
ds.unc["temperature"].total_unc()
69+
# get total error-covariance matrix for all components
70+
ds.unc["temperature"].total_err_cov_matrix()
71+
72+
This information is preserved in metadata when written to netCDF files
73+
74+
.. ipython:: python
75+
76+
# show uncertainty components
77+
ds.unc["temperature"]
78+
# write file
79+
ds.to_netcdf("~/temp_ds.nc")
80+
# reopen file
81+
ds = xr.open_dataset("~/temp_ds.nc")
82+
# show uncertainty components
83+
ds.unc["temperature"]
84+
85+
Similarly, data flags can be defined using the dataset’s ``flag`` accessor, which again is provided by **obsarray**. These flags are defined following the `CF Convention <https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html#flags>`_ metadata standard.
86+
87+
A flag variable can be created to store data for a set of flags with defined meanings
88+
89+
.. ipython:: python
90+
91+
ds.flag["quality_flags"] = (
92+
["time"],
93+
{"flag_meanings": ["dubious", "invalid", "saturated"]}
94+
)
95+
print(ds.flag)
96+
97+
These flag meanings can be indexed, to get and set their value
98+
99+
.. ipython:: python
100+
101+
print(ds.flag["quality_flags"]["dubious"].value)
102+
ds.flag["quality_flags"]["dubious"][0] = True
103+
print(ds.flag["quality_flags"]["dubious"].value)

docs/content/user/templater.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _template:
2+
13
=================================
24
Creating Datasets Using Templates
35
=================================

0 commit comments

Comments
 (0)