obsarray 1.0.1__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {obsarray-1.0.1/obsarray.egg-info → obsarray-1.0.3}/PKG-INFO +8 -13
- obsarray-1.0.3/docs/conf.py +181 -0
- obsarray-1.0.3/notebook/test_register_err_corr_form.py +45 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/__init__.py +1 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/_version.py +4 -4
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/flag_accessor.py +6 -6
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/dataset_util.py +4 -4
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/test/test_unc_accessor.py +86 -24
- obsarray-1.0.3/obsarray/test/test_utils.py +169 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/unc_accessor.py +99 -4
- obsarray-1.0.3/obsarray/utils.py +66 -0
- {obsarray-1.0.1 → obsarray-1.0.3/obsarray.egg-info}/PKG-INFO +8 -13
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray.egg-info/SOURCES.txt +5 -2
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray.egg-info/requires.txt +1 -1
- obsarray-1.0.3/obsarray.egg-info/top_level.txt +5 -0
- obsarray-1.0.3/pyproject.toml +47 -0
- obsarray-1.0.3/setup.cfg +4 -0
- obsarray-1.0.3/setup.py +7 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/versioneer.py +790 -341
- obsarray-1.0.1/obsarray/utils.py +0 -31
- obsarray-1.0.1/obsarray.egg-info/top_level.txt +0 -1
- obsarray-1.0.1/setup.cfg +0 -30
- obsarray-1.0.1/setup.py +0 -48
- {obsarray-1.0.1 → obsarray-1.0.3}/LICENSE +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/MANIFEST.in +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/README.md +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/err_corr.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/__init__.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/dstemplater.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/dswriter.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/template_util.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/tests/__init__.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/tests/test_dataset_util.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/tests/test_dswriter.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/templater/tests/test_template_util.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/test/__init__.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/test/test_err_corr_forms.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray/test/test_flag_accessor.py +0 -0
- {obsarray-1.0.1 → obsarray-1.0.3}/obsarray.egg-info/dependency_links.txt +0 -0
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: obsarray
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Measurement data handling in Python
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
-
Classifier: Programming Language :: Python
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
5
|
+
Author-email: CoMet Toolkit Team <team@comet-toolkit.org>
|
|
6
|
+
Project-URL: Homepage, https://github.com/comet-toolkit/obsarray
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
15
9
|
License-File: LICENSE
|
|
16
10
|
Requires-Dist: comet_maths
|
|
17
|
-
Requires-Dist: netcdf4
|
|
11
|
+
Requires-Dist: netcdf4
|
|
18
12
|
Requires-Dist: xarray
|
|
19
13
|
Provides-Extra: dev
|
|
20
14
|
Requires-Dist: pre-commit; extra == "dev"
|
|
@@ -24,6 +18,7 @@ Requires-Dist: sphinx_design; extra == "dev"
|
|
|
24
18
|
Requires-Dist: sphinx_book_theme; extra == "dev"
|
|
25
19
|
Requires-Dist: ipython; extra == "dev"
|
|
26
20
|
Requires-Dist: sphinx_autosummary_accessors; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
27
22
|
|
|
28
23
|
# obsarray: Measurement uncertainty handling in Python
|
|
29
24
|
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
#
|
|
3
|
+
# obsarray documentation build configuration file, created by
|
|
4
|
+
# cookiecutter
|
|
5
|
+
#
|
|
6
|
+
# This file is execfile()d with the current directory set to its
|
|
7
|
+
# containing dir.
|
|
8
|
+
#
|
|
9
|
+
# Note that not all possible configuration values are present in this
|
|
10
|
+
# autogenerated file.
|
|
11
|
+
#
|
|
12
|
+
# All configuration values have a default; values that are commented out
|
|
13
|
+
# serve to show the default.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# If extensions (or modules to document with autodoc) are in another
|
|
17
|
+
# directory, add these directories to sys.path here. If the directory is
|
|
18
|
+
# relative to the documentation root, use os.path.abspath to make it
|
|
19
|
+
# absolute, like shown here.
|
|
20
|
+
|
|
21
|
+
import sphinx_autosummary_accessors
|
|
22
|
+
import obsarray
|
|
23
|
+
|
|
24
|
+
project_title = "obsarray".replace("_", " ").title()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# -- General configuration ---------------------------------------------
|
|
28
|
+
|
|
29
|
+
# If your documentation needs a minimal Sphinx version, state it here.
|
|
30
|
+
#
|
|
31
|
+
# needs_sphinx = '1.0'
|
|
32
|
+
|
|
33
|
+
# Attempt to make links automatially
|
|
34
|
+
default_role = "code"
|
|
35
|
+
|
|
36
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
|
37
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
|
38
|
+
# CFAB added napolean to support google-style docstrings
|
|
39
|
+
extensions = [
|
|
40
|
+
"sphinx.ext.autodoc",
|
|
41
|
+
"sphinx.ext.autosummary",
|
|
42
|
+
"sphinx.ext.intersphinx",
|
|
43
|
+
"sphinx.ext.viewcode",
|
|
44
|
+
"sphinx.ext.napoleon",
|
|
45
|
+
"IPython.sphinxext.ipython_directive",
|
|
46
|
+
"IPython.sphinxext.ipython_console_highlighting",
|
|
47
|
+
"sphinx_design",
|
|
48
|
+
"sphinx_autosummary_accessors",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# Add any paths that contain templates here, relative to this directory.
|
|
52
|
+
templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]
|
|
53
|
+
|
|
54
|
+
# The suffix(es) of source filenames.
|
|
55
|
+
# You can specify multiple suffix as a list of string:
|
|
56
|
+
#
|
|
57
|
+
# source_suffix = ['.rst', '.md']
|
|
58
|
+
source_suffix = ".rst"
|
|
59
|
+
|
|
60
|
+
# The master toctree document.
|
|
61
|
+
master_doc = "index"
|
|
62
|
+
|
|
63
|
+
# General information about the project.
|
|
64
|
+
project = project_title
|
|
65
|
+
copyright = "CoMet Toolkit Team"
|
|
66
|
+
author = "CoMet Toolkit Team"
|
|
67
|
+
|
|
68
|
+
# The version info for the project you're documenting, acts as replacement
|
|
69
|
+
# for |version| and |release|, also used in various other places throughout
|
|
70
|
+
# the built documents.
|
|
71
|
+
#
|
|
72
|
+
# The short X.Y version.
|
|
73
|
+
version = obsarray.__version__
|
|
74
|
+
# The full version, including alpha/beta/rc tags.
|
|
75
|
+
release = obsarray.__version__
|
|
76
|
+
|
|
77
|
+
# The language for content autogenerated by Sphinx. Refer to documentation
|
|
78
|
+
# for a list of supported languages.
|
|
79
|
+
#
|
|
80
|
+
# This is also used if you do content translation via gettext catalogs.
|
|
81
|
+
# Usually you set "language" from the command line for these cases.
|
|
82
|
+
language = None
|
|
83
|
+
|
|
84
|
+
# List of patterns, relative to source directory, that match files and
|
|
85
|
+
# directories to ignore when looking for source files.
|
|
86
|
+
# This patterns also effect to html_static_path and html_extra_path
|
|
87
|
+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
|
88
|
+
|
|
89
|
+
# The name of the Pygments (syntax highlighting) style to use.
|
|
90
|
+
pygments_style = "sphinx"
|
|
91
|
+
|
|
92
|
+
rst_prolog = """
|
|
93
|
+
.. role:: python(code)
|
|
94
|
+
:language: python
|
|
95
|
+
:class: highlight
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
|
99
|
+
todo_include_todos = False
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# -- Options for HTML output -------------------------------------------
|
|
103
|
+
|
|
104
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
105
|
+
# a list of builtin themes.
|
|
106
|
+
#
|
|
107
|
+
html_theme = "sphinx_book_theme"
|
|
108
|
+
|
|
109
|
+
# Theme options are theme-specific and customize the look and feel of a
|
|
110
|
+
# theme further. For a list of options available for each theme, see the
|
|
111
|
+
# documentation.
|
|
112
|
+
#
|
|
113
|
+
# html_theme_options = {}
|
|
114
|
+
|
|
115
|
+
html_logo = "figs/obsarray.png"
|
|
116
|
+
|
|
117
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
|
118
|
+
# relative to this directory. They are copied after the builtin static files,
|
|
119
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
120
|
+
html_static_path = ["_static"]
|
|
121
|
+
|
|
122
|
+
# -- Options for HTMLHelp output ---------------------------------------
|
|
123
|
+
|
|
124
|
+
# Output file base name for HTML help builder.
|
|
125
|
+
htmlhelp_basename = "obsarraydoc"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# -- Options for LaTeX output ------------------------------------------
|
|
129
|
+
|
|
130
|
+
latex_elements = {
|
|
131
|
+
# The paper size ('letterpaper' or 'a4paper').
|
|
132
|
+
#
|
|
133
|
+
# 'papersize': 'letterpaper',
|
|
134
|
+
# The font size ('10pt', '11pt' or '12pt').
|
|
135
|
+
#
|
|
136
|
+
# 'pointsize': '10pt',
|
|
137
|
+
# Additional stuff for the LaTeX preamble.
|
|
138
|
+
#
|
|
139
|
+
# 'preamble': '',
|
|
140
|
+
# Latex figure (float) alignment
|
|
141
|
+
#
|
|
142
|
+
# 'figure_align': 'htbp',
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Grouping the document tree into LaTeX files. List of tuples
|
|
146
|
+
# (source start file, target name, title, author, documentclass
|
|
147
|
+
# [howto, manual, or own class]).
|
|
148
|
+
latex_documents = [
|
|
149
|
+
(
|
|
150
|
+
master_doc,
|
|
151
|
+
"user_manual.tex",
|
|
152
|
+
"{} Documentation".format(project_title),
|
|
153
|
+
"CoMet Toolkit Team",
|
|
154
|
+
"manual",
|
|
155
|
+
),
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# -- Options for manual page output ------------------------------------
|
|
160
|
+
|
|
161
|
+
# One entry per manual page. List of tuples
|
|
162
|
+
# (source start file, name, description, authors, manual section).
|
|
163
|
+
man_pages = [(master_doc, "obsarray", "obsarray Documentation", [author], 1)]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# -- Options for Texinfo output ----------------------------------------
|
|
167
|
+
|
|
168
|
+
# Grouping the document tree into Texinfo files. List of tuples
|
|
169
|
+
# (source start file, target name, title, author,
|
|
170
|
+
# dir menu entry, description, category)
|
|
171
|
+
texinfo_documents = [
|
|
172
|
+
(
|
|
173
|
+
master_doc,
|
|
174
|
+
"obsarray",
|
|
175
|
+
"obsarray Documentation",
|
|
176
|
+
author,
|
|
177
|
+
"obsarray",
|
|
178
|
+
"Extension to xarray for handling uncertainty quantified observation data",
|
|
179
|
+
"Miscellaneous",
|
|
180
|
+
),
|
|
181
|
+
]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from obsarray.err_corr import register_err_corr_form, BaseErrCorrForm
|
|
2
|
+
import xarray as xr
|
|
3
|
+
import numpy as np
|
|
4
|
+
import obsarray
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@register_err_corr_form("new")
|
|
8
|
+
class NewForm(BaseErrCorrForm):
|
|
9
|
+
|
|
10
|
+
form = "new"
|
|
11
|
+
is_systematic = True
|
|
12
|
+
|
|
13
|
+
def build_matrix(self, idx: np.ndarray) -> np.ndarray:
|
|
14
|
+
return "abc"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# ds = xr.open_dataset("obs_example.nc")
|
|
18
|
+
#
|
|
19
|
+
# ds.unc["temperature"]["u_sys_temperature"] = (
|
|
20
|
+
# ["x", "y", "time"],
|
|
21
|
+
# ds.temperature * 0.03,
|
|
22
|
+
# {
|
|
23
|
+
# "err_corr": [
|
|
24
|
+
# {
|
|
25
|
+
# "dim": "x",
|
|
26
|
+
# "form": "new",
|
|
27
|
+
# "params": [],
|
|
28
|
+
# },
|
|
29
|
+
# {
|
|
30
|
+
# "dim": "y",
|
|
31
|
+
# "form": "systematic",
|
|
32
|
+
# "params": [],
|
|
33
|
+
# },
|
|
34
|
+
# {
|
|
35
|
+
# "dim": "time",
|
|
36
|
+
# "form": "systematic",
|
|
37
|
+
# "params": [],
|
|
38
|
+
# },
|
|
39
|
+
# ]
|
|
40
|
+
# },
|
|
41
|
+
# )
|
|
42
|
+
#
|
|
43
|
+
# p = ds.unc["temperature"]["u_sys_temperature"]
|
|
44
|
+
#
|
|
45
|
+
# pass
|
|
@@ -9,6 +9,7 @@ from obsarray.err_corr import err_corr_forms
|
|
|
9
9
|
from obsarray.templater.template_util import create_ds
|
|
10
10
|
from obsarray.templater.dstemplater import DSTemplater
|
|
11
11
|
from obsarray.templater.dswriter import DSWriter
|
|
12
|
+
from obsarray.utils import append_names
|
|
12
13
|
|
|
13
14
|
__version__ = get_versions()["version"]
|
|
14
15
|
del get_versions
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
# This file was generated by 'versioneer.py' (0.
|
|
2
|
+
# This file was generated by 'versioneer.py' (0.29) from
|
|
3
3
|
# revision-control system data, or from the parent directory name of an
|
|
4
4
|
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
|
5
5
|
# of this file.
|
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "
|
|
11
|
+
"date": "2025-06-22T11:46:36+0200",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "
|
|
14
|
+
"full-revisionid": "48598121962220e8e42df0515693a450e732585c",
|
|
15
|
+
"version": "1.0.3"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -194,12 +194,12 @@ class FlagVariable:
|
|
|
194
194
|
)
|
|
195
195
|
|
|
196
196
|
if flag_meaning not in flag_meanings:
|
|
197
|
-
self._obj[
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
self._obj[
|
|
198
|
+
self._flag_var_name
|
|
199
|
+
].attrs = DatasetUtil.add_flag_meaning_to_attrs(
|
|
200
|
+
self._obj[self._flag_var_name].attrs,
|
|
201
|
+
flag_meaning,
|
|
202
|
+
self._obj[self._flag_var_name].dtype,
|
|
203
203
|
)
|
|
204
204
|
|
|
205
205
|
self[flag_meaning][:] = flag_value
|
|
@@ -454,15 +454,15 @@ class DatasetUtil:
|
|
|
454
454
|
if dtype == numpy.int8:
|
|
455
455
|
return numpy.int8(-127)
|
|
456
456
|
if dtype == numpy.uint8:
|
|
457
|
-
return numpy.uint8
|
|
457
|
+
return numpy.iinfo(numpy.uint8).max
|
|
458
458
|
elif dtype == numpy.int16:
|
|
459
459
|
return numpy.int16(-32767)
|
|
460
460
|
elif dtype == numpy.uint16:
|
|
461
|
-
return numpy.uint16
|
|
461
|
+
return numpy.iinfo(numpy.uint16).max
|
|
462
462
|
elif dtype == numpy.int32:
|
|
463
463
|
return numpy.int32(-2147483647)
|
|
464
464
|
elif dtype == numpy.uint32:
|
|
465
|
-
return numpy.uint32
|
|
465
|
+
return numpy.iinfo(numpy.uint32).max
|
|
466
466
|
elif dtype == numpy.int64:
|
|
467
467
|
return numpy.int64(-9223372036854775806)
|
|
468
468
|
elif dtype == numpy.float32:
|
|
@@ -507,7 +507,7 @@ class DatasetUtil:
|
|
|
507
507
|
ds[flag_meaning] = DatasetUtil.create_variable(
|
|
508
508
|
list(da.shape), bool, dim_names=list(da.dims)
|
|
509
509
|
)
|
|
510
|
-
ds[flag_meaning] = (da & flag_mask).astype(bool)
|
|
510
|
+
ds[flag_meaning] = (da.astype(int) & flag_mask).astype(bool)
|
|
511
511
|
|
|
512
512
|
return ds
|
|
513
513
|
|
|
@@ -34,7 +34,7 @@ def compare_err_corr_form(self, form, exp_form):
|
|
|
34
34
|
self.assertCountEqual(form._unc_var_name, exp_form._unc_var_name)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def create_ds():
|
|
37
|
+
def create_ds(var_suffix="", dim_suffix="", coord_dim_suffix_extra=""):
|
|
38
38
|
np.random.seed(0)
|
|
39
39
|
temperature = 15 + 8 * np.random.randn(2, 2, 3)
|
|
40
40
|
u_r_temperature = temperature * 0.02
|
|
@@ -47,42 +47,59 @@ def create_ds():
|
|
|
47
47
|
reference_time = pd.Timestamp("2014-09-05")
|
|
48
48
|
|
|
49
49
|
ds = xr.Dataset(
|
|
50
|
-
data_vars=
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
data_vars={
|
|
51
|
+
"temperature"
|
|
52
|
+
+ var_suffix: (
|
|
53
|
+
[
|
|
54
|
+
"x" + dim_suffix,
|
|
55
|
+
"y" + dim_suffix,
|
|
56
|
+
"time" + dim_suffix + coord_dim_suffix_extra,
|
|
57
|
+
],
|
|
58
|
+
temperature,
|
|
59
|
+
{"units": "K"},
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
coords={
|
|
63
|
+
"lon" + var_suffix: (["x" + dim_suffix, "y" + dim_suffix], lon),
|
|
64
|
+
"lat" + var_suffix: (["x" + dim_suffix, "y" + dim_suffix], lat),
|
|
65
|
+
"time" + var_suffix: ("time" + dim_suffix + coord_dim_suffix_extra, time),
|
|
66
|
+
"reference_time": reference_time,
|
|
67
|
+
},
|
|
59
68
|
attrs=dict(description="Weather related data."),
|
|
60
69
|
)
|
|
61
70
|
|
|
62
|
-
ds.unc["temperature"]["u_ran_temperature"] = (
|
|
63
|
-
[
|
|
71
|
+
ds.unc["temperature" + var_suffix]["u_ran_temperature" + var_suffix] = (
|
|
72
|
+
[
|
|
73
|
+
"x" + dim_suffix,
|
|
74
|
+
"y" + dim_suffix,
|
|
75
|
+
"time" + dim_suffix + coord_dim_suffix_extra,
|
|
76
|
+
],
|
|
64
77
|
temperature * 0.05,
|
|
65
78
|
{"units": "K", "pdf_shape": "gaussian"},
|
|
66
79
|
)
|
|
67
80
|
|
|
68
|
-
ds.unc["temperature"]["u_sys_temperature"] = (
|
|
69
|
-
[
|
|
81
|
+
ds.unc["temperature" + var_suffix]["u_sys_temperature" + var_suffix] = (
|
|
82
|
+
[
|
|
83
|
+
"x" + dim_suffix,
|
|
84
|
+
"y" + dim_suffix,
|
|
85
|
+
"time" + dim_suffix + coord_dim_suffix_extra,
|
|
86
|
+
],
|
|
70
87
|
temperature * 0.03,
|
|
71
88
|
{
|
|
72
89
|
"units": "K",
|
|
73
90
|
"err_corr": [
|
|
74
91
|
{
|
|
75
|
-
"dim": "x",
|
|
92
|
+
"dim": "x" + dim_suffix,
|
|
76
93
|
"form": "systematic",
|
|
77
94
|
"params": [],
|
|
78
95
|
},
|
|
79
96
|
{
|
|
80
|
-
"dim": "y",
|
|
97
|
+
"dim": "y" + dim_suffix,
|
|
81
98
|
"form": "systematic",
|
|
82
99
|
"params": [],
|
|
83
100
|
},
|
|
84
101
|
{
|
|
85
|
-
"dim": "time",
|
|
102
|
+
"dim": "time" + dim_suffix + coord_dim_suffix_extra,
|
|
86
103
|
"form": "systematic",
|
|
87
104
|
"params": [],
|
|
88
105
|
},
|
|
@@ -91,19 +108,26 @@ def create_ds():
|
|
|
91
108
|
},
|
|
92
109
|
)
|
|
93
110
|
|
|
94
|
-
ds.unc["temperature"]["u_str_temperature"] = (
|
|
95
|
-
[
|
|
111
|
+
ds.unc["temperature" + var_suffix]["u_str_temperature" + var_suffix] = (
|
|
112
|
+
[
|
|
113
|
+
"x" + dim_suffix,
|
|
114
|
+
"y" + dim_suffix,
|
|
115
|
+
"time" + dim_suffix + coord_dim_suffix_extra,
|
|
116
|
+
],
|
|
96
117
|
temperature * 0.1,
|
|
97
118
|
{
|
|
98
119
|
"units": "K",
|
|
99
120
|
"err_corr": [
|
|
100
121
|
{
|
|
101
|
-
"dim": [
|
|
122
|
+
"dim": [
|
|
123
|
+
"x" + dim_suffix,
|
|
124
|
+
"time" + dim_suffix + coord_dim_suffix_extra,
|
|
125
|
+
],
|
|
102
126
|
"form": "err_corr_matrix",
|
|
103
|
-
"params": ["err_corr_str_temperature"],
|
|
127
|
+
"params": ["err_corr_str_temperature" + var_suffix],
|
|
104
128
|
},
|
|
105
129
|
{
|
|
106
|
-
"dim": "y",
|
|
130
|
+
"dim": "y" + dim_suffix,
|
|
107
131
|
"form": "systematic",
|
|
108
132
|
"params": [],
|
|
109
133
|
},
|
|
@@ -112,8 +136,8 @@ def create_ds():
|
|
|
112
136
|
},
|
|
113
137
|
)
|
|
114
138
|
|
|
115
|
-
ds["err_corr_str_temperature"] = (
|
|
116
|
-
["x.time", "x.time"],
|
|
139
|
+
ds["err_corr_str_temperature" + var_suffix] = (
|
|
140
|
+
["x.time" + dim_suffix, "x.time" + dim_suffix],
|
|
117
141
|
np.ones(
|
|
118
142
|
(
|
|
119
143
|
temperature.shape[0] * temperature.shape[2],
|
|
@@ -740,6 +764,44 @@ class TestUncertainty(unittest.TestCase):
|
|
|
740
764
|
exp_ecm = xr.DataArray(np.ones((12, 12)), dims=["x.y.time", "x.y.time"])
|
|
741
765
|
xr.testing.assert_equal(ecm, exp_ecm)
|
|
742
766
|
|
|
767
|
+
def test_rename_vars(self):
|
|
768
|
+
var_suffix = "_test"
|
|
769
|
+
input_ds = create_ds()
|
|
770
|
+
|
|
771
|
+
ds = input_ds.unc.rename(
|
|
772
|
+
{
|
|
773
|
+
"temperature": "temperature" + var_suffix,
|
|
774
|
+
"lon": "lon" + var_suffix,
|
|
775
|
+
"lat": "lat" + var_suffix,
|
|
776
|
+
"time": "time" + var_suffix,
|
|
777
|
+
"u_ran_temperature": "u_ran_temperature" + var_suffix,
|
|
778
|
+
"u_str_temperature": "u_str_temperature" + var_suffix,
|
|
779
|
+
"u_sys_temperature": "u_sys_temperature" + var_suffix,
|
|
780
|
+
"err_corr_str_temperature": "err_corr_str_temperature" + var_suffix,
|
|
781
|
+
}
|
|
782
|
+
)
|
|
783
|
+
|
|
784
|
+
exp_ds = create_ds(var_suffix=var_suffix, coord_dim_suffix_extra=var_suffix)
|
|
785
|
+
|
|
786
|
+
xr.testing.assert_identical(ds, exp_ds)
|
|
787
|
+
|
|
788
|
+
def test_rename_dims(self):
|
|
789
|
+
dim_suffix = "_test"
|
|
790
|
+
input_ds = create_ds()
|
|
791
|
+
|
|
792
|
+
ds = input_ds.unc.rename_dims(
|
|
793
|
+
{
|
|
794
|
+
"x": "x" + dim_suffix,
|
|
795
|
+
"y": "y" + dim_suffix,
|
|
796
|
+
"time": "time" + dim_suffix,
|
|
797
|
+
"x.time": "x.time_test",
|
|
798
|
+
}
|
|
799
|
+
)
|
|
800
|
+
|
|
801
|
+
exp_ds = create_ds(dim_suffix=dim_suffix)
|
|
802
|
+
|
|
803
|
+
xr.testing.assert_identical(ds, exp_ds)
|
|
804
|
+
|
|
743
805
|
|
|
744
806
|
if __name__ == "__main__":
|
|
745
807
|
unittest.main()
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""test_utils - tests for obsarray.utils"""
|
|
2
|
+
|
|
3
|
+
import unittest
|
|
4
|
+
import numpy as np
|
|
5
|
+
from obsarray import append_names, create_ds
|
|
6
|
+
import xarray as xr
|
|
7
|
+
|
|
8
|
+
__author__ = "Sam Hunt <sam.hunt@npl.co.uk>"
|
|
9
|
+
__all__ = []
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_test_ds(suffix):
|
|
13
|
+
# define ds variables
|
|
14
|
+
template = {
|
|
15
|
+
"temperature"
|
|
16
|
+
+ suffix: {
|
|
17
|
+
"dtype": np.float32,
|
|
18
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
19
|
+
"attributes": {
|
|
20
|
+
"units": "K",
|
|
21
|
+
"unc_comps": [
|
|
22
|
+
"u_ran_temperature" + suffix,
|
|
23
|
+
"u_sys_temperature" + suffix,
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
"u_ran_temperature"
|
|
28
|
+
+ suffix: {
|
|
29
|
+
"dtype": np.float32,
|
|
30
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
31
|
+
"attributes": {
|
|
32
|
+
"units": "K",
|
|
33
|
+
"err_corr": [
|
|
34
|
+
{"dim": "x" + suffix, "form": "random", "params": [], "units": []},
|
|
35
|
+
{"dim": "y" + suffix, "form": "random", "params": [], "units": []},
|
|
36
|
+
{
|
|
37
|
+
"dim": "time" + suffix,
|
|
38
|
+
"form": "random",
|
|
39
|
+
"params": [],
|
|
40
|
+
"units": [],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"u_sys_temperature"
|
|
46
|
+
+ suffix: {
|
|
47
|
+
"dtype": np.float32,
|
|
48
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
49
|
+
"attributes": {
|
|
50
|
+
"units": "K",
|
|
51
|
+
"err_corr": [
|
|
52
|
+
{
|
|
53
|
+
"dim": "x" + suffix,
|
|
54
|
+
"form": "systematic",
|
|
55
|
+
"params": [],
|
|
56
|
+
"units": [],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"dim": "y" + suffix,
|
|
60
|
+
"form": "systematic",
|
|
61
|
+
"params": [],
|
|
62
|
+
"units": [],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"dim": "time" + suffix,
|
|
66
|
+
"form": "systematic",
|
|
67
|
+
"params": [],
|
|
68
|
+
"units": [],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
"pressure"
|
|
74
|
+
+ suffix: {
|
|
75
|
+
"dtype": np.float32,
|
|
76
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
77
|
+
"attributes": {"units": "Pa", "unc_comps": ["u_str_pressure" + suffix]},
|
|
78
|
+
},
|
|
79
|
+
"u_str_pressure"
|
|
80
|
+
+ suffix: {
|
|
81
|
+
"dtype": np.float32,
|
|
82
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
83
|
+
"attributes": {
|
|
84
|
+
"units": "Pa",
|
|
85
|
+
"err_corr": [
|
|
86
|
+
{"dim": "x" + suffix, "form": "random", "params": [], "units": []},
|
|
87
|
+
{
|
|
88
|
+
"dim": "y" + suffix,
|
|
89
|
+
"form": "err_corr_matrix",
|
|
90
|
+
"params": "err_corr_str_pressure_y",
|
|
91
|
+
"units": [],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"dim": "time" + suffix,
|
|
95
|
+
"form": "systematic",
|
|
96
|
+
"params": [],
|
|
97
|
+
"units": [],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
"err_corr_str_pressure_y"
|
|
103
|
+
+ suffix: {
|
|
104
|
+
"dtype": np.float32,
|
|
105
|
+
"dim": ["y" + suffix, "y" + suffix],
|
|
106
|
+
"attributes": {"units": ""},
|
|
107
|
+
},
|
|
108
|
+
"n_moles"
|
|
109
|
+
+ suffix: {
|
|
110
|
+
"dtype": np.float32,
|
|
111
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
112
|
+
"attributes": {"units": "", "unc_comps": ["u_ran_n_moles" + suffix]},
|
|
113
|
+
},
|
|
114
|
+
"u_ran_n_moles"
|
|
115
|
+
+ suffix: {
|
|
116
|
+
"dtype": np.float32,
|
|
117
|
+
"dim": ["x" + suffix, "y" + suffix, "time" + suffix],
|
|
118
|
+
"attributes": {
|
|
119
|
+
"units": "",
|
|
120
|
+
"err_corr": [
|
|
121
|
+
{"dim": "x" + suffix, "form": "random", "params": [], "units": []},
|
|
122
|
+
{"dim": "y" + suffix, "form": "random", "params": [], "units": []},
|
|
123
|
+
{
|
|
124
|
+
"dim": "time" + suffix,
|
|
125
|
+
"form": "random",
|
|
126
|
+
"params": [],
|
|
127
|
+
"units": [],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# define dim_size_dict to specify size of arrays
|
|
135
|
+
dim_sizes = {"x" + suffix: 20, "y" + suffix: 30, "time" + suffix: 6}
|
|
136
|
+
|
|
137
|
+
# create dataset template
|
|
138
|
+
ds = create_ds(template, dim_sizes)
|
|
139
|
+
|
|
140
|
+
# populate with example data
|
|
141
|
+
ds["temperature" + suffix].values = 293 * np.ones((20, 30, 6))
|
|
142
|
+
ds["u_ran_temperature" + suffix].values = 1 * np.ones((20, 30, 6))
|
|
143
|
+
ds["u_sys_temperature" + suffix].values = 0.4 * np.ones((20, 30, 6))
|
|
144
|
+
ds["pressure" + suffix].values = 10**5 * np.ones((20, 30, 6))
|
|
145
|
+
ds["u_str_pressure" + suffix].values = 10 * np.ones((20, 30, 6))
|
|
146
|
+
ds["err_corr_str_pressure_y" + suffix].values = 0.5 * np.ones(
|
|
147
|
+
(30, 30)
|
|
148
|
+
) + 0.5 * np.eye(30)
|
|
149
|
+
ds["n_moles" + suffix].values = 40 * np.ones((20, 30, 6))
|
|
150
|
+
ds["u_ran_n_moles" + suffix].values = 1 * np.ones((20, 30, 6))
|
|
151
|
+
|
|
152
|
+
ds.attrs["attr" + suffix] = "val"
|
|
153
|
+
|
|
154
|
+
return ds
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class TestAppendNames(unittest.TestCase):
|
|
158
|
+
def test_append_names(self):
|
|
159
|
+
|
|
160
|
+
input_ds = create_test_ds(suffix="")
|
|
161
|
+
ds = append_names(input_ds, "_test")
|
|
162
|
+
|
|
163
|
+
exp_ds = create_test_ds(suffix="_test")
|
|
164
|
+
|
|
165
|
+
xr.testing.assert_identical(ds, exp_ds)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
unittest.main()
|