queryearth 0.0.1__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.
Files changed (36) hide show
  1. queryearth-0.0.1/.gitignore +8 -0
  2. queryearth-0.0.1/LICENSE +201 -0
  3. queryearth-0.0.1/MANIFEST.in +3 -0
  4. queryearth-0.0.1/PKG-INFO +55 -0
  5. queryearth-0.0.1/README.md +29 -0
  6. queryearth-0.0.1/examples/toy/pack.toml +37 -0
  7. queryearth-0.0.1/examples/toy/play.py +181 -0
  8. queryearth-0.0.1/examples/toy/rules.geojson +210 -0
  9. queryearth-0.0.1/pyproject.toml +42 -0
  10. queryearth-0.0.1/queryearth/__init__.py +110 -0
  11. queryearth-0.0.1/queryearth/_version.py +24 -0
  12. queryearth-0.0.1/queryearth/dimensions.py +532 -0
  13. queryearth-0.0.1/queryearth/emit.py +190 -0
  14. queryearth-0.0.1/queryearth/errors.py +36 -0
  15. queryearth-0.0.1/queryearth/index.py +847 -0
  16. queryearth-0.0.1/queryearth/objects.py +516 -0
  17. queryearth-0.0.1/queryearth/packs.py +216 -0
  18. queryearth-0.0.1/queryearth/rules.py +497 -0
  19. queryearth-0.0.1/queryearth/space.py +306 -0
  20. queryearth-0.0.1/queryearth/time.py +312 -0
  21. queryearth-0.0.1/queryearth.egg-info/PKG-INFO +55 -0
  22. queryearth-0.0.1/queryearth.egg-info/SOURCES.txt +34 -0
  23. queryearth-0.0.1/queryearth.egg-info/dependency_links.txt +1 -0
  24. queryearth-0.0.1/queryearth.egg-info/requires.txt +9 -0
  25. queryearth-0.0.1/queryearth.egg-info/scm_file_list.json +45 -0
  26. queryearth-0.0.1/queryearth.egg-info/scm_version.json +8 -0
  27. queryearth-0.0.1/queryearth.egg-info/top_level.txt +1 -0
  28. queryearth-0.0.1/setup.cfg +4 -0
  29. queryearth-0.0.1/tests/test_dimensions.py +284 -0
  30. queryearth-0.0.1/tests/test_emit.py +208 -0
  31. queryearth-0.0.1/tests/test_import.py +6 -0
  32. queryearth-0.0.1/tests/test_index.py +1103 -0
  33. queryearth-0.0.1/tests/test_packs.py +523 -0
  34. queryearth-0.0.1/tests/test_queries.py +284 -0
  35. queryearth-0.0.1/tests/test_space.py +321 -0
  36. queryearth-0.0.1/tests/test_time.py +357 -0
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .pytest_cache/
7
+ .ipynb_checkpoints/
8
+ queryearth/_version.py
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020-2025 University Corporation for Atmospheric Research (UCAR)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ prune docs
2
+ prune .github
3
+ exclude CLAUDE.md
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: queryearth
3
+ Version: 0.0.1
4
+ Summary: Match rules scoped by area, time and other dimensions to a request, and get caveats, coverage gaps and recommendations.
5
+ Author: Manish Venumuddula
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/CROCODILE-CESM/queryearth
8
+ Keywords: geospatial,advisories,data quality,rules,earth science
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: GIS
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+ Requires-Dist: shapely>=2.1
19
+ Provides-Extra: test
20
+ Requires-Dist: pytest; extra == "test"
21
+ Requires-Dist: jsonschema; extra == "test"
22
+ Requires-Dist: cftime; extra == "test"
23
+ Requires-Dist: pandas; extra == "test"
24
+ Requires-Dist: pyproj; extra == "test"
25
+ Dynamic: license-file
26
+
27
+ # queryearth
28
+
29
+ queryearth answers one question: given where (a point or a polygon, such as a lake outline or a model domain), when (a time range) and anything else that matters (grid resolution, product, variable and so on), which registered rules apply, how much of the request does each one cover, and what does it say to watch out for or to do?
30
+
31
+ Rules are GeoJSON features or short Python classes. A query returns findings of three kinds: caveats ("these values are climatology, not observations"), coverage gaps ("this product does not reach part of your request") and recommendations ("set this model parameter"). queryearth ships no rules of its own; you bring yours.
32
+
33
+ **Status:** pre-alpha. The design is in [docs/design.md](docs/design.md). To try it, run [examples/toy/play.py](examples/toy/play.py), which loads a small made-up pack and walks through queries, coverage gaps, Python rules, `emit()`, `suitable()` and `query_points()`.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install queryearth
39
+ ```
40
+
41
+ queryearth needs Python 3.11 or later, numpy and shapely 2.1 or later.
42
+
43
+ ## Development
44
+
45
+ ```bash
46
+ pip install -e ".[test]"
47
+ pytest
48
+ black .
49
+ ```
50
+
51
+ Versions come from git tags through setuptools-scm. Every push to `main` builds the package, and every GitHub release tagged `vX.Y.Z` publishes version X.Y.Z to PyPI.
52
+
53
+ ## Licence
54
+
55
+ Apache-2.0.
@@ -0,0 +1,29 @@
1
+ # queryearth
2
+
3
+ queryearth answers one question: given where (a point or a polygon, such as a lake outline or a model domain), when (a time range) and anything else that matters (grid resolution, product, variable and so on), which registered rules apply, how much of the request does each one cover, and what does it say to watch out for or to do?
4
+
5
+ Rules are GeoJSON features or short Python classes. A query returns findings of three kinds: caveats ("these values are climatology, not observations"), coverage gaps ("this product does not reach part of your request") and recommendations ("set this model parameter"). queryearth ships no rules of its own; you bring yours.
6
+
7
+ **Status:** pre-alpha. The design is in [docs/design.md](docs/design.md). To try it, run [examples/toy/play.py](examples/toy/play.py), which loads a small made-up pack and walks through queries, coverage gaps, Python rules, `emit()`, `suitable()` and `query_points()`.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install queryearth
13
+ ```
14
+
15
+ queryearth needs Python 3.11 or later, numpy and shapely 2.1 or later.
16
+
17
+ ## Development
18
+
19
+ ```bash
20
+ pip install -e ".[test]"
21
+ pytest
22
+ black .
23
+ ```
24
+
25
+ Versions come from git tags through setuptools-scm. Every push to `main` builds the package, and every GitHub release tagged `vX.Y.Z` publishes version X.Y.Z to PyPI.
26
+
27
+ ## Licence
28
+
29
+ Apache-2.0.
@@ -0,0 +1,37 @@
1
+ # A made-up pack to play with. The products, rules and parameter names are
2
+ # invented; nothing here describes real data or real model guidance.
3
+ [pack]
4
+ name = "toy"
5
+ version = "0.1.0"
6
+ code_prefix = ["TOY"]
7
+ license = "CC0-1.0"
8
+ files = ["rules.geojson"]
9
+
10
+ # The dimensions the records use. They must exist on the Index the pack is
11
+ # loaded into (play.py declares the resolution axis; the facets are defaults).
12
+ [axes.resolution]
13
+ unit = "km"
14
+ description = "horizontal grid spacing"
15
+
16
+ [facets]
17
+ names = ["product", "variable", "model"]
18
+
19
+ # A global ocean reanalysis, from 1993 onwards.
20
+ [products.toy_ocean]
21
+ aliases = ["TOYO"]
22
+ variables = ["thetao", "so", "zos"]
23
+ resolution = [0.25, "deg"]
24
+ coverage = { time = ["1993-01-01", ".."] }
25
+
26
+ # A global atmosphere reanalysis, from 1950 onwards.
27
+ [products.toy_atmos]
28
+ variables = ["t2m", "tp"]
29
+ resolution = [0.5, "deg"]
30
+ coverage = { time = ["1950-01-01", ".."] }
31
+
32
+ # A regional ocean product that covers one box (roughly the Gulf of Mexico)
33
+ # for 2010 to 2023 only.
34
+ [products.toy_coastal]
35
+ variables = ["thetao", "so"]
36
+ resolution = [2.0, "km"]
37
+ coverage = { time = ["2010-01-01", "2023-12-31"], box = { west = -98, width = 18, south = 18, north = 31 } }
@@ -0,0 +1,181 @@
1
+ """Play with queryearth on a made-up pack.
2
+
3
+ Run it cell by cell in VS Code (each "# %%" line starts a cell), or as a script
4
+ from the repository root:
5
+
6
+ pip install -e .
7
+ python examples/toy/play.py
8
+
9
+ Everything in the toy pack is invented: the products (toy_ocean, toy_atmos,
10
+ toy_coastal), the rules (TOY...) and the parameter names. Edit pack.toml,
11
+ rules.geojson or this file and rerun to see what changes.
12
+ """
13
+
14
+ # %% Set up: an Index with a resolution axis, then load the toy pack.
15
+ import logging
16
+ from pathlib import Path
17
+
18
+ import numpy as np
19
+
20
+ import queryearth as qe
21
+ from queryearth import space as sp
22
+
23
+ HERE = Path(globals().get("__file__", "play.py")).resolve().parent
24
+
25
+ index = qe.Index("toy", axes=[qe.Axis("resolution", "km")])
26
+ print("loaded:", index.load_pack(HERE))
27
+ print("products:", list(index.products))
28
+
29
+
30
+ def show(findings):
31
+ """One line per finding, then any suggestions under it."""
32
+ if not findings:
33
+ print(" (no findings)")
34
+ for f in findings:
35
+ area, time = (
36
+ "-" if x is None else f"{x:.0%}" for x in (f.area_fraction, f.time_fraction)
37
+ )
38
+ print(f" {f.code:7} {f.kind:14} {f.severity.name:8} {f.product or '-':11}")
39
+ print(f" {f.title}")
40
+ print(f" area {area}, time {time}, periods {f.time_overlap}")
41
+ if f.conditional_on:
42
+ print(f" conditional on {f.conditional_on}")
43
+ if f.assumed:
44
+ print(f" filled from the product: {f.assumed}")
45
+ for s in f.suggestions:
46
+ print(f" -> set {s.target}:{s.key} = {s.value!r}")
47
+
48
+
49
+ # %% 1. A Bering Sea domain that crosses the antimeridian, winter 2000-01, 8 km.
50
+ # TOY002 covers only December to March, so its time fraction is below 1.
51
+ # TOY101 needs the Arctic, and only the top of this domain is north of 66.5N.
52
+ bering = sp.box(165, 52, -160, 70) # west, south, east, north
53
+ winter = qe.interval("2000-11-01", "2001-03-31")
54
+ show(
55
+ index.query(
56
+ space=bering,
57
+ time=winter,
58
+ axes={"resolution": (8, 8)},
59
+ facets={"model": ["mom6"]},
60
+ requests=[qe.Request("toy_ocean", variables=("thetao", "so"))],
61
+ )
62
+ )
63
+
64
+ # %% 2. The same domain with no time: each product's coverage is used instead,
65
+ # and the findings say so in "filled from the product".
66
+ show(
67
+ index.query(
68
+ space=bering,
69
+ axes={"resolution": (8, 8)},
70
+ requests=[qe.Request("toy_ocean", variables="so")],
71
+ )
72
+ )
73
+
74
+ # %% 3. Resolution only. TOY102 applies outright; with include_conditional=True
75
+ # the other rules come back too, each naming what the query left out.
76
+ show(index.query(axes={"resolution": (3, 3)}, include_conditional=True))
77
+
78
+ # %% 4. Coverage gaps. toy_coastal covers one box from 2010 to 2023 only, so
79
+ # asking for it in the Bering Sea gives QE001 (space) and in 2005 QE002 (time).
80
+ show(index.query(space=bering, time=winter, requests=["toy_coastal"]))
81
+ gulf = sp.box(-95, 22, -85, 29)
82
+ show(
83
+ index.query(
84
+ space=gulf,
85
+ time=qe.interval("2005-01-01", "2005-12-31"),
86
+ requests=["toy_coastal"],
87
+ )
88
+ )
89
+
90
+ # %% 5. Rules written in Python. A static rule, and a computed rule whose
91
+ # suggestion depends on the query (a made-up time step from the finest cells).
92
+ index.add(
93
+ qe.Rule(
94
+ code="TOY201",
95
+ kind="caveat",
96
+ title="toy_atmos 2 m temperature is too cold over sea ice",
97
+ message="Over sea ice, toy_atmos t2m runs a few kelvin too cold.",
98
+ severity=qe.Severity.WARNING,
99
+ scope=qe.Scope(
100
+ space=sp.box(-180, 60, 180, 90), facets={"product": ["toy_atmos"]}
101
+ ),
102
+ )
103
+ )
104
+
105
+
106
+ @index.rule(
107
+ "TOY202",
108
+ kind="recommendation",
109
+ axes={"resolution": {"gt": 0}}, # needs a resolution, so conditional without one
110
+ )
111
+ def time_step(query, match):
112
+ """Set the toy time step from the finest cells"""
113
+ finest_km = match.axes["resolution"].lo
114
+ seconds = 30.0 * finest_km # made up: 30 s per km
115
+ return {"suggestions": [qe.Suggestion("MOM_input", "TOY_DT", seconds, "made up")]}
116
+
117
+
118
+ show(
119
+ index.query(
120
+ space=bering,
121
+ time=winter,
122
+ axes={"resolution": (4, 12)},
123
+ requests=["toy_atmos"],
124
+ )
125
+ )
126
+
127
+ # %% 6. Findings are data; emit() reports them. Try each mode.
128
+ findings = index.query(
129
+ space=bering,
130
+ time=winter,
131
+ axes={"resolution": (8, 8)},
132
+ facets={"model": ["mom6"]},
133
+ requests=[qe.Request("toy_ocean", variables=("thetao", "so"))],
134
+ )
135
+
136
+ qe.emit(findings) # default: Python warnings for caveats, log lines for advice
137
+
138
+ logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s", force=True)
139
+ qe.emit(findings, mode="log")
140
+
141
+ collected = []
142
+ qe.emit(findings, mode=lambda finding, text: collected.append(text)) # a sink
143
+ print("sink got:", collected)
144
+
145
+ try:
146
+ qe.emit(findings, mode="raise")
147
+ except qe.AdvisoryError as err:
148
+ print("raised for:", [f.code for f in err.findings])
149
+
150
+ with qe.policy(mode="log", ignore={"TOY002"}, show_recommendations=False):
151
+ qe.emit(findings) # only TOY001 is left
152
+
153
+ # %% 7. Which product suits salinity in the Gulf in 2000? toy_coastal starts in
154
+ # 2010 so it drops out; toy_ocean stays, with TOY001 against it. A low score
155
+ # means fewer known concerns, not better data.
156
+ for s in index.suitable(
157
+ qe.Query(space=gulf, time=qe.interval("2000-01-01", "2000-12-31")),
158
+ "so",
159
+ include_dropped=True,
160
+ ):
161
+ print(f" {s.product.name:11} score {s.score} {[f.code for f in s.findings]}")
162
+
163
+ # %% 8. Many points at once: every 1-degree cell centre, January 2001, toy_ocean.
164
+ lon, lat = np.meshgrid(np.arange(-179.5, 180, 1.0), np.arange(-89.5, 90, 1.0))
165
+ result = index.query_points(
166
+ lon,
167
+ lat,
168
+ time=qe.interval("2001-01-01", "2001-01-31"),
169
+ requests=[qe.Request("toy_ocean", variables="thetao")],
170
+ )
171
+ for key, mask in result.masks.items():
172
+ print(f" {key}: {mask.sum()} of {mask.size} points")
173
+
174
+ try:
175
+ import matplotlib.pyplot as plt
176
+
177
+ plt.pcolormesh(lon, lat, result.any(min_severity="info"), shading="nearest")
178
+ plt.title("points with a finding")
179
+ plt.show()
180
+ except ImportError:
181
+ pass