aeronet-oc-db 1.2.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.
@@ -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 2026 Tristan Harmel
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,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: aeronet_oc_db
3
+ Version: 1.2.1
4
+ Summary: AERONET-OC version 3 database: download, update, netCDF/Parquet conversion and readers for satellite validation
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Repository, https://github.com/Tristanovsk/aeronet_oc_db
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas>=2
12
+ Requires-Dist: xarray
13
+ Requires-Dist: netCDF4
14
+ Requires-Dist: pyarrow>=12
15
+ Requires-Dist: requests
16
+ Requires-Dist: pyproj
17
+ Provides-Extra: test
18
+ Requires-Dist: pytest; extra == "test"
19
+ Dynamic: license-file
20
+
21
+ # aeronet_oc_db
22
+
23
+ AERONET-OC (version 3, SeaPRISM) database for the validation of the satellite products of `grs`,
24
+ `hgrs`, `grstbx` and `radcalnet_oc`. It replaces the legacy shell tool (`../download_aeronet_OC_v3.sh`)
25
+ and does the following:
26
+
27
+ * **downloads** the data from the AERONET web service (`print_web_data_v3`, all points). It either
28
+ re-downloads the full record of each site, which picks up the reprocessing of past data, or
29
+ fetches only the last days and merges them into the raw file;
30
+ * **discovers** the new AERONET-OC sites (sites with data in the last 60 days);
31
+ * keeps the **raw files** `<site>_OCv3.lev15|lev20` in the legacy layout. Each file is replaced
32
+ atomically and only when its records changed, so existing readers keep working without changes;
33
+ * **builds** the database products of the changed sites:
34
+ * one netCDF-4 file per site and level (CF-1.10 / ACDD-1.3, `featureType=timeSeries`, compressed
35
+ float32), dimensions `(time, wl)`;
36
+ * a Hive-partitioned Parquet dataset (zstd) with one row per (record, band), for queries across
37
+ sites with pandas, pyarrow, duckdb or polars;
38
+ * `catalog.csv`: one row per site and level with the coverage, location, bands, instruments, PI
39
+ and the checksum of the raw file;
40
+ * provides **readers** for validation: a dataset per site, filtered tables, and in situ statistics
41
+ at satellite overpass times.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install git+https://github.com/Tristanovsk/aeronet_oc_db.git
47
+ # development (editable) install
48
+ git clone https://github.com/Tristanovsk/aeronet_oc_db.git && pip install -e aeronet_oc_db
49
+ ```
50
+
51
+ The packages that use it declare it as their `aeronet` extra under its name (`aeronet_oc_db>=1.2`), because
52
+ PyPI does not accept dependencies given by a git URL: install `aeronet_oc_db` from GitHub first, then e.g.
53
+ `pip install radcalnet_oc[aeronet]`.
54
+
55
+ ## Update
56
+
57
+ ```bash
58
+ aeronet-oc-db update --discover # full re-download of all sites, new sites, build
59
+ aeronet-oc-db update --days 30 # quick update: last 30 days merged into the raw files
60
+ aeronet-oc-db update --sites AAOT Venise --levels lev20
61
+ aeronet-oc-db build --force # rebuild the products from the raw files
62
+ aeronet-oc-db discover # active sites, flags the ones not in the database
63
+ aeronet-oc-db status # catalog
64
+ ```
65
+
66
+ The root folder is `$AERONET_OC_ROOT`, or `/DATA/AERONET/OCv3` by default (`--root` overrides it).
67
+ Each run is logged in `db/update.log`.
68
+
69
+ Level 2.0 data are quality-assured with a delay of months to years and past records get
70
+ reprocessed. Use `--days` for frequent updates, and run a full update (the default) from time to
71
+ time, e.g. monthly.
72
+
73
+ ## Location of the database (shared by all the packages)
74
+
75
+ The packages find the database without hardcoded paths, in this order:
76
+
77
+ 1. `$AERONET_OC_ROOT`;
78
+ 2. `root` in `~/.config/aeronet_oc_db/config.toml` (also read by Jupyter, PyCharm and cron, which do not
79
+ always inherit the shell environment):
80
+ ```toml
81
+ root = "/DATA/AERONET/OCv3"
82
+ ```
83
+ 3. `/DATA/AERONET/OCv3`.
84
+
85
+ ## Use from the other packages
86
+
87
+ `aeronet_oc_db` is the single access layer to the AERONET-OC data. Each package declares it as an
88
+ optional dependency (`aeronet` extra), imports it only in the functions that need it, and keeps a
89
+ fallback when it is missing (CI, users without the database):
90
+
91
+ | package | install | entry points |
92
+ |---|---|---|
93
+ | radcalnet_oc | `pip install radcalnet_oc[aeronet]` | `Aeronet().read_site(site, level)`, `Aeronet.open_site`, `Aeronet().aeronet_oc_site_info` |
94
+ | grstbx | `pip install grstbx[aeronet]` | `Data().read_aeronet_oc_site`, `Data.open_aeronet_oc`, `Data.aeronet_oc_sites` |
95
+ | invRrs | `pip install invRrs[aeronet]` | `aeronet_data_loading.read().read_site`, `read.open_site`, `read.sites` |
96
+ | hgrs | validation scripts | `validation/aeronet_oc/common.py` (`HGRS_VAL_AERONET` overrides the location) |
97
+ | aeronet_visu | | `aeronet_files_merger.py` |
98
+
99
+ Functions of `aeronet_oc_db` for the code of the packages:
100
+
101
+ ```python
102
+ import aeronet_oc_db
103
+ aeronet_oc_db.open_site('AAOT', 'lev20') # xarray.Dataset (time, wl), database names
104
+ aeronet_oc_db.open_site('AAOT', 'lev20', legacy_names=True) # names of the former netcdf/OCv3 files
105
+ aeronet_oc_db.raw_file('AAOT', 'lev20') # raw file, for the existing text readers
106
+ aeronet_oc_db.site_info() # location, Sentinel-2 tile, coverage per level
107
+ aeronet_oc_db.site_info(level='lev15') # columns of info_aeronet_oc_v15_location.csv
108
+ aeronet_oc_db.default_root() # location of the database
109
+ ```
110
+
111
+ `legacy_names=True` gives the variable names of the former `AERONET/netcdf/OCv3` conversion
112
+ (`Aerosol_Optical_Depth`, `Lwn_fQ`, `Rrs_Lwn*`, `'Total_Precipitable_Water(cm)'`, `wavelength` in um,
113
+ `SZA`, ...), so that existing code only changes the line that opens the data. New code should use the
114
+ database names.
115
+
116
+ The Sentinel-2 tile of each site comes from `aeronet_oc_db/data/site_s2_tile.csv` (checked by hand: the
117
+ stations in the overlap of two tiles, e.g. Venise and AAOT in 32TQR rather than 33TUL), or is computed
118
+ (MGRS 100 km square) for the new sites. Add a line to that file to force the tile of a site.
119
+
120
+ ## Layout
121
+
122
+ ```
123
+ OCv3/
124
+ <site>_OCv3.lev15, <site>_OCv3.lev20 raw files (legacy layout: header on line 8)
125
+ db/catalog.csv
126
+ db/netcdf/<level>/<site>_OCv3.<level>.nc
127
+ db/parquet/level=<level>/site=<site>/data.parquet
128
+ db/update.log
129
+ ```
130
+
131
+ ## Variables
132
+
133
+ | name | dims | units | AERONET field |
134
+ |---|---|---|---|
135
+ | `wl` | coord | nm | nominal band |
136
+ | `wl_exact` | time, wl | nm | `Exact_Wavelengths(um)` |
137
+ | `Lt`, `Lt_std`, `Lt_min_rel` | time, wl | uW cm-2 nm-1 sr-1 | `Lt_mean`, `Lt_stddev`, `Lt_min_rel` |
138
+ | `Li`, `Li_std` | time, wl | uW cm-2 nm-1 sr-1 | `Li_mean`, `Li_stddev` |
139
+ | `rho` | time, wl | 1 | `Rho` |
140
+ | `Lw`, `LwQ`, `Lwn`, `Lwn_fQ`, `Lwn_IOP` | time, wl | uW cm-2 nm-1 sr-1 | `Lw`, `LwQ`, `Lwn`, `Lwn_f/Q`, `Lwn_IOP` |
141
+ | `Rrs_Lwn`, `Rrs_Lwn_fQ`, `Rrs_Lwn_IOP` | time, wl | sr-1 | 10 Lwn / F0 (see below) |
142
+ | `aot`, `tau_rayleigh`, `tau_o3`, `tau_no2`, `tau_h2o` | time, wl | 1 | `*_Optical_Depth` |
143
+ | `sza_band`, `saa_band` | time, wl | degree | `Solar_Zenith_Angle`, `Solar_Azimuth_Angle` |
144
+ | `sza` | time | degree | mean of `sza_band` |
145
+ | `tco3`, `tno2` | time | DU | `Total_Ozone(Du)`, `Total_NO2(DU)` |
146
+ | `tcwv` | time | cm | `Total_Precipitable_Water(cm)` |
147
+ | `chl` | time | mg m-3 | `Chlorophyll-a` |
148
+ | `wind`, `pressure` | time | m s-1, hPa | `Wind_Speed(m/s)`, `Pressure(hPa)` |
149
+ | `raa_sea`, `vza_sea` | time | degree | `ASea(Degrees)`, `ZSea(Degrees)` |
150
+ | `instrument`, `quality_level`, `last_processed` | time | | instrument number, data level, processing date |
151
+ | `latitude`, `longitude`, `elevation`, `station_name` | scalar | | site |
152
+
153
+ `Rrs_* = 10 Lwn_* / F0(wl_exact)`. F0 is the Thuillier et al. (2003) spectrum averaged over a
154
+ Gaussian band of 10 nm FWHM centred on the exact wavelength, as in `hgrs/validation/aeronet_oc`.
155
+ The previous `AERONET/netcdf/OCv3` files used the 0.3 nm spectrum interpolated at the exact
156
+ wavelength, which gives up to ±4% differences at 412 and 443 nm because of the Fraunhofer lines.
157
+ Times are UTC.
158
+
159
+ ## Use in the validation
160
+
161
+ ```python
162
+ from aeronet_oc_db import Database
163
+ db = Database()
164
+
165
+ # one site (xarray)
166
+ ds = db.open('AAOT', 'lev20')
167
+ ds.Rrs_Lwn_fQ.sel(time='2023-07').plot.line(x='wl', add_legend=False)
168
+
169
+ # in situ data at satellite overpasses: median of the records within 1 h
170
+ mu = db.match('AAOT', overpass_times, level='lev20', max_lag='1h') # dims (match, wl)
171
+ mu.Rrs_Lwn_fQ, mu.aot, mu.n_records, mu.lag_min
172
+
173
+ # several sites, filtered at read time (pandas)
174
+ df = db.table('lev20', sites=['AAOT', 'Venise', 'Galata_Platform'], start='2018-01-01',
175
+ columns=['Rrs_Lwn_fQ', 'aot', 'sza', 'chl'], wl=[443, 490, 560, 665])
176
+
177
+ # sites with a long level 2.0 record
178
+ db.catalog.query("level == 'lev20' and n_records > 1000")
179
+ ```
180
+
181
+ The products can be read without this package:
182
+
183
+ ```python
184
+ import xarray as xr, pandas as pd
185
+ xr.open_dataset('/DATA/AERONET/OCv3/db/netcdf/lev20/AAOT_OCv3.lev20.nc')
186
+ pd.read_parquet('/DATA/AERONET/OCv3/db/parquet', filters=[('level', '==', 'lev20'), ('site', '==', 'AAOT')])
187
+ # duckdb: SELECT * FROM read_parquet('/DATA/AERONET/OCv3/db/parquet/*/*/*.parquet', hive_partitioning=true)
188
+ ```
189
+
190
+ ## Tests
191
+
192
+ ```bash
193
+ ~/anaconda3/envs/py12/bin/python -m pytest tests
194
+ ```
195
+
196
+ ## Releasing on PyPI
197
+
198
+ The workflow `.github/workflows/pypi.yml` builds the sdist and the wheel, checks them (`twine check`, version,
199
+ content), runs the tests on the installed wheel with Python 3.10 and 3.12, then publishes with PyPI trusted
200
+ publishing (no token stored).
201
+
202
+ One-time setup, on pypi.org and test.pypi.org (*Your projects > Publishing > Add a new pending publisher*):
203
+ owner `Tristanovsk`, repository `aeronet_oc_db`, workflow `pypi.yml`, environment `pypi` (resp.
204
+ `testpypi`). In the GitHub repository, create the environments `pypi` and `testpypi`
205
+ (*Settings > Environments*; a required reviewer on `pypi` adds a manual approval before each upload).
206
+
207
+ Release:
208
+
209
+ 1. set `__version__` in `aeronet_oc_db/__init__.py` (the only place, `pyproject.toml` reads it);
210
+ 2. *Actions > Publish on PyPI > Run workflow* with `testpypi`, then check
211
+ `pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ aeronet_oc_db`;
212
+ 3. tag and push: `git tag -a v<version> -m "aeronet_oc_db <version>" && git push origin v<version>`: the
213
+ workflow publishes on PyPI (the tag must match `__version__`).
214
+
215
+ Once on PyPI, `pip install radcalnet_oc[aeronet]` (or grstbx, invRrs) installs `aeronet_oc_db` with no
216
+ extra step.
217
+
218
+ ## Data policy
219
+
220
+ AERONET-OC data are public. Publications must acknowledge AERONET and the site PIs (the PI is
221
+ stored in the attributes of each file and in the catalog). See
222
+ https://aeronet.gsfc.nasa.gov/new_web/data_usage.html.
@@ -0,0 +1,202 @@
1
+ # aeronet_oc_db
2
+
3
+ AERONET-OC (version 3, SeaPRISM) database for the validation of the satellite products of `grs`,
4
+ `hgrs`, `grstbx` and `radcalnet_oc`. It replaces the legacy shell tool (`../download_aeronet_OC_v3.sh`)
5
+ and does the following:
6
+
7
+ * **downloads** the data from the AERONET web service (`print_web_data_v3`, all points). It either
8
+ re-downloads the full record of each site, which picks up the reprocessing of past data, or
9
+ fetches only the last days and merges them into the raw file;
10
+ * **discovers** the new AERONET-OC sites (sites with data in the last 60 days);
11
+ * keeps the **raw files** `<site>_OCv3.lev15|lev20` in the legacy layout. Each file is replaced
12
+ atomically and only when its records changed, so existing readers keep working without changes;
13
+ * **builds** the database products of the changed sites:
14
+ * one netCDF-4 file per site and level (CF-1.10 / ACDD-1.3, `featureType=timeSeries`, compressed
15
+ float32), dimensions `(time, wl)`;
16
+ * a Hive-partitioned Parquet dataset (zstd) with one row per (record, band), for queries across
17
+ sites with pandas, pyarrow, duckdb or polars;
18
+ * `catalog.csv`: one row per site and level with the coverage, location, bands, instruments, PI
19
+ and the checksum of the raw file;
20
+ * provides **readers** for validation: a dataset per site, filtered tables, and in situ statistics
21
+ at satellite overpass times.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install git+https://github.com/Tristanovsk/aeronet_oc_db.git
27
+ # development (editable) install
28
+ git clone https://github.com/Tristanovsk/aeronet_oc_db.git && pip install -e aeronet_oc_db
29
+ ```
30
+
31
+ The packages that use it declare it as their `aeronet` extra under its name (`aeronet_oc_db>=1.2`), because
32
+ PyPI does not accept dependencies given by a git URL: install `aeronet_oc_db` from GitHub first, then e.g.
33
+ `pip install radcalnet_oc[aeronet]`.
34
+
35
+ ## Update
36
+
37
+ ```bash
38
+ aeronet-oc-db update --discover # full re-download of all sites, new sites, build
39
+ aeronet-oc-db update --days 30 # quick update: last 30 days merged into the raw files
40
+ aeronet-oc-db update --sites AAOT Venise --levels lev20
41
+ aeronet-oc-db build --force # rebuild the products from the raw files
42
+ aeronet-oc-db discover # active sites, flags the ones not in the database
43
+ aeronet-oc-db status # catalog
44
+ ```
45
+
46
+ The root folder is `$AERONET_OC_ROOT`, or `/DATA/AERONET/OCv3` by default (`--root` overrides it).
47
+ Each run is logged in `db/update.log`.
48
+
49
+ Level 2.0 data are quality-assured with a delay of months to years and past records get
50
+ reprocessed. Use `--days` for frequent updates, and run a full update (the default) from time to
51
+ time, e.g. monthly.
52
+
53
+ ## Location of the database (shared by all the packages)
54
+
55
+ The packages find the database without hardcoded paths, in this order:
56
+
57
+ 1. `$AERONET_OC_ROOT`;
58
+ 2. `root` in `~/.config/aeronet_oc_db/config.toml` (also read by Jupyter, PyCharm and cron, which do not
59
+ always inherit the shell environment):
60
+ ```toml
61
+ root = "/DATA/AERONET/OCv3"
62
+ ```
63
+ 3. `/DATA/AERONET/OCv3`.
64
+
65
+ ## Use from the other packages
66
+
67
+ `aeronet_oc_db` is the single access layer to the AERONET-OC data. Each package declares it as an
68
+ optional dependency (`aeronet` extra), imports it only in the functions that need it, and keeps a
69
+ fallback when it is missing (CI, users without the database):
70
+
71
+ | package | install | entry points |
72
+ |---|---|---|
73
+ | radcalnet_oc | `pip install radcalnet_oc[aeronet]` | `Aeronet().read_site(site, level)`, `Aeronet.open_site`, `Aeronet().aeronet_oc_site_info` |
74
+ | grstbx | `pip install grstbx[aeronet]` | `Data().read_aeronet_oc_site`, `Data.open_aeronet_oc`, `Data.aeronet_oc_sites` |
75
+ | invRrs | `pip install invRrs[aeronet]` | `aeronet_data_loading.read().read_site`, `read.open_site`, `read.sites` |
76
+ | hgrs | validation scripts | `validation/aeronet_oc/common.py` (`HGRS_VAL_AERONET` overrides the location) |
77
+ | aeronet_visu | | `aeronet_files_merger.py` |
78
+
79
+ Functions of `aeronet_oc_db` for the code of the packages:
80
+
81
+ ```python
82
+ import aeronet_oc_db
83
+ aeronet_oc_db.open_site('AAOT', 'lev20') # xarray.Dataset (time, wl), database names
84
+ aeronet_oc_db.open_site('AAOT', 'lev20', legacy_names=True) # names of the former netcdf/OCv3 files
85
+ aeronet_oc_db.raw_file('AAOT', 'lev20') # raw file, for the existing text readers
86
+ aeronet_oc_db.site_info() # location, Sentinel-2 tile, coverage per level
87
+ aeronet_oc_db.site_info(level='lev15') # columns of info_aeronet_oc_v15_location.csv
88
+ aeronet_oc_db.default_root() # location of the database
89
+ ```
90
+
91
+ `legacy_names=True` gives the variable names of the former `AERONET/netcdf/OCv3` conversion
92
+ (`Aerosol_Optical_Depth`, `Lwn_fQ`, `Rrs_Lwn*`, `'Total_Precipitable_Water(cm)'`, `wavelength` in um,
93
+ `SZA`, ...), so that existing code only changes the line that opens the data. New code should use the
94
+ database names.
95
+
96
+ The Sentinel-2 tile of each site comes from `aeronet_oc_db/data/site_s2_tile.csv` (checked by hand: the
97
+ stations in the overlap of two tiles, e.g. Venise and AAOT in 32TQR rather than 33TUL), or is computed
98
+ (MGRS 100 km square) for the new sites. Add a line to that file to force the tile of a site.
99
+
100
+ ## Layout
101
+
102
+ ```
103
+ OCv3/
104
+ <site>_OCv3.lev15, <site>_OCv3.lev20 raw files (legacy layout: header on line 8)
105
+ db/catalog.csv
106
+ db/netcdf/<level>/<site>_OCv3.<level>.nc
107
+ db/parquet/level=<level>/site=<site>/data.parquet
108
+ db/update.log
109
+ ```
110
+
111
+ ## Variables
112
+
113
+ | name | dims | units | AERONET field |
114
+ |---|---|---|---|
115
+ | `wl` | coord | nm | nominal band |
116
+ | `wl_exact` | time, wl | nm | `Exact_Wavelengths(um)` |
117
+ | `Lt`, `Lt_std`, `Lt_min_rel` | time, wl | uW cm-2 nm-1 sr-1 | `Lt_mean`, `Lt_stddev`, `Lt_min_rel` |
118
+ | `Li`, `Li_std` | time, wl | uW cm-2 nm-1 sr-1 | `Li_mean`, `Li_stddev` |
119
+ | `rho` | time, wl | 1 | `Rho` |
120
+ | `Lw`, `LwQ`, `Lwn`, `Lwn_fQ`, `Lwn_IOP` | time, wl | uW cm-2 nm-1 sr-1 | `Lw`, `LwQ`, `Lwn`, `Lwn_f/Q`, `Lwn_IOP` |
121
+ | `Rrs_Lwn`, `Rrs_Lwn_fQ`, `Rrs_Lwn_IOP` | time, wl | sr-1 | 10 Lwn / F0 (see below) |
122
+ | `aot`, `tau_rayleigh`, `tau_o3`, `tau_no2`, `tau_h2o` | time, wl | 1 | `*_Optical_Depth` |
123
+ | `sza_band`, `saa_band` | time, wl | degree | `Solar_Zenith_Angle`, `Solar_Azimuth_Angle` |
124
+ | `sza` | time | degree | mean of `sza_band` |
125
+ | `tco3`, `tno2` | time | DU | `Total_Ozone(Du)`, `Total_NO2(DU)` |
126
+ | `tcwv` | time | cm | `Total_Precipitable_Water(cm)` |
127
+ | `chl` | time | mg m-3 | `Chlorophyll-a` |
128
+ | `wind`, `pressure` | time | m s-1, hPa | `Wind_Speed(m/s)`, `Pressure(hPa)` |
129
+ | `raa_sea`, `vza_sea` | time | degree | `ASea(Degrees)`, `ZSea(Degrees)` |
130
+ | `instrument`, `quality_level`, `last_processed` | time | | instrument number, data level, processing date |
131
+ | `latitude`, `longitude`, `elevation`, `station_name` | scalar | | site |
132
+
133
+ `Rrs_* = 10 Lwn_* / F0(wl_exact)`. F0 is the Thuillier et al. (2003) spectrum averaged over a
134
+ Gaussian band of 10 nm FWHM centred on the exact wavelength, as in `hgrs/validation/aeronet_oc`.
135
+ The previous `AERONET/netcdf/OCv3` files used the 0.3 nm spectrum interpolated at the exact
136
+ wavelength, which gives up to ±4% differences at 412 and 443 nm because of the Fraunhofer lines.
137
+ Times are UTC.
138
+
139
+ ## Use in the validation
140
+
141
+ ```python
142
+ from aeronet_oc_db import Database
143
+ db = Database()
144
+
145
+ # one site (xarray)
146
+ ds = db.open('AAOT', 'lev20')
147
+ ds.Rrs_Lwn_fQ.sel(time='2023-07').plot.line(x='wl', add_legend=False)
148
+
149
+ # in situ data at satellite overpasses: median of the records within 1 h
150
+ mu = db.match('AAOT', overpass_times, level='lev20', max_lag='1h') # dims (match, wl)
151
+ mu.Rrs_Lwn_fQ, mu.aot, mu.n_records, mu.lag_min
152
+
153
+ # several sites, filtered at read time (pandas)
154
+ df = db.table('lev20', sites=['AAOT', 'Venise', 'Galata_Platform'], start='2018-01-01',
155
+ columns=['Rrs_Lwn_fQ', 'aot', 'sza', 'chl'], wl=[443, 490, 560, 665])
156
+
157
+ # sites with a long level 2.0 record
158
+ db.catalog.query("level == 'lev20' and n_records > 1000")
159
+ ```
160
+
161
+ The products can be read without this package:
162
+
163
+ ```python
164
+ import xarray as xr, pandas as pd
165
+ xr.open_dataset('/DATA/AERONET/OCv3/db/netcdf/lev20/AAOT_OCv3.lev20.nc')
166
+ pd.read_parquet('/DATA/AERONET/OCv3/db/parquet', filters=[('level', '==', 'lev20'), ('site', '==', 'AAOT')])
167
+ # duckdb: SELECT * FROM read_parquet('/DATA/AERONET/OCv3/db/parquet/*/*/*.parquet', hive_partitioning=true)
168
+ ```
169
+
170
+ ## Tests
171
+
172
+ ```bash
173
+ ~/anaconda3/envs/py12/bin/python -m pytest tests
174
+ ```
175
+
176
+ ## Releasing on PyPI
177
+
178
+ The workflow `.github/workflows/pypi.yml` builds the sdist and the wheel, checks them (`twine check`, version,
179
+ content), runs the tests on the installed wheel with Python 3.10 and 3.12, then publishes with PyPI trusted
180
+ publishing (no token stored).
181
+
182
+ One-time setup, on pypi.org and test.pypi.org (*Your projects > Publishing > Add a new pending publisher*):
183
+ owner `Tristanovsk`, repository `aeronet_oc_db`, workflow `pypi.yml`, environment `pypi` (resp.
184
+ `testpypi`). In the GitHub repository, create the environments `pypi` and `testpypi`
185
+ (*Settings > Environments*; a required reviewer on `pypi` adds a manual approval before each upload).
186
+
187
+ Release:
188
+
189
+ 1. set `__version__` in `aeronet_oc_db/__init__.py` (the only place, `pyproject.toml` reads it);
190
+ 2. *Actions > Publish on PyPI > Run workflow* with `testpypi`, then check
191
+ `pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ aeronet_oc_db`;
192
+ 3. tag and push: `git tag -a v<version> -m "aeronet_oc_db <version>" && git push origin v<version>`: the
193
+ workflow publishes on PyPI (the tag must match `__version__`).
194
+
195
+ Once on PyPI, `pip install radcalnet_oc[aeronet]` (or grstbx, invRrs) installs `aeronet_oc_db` with no
196
+ extra step.
197
+
198
+ ## Data policy
199
+
200
+ AERONET-OC data are public. Publications must acknowledge AERONET and the site PIs (the PI is
201
+ stored in the attributes of each file and in the catalog). See
202
+ https://aeronet.gsfc.nasa.gov/new_web/data_usage.html.
@@ -0,0 +1,31 @@
1
+ '''
2
+ AERONET-OC version 3 database: download and update of the raw files of the AERONET web service,
3
+ conversion into CF/ACDD netCDF-4 and Hive-partitioned Parquet, catalog and readers for the
4
+ validation of satellite products (grs, hgrs, grstbx, radcalnet_oc).
5
+ '''
6
+ __version__ = '1.2.1'
7
+
8
+ from .database import Database, DEFAULT_ROOT # noqa: E402,F401
9
+ from .raw import RawFile, parse # noqa: E402,F401
10
+ from .config import default_root # noqa: E402,F401
11
+
12
+
13
+ # shortcuts on the default database (location: see :mod:`aeronet_oc_db.config`)
14
+ def open_site(site, level='lev20', legacy_names=False, **kwargs):
15
+ '''netCDF dataset (time, wl) of a site, see :meth:`Database.open`'''
16
+ return Database().open(site, level, legacy_names=legacy_names, **kwargs)
17
+
18
+
19
+ def raw_file(site, level='lev20'):
20
+ '''path of the raw AERONET-OC file of a site (legacy text format)'''
21
+ return Database().raw_path(site, level)
22
+
23
+
24
+ def site_info(level=None):
25
+ '''one row per site: location, Sentinel-2 tile and coverage, see :meth:`Database.site_info`'''
26
+ return Database().site_info(level)
27
+
28
+
29
+ def catalog():
30
+ '''one row per site and level, see :attr:`Database.catalog`'''
31
+ return Database().catalog