firms-client 0.1.0__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,202 @@
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 [yyyy] [name of copyright owner]
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.
202
+
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: firms-client
3
+ Version: 0.1.0
4
+ Summary: Client for NASA FIRMS active fires: open per-country archives, NRT area API, detection types
5
+ Keywords: firms,nasa,wildfire,active fire,hotspot,modis,viirs,remote sensing
6
+ Author: Giuseppe Zileni
7
+ Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: GIS
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: httpx>=0.27
20
+ Requires-Python: >=3.12
21
+ Project-URL: Homepage, https://github.com/agent-engineering-studio/firms-client
22
+ Project-URL: Issues, https://github.com/agent-engineering-studio/firms-client/issues
23
+ Project-URL: Changelog, https://github.com/agent-engineering-studio/firms-client/blob/main/CHANGELOG.md
24
+ Description-Content-Type: text/markdown
25
+
26
+ # firms-client
27
+
28
+ Async Python client for [NASA FIRMS](https://firms.modaps.eosdis.nasa.gov/)
29
+ active-fire detections (MODIS since 2000, VIIRS since 2012): the **open
30
+ per-country archives**, the near-real-time **area API**, and the parsing
31
+ that tells a vegetation fire from a steelworks.
32
+
33
+ [![ci](https://github.com/agent-engineering-studio/firms-client/actions/workflows/ci.yml/badge.svg)](https://github.com/agent-engineering-studio/firms-client/actions/workflows/ci.yml)
34
+ [![PyPI](https://img.shields.io/pypi/v/firms-client)](https://pypi.org/project/firms-client/)
35
+
36
+ One dependency: `httpx`.
37
+
38
+ ## Why a library
39
+
40
+ | You might think | What is true |
41
+ |---|---|
42
+ | the archive needs an Earthdata login and arrives by e-mail | yearly CSVs per country are **static and open**: no account, no key |
43
+ | every satellite has a country archive | `modis` (2000-) and `viirs-snpp` (2012-) do; `viirs-noaa20` / `noaa21` do not |
44
+ | high confidence means fire | a steelworks is hot for real and comes through at **high** confidence |
45
+ | a confidence filter is enough | only the `type` column says *what* burned: 0 vegetation, 1 volcano, 2 industry, 3 offshore |
46
+ | confidence is one format | MODIS writes a 0-100 percentage, VIIRS `l`/`n`/`h` or `low`/`nominal`/`high` |
47
+ | a missing year is an empty file | it is a 404 with a JSON body; an error with status 200 is caught too |
48
+ | a bad MAP_KEY returns JSON | it is HTTP **400** with plain text `Invalid MAP_KEY.` |
49
+
50
+ On Italy, about a quarter of the VIIRS detections are not vegetation fires.
51
+ Without `type == 0`, the most "burnt" square kilometre in the country was
52
+ the ILVA steelworks in Taranto, with 3,308 fire-days.
53
+
54
+ All checked against the live service on 3 November 2026.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ pip install firms-client
60
+ ```
61
+
62
+ ## Use
63
+
64
+ The yearly archive of a country, no key needed:
65
+
66
+ ```python
67
+ import asyncio
68
+ from collections import Counter
69
+
70
+ import httpx
71
+
72
+ from firms_client import ARCHIVE_PRODUCTS, fetch_archive, select
73
+
74
+
75
+ async def main() -> None:
76
+ async with httpx.AsyncClient(timeout=120) as client:
77
+ for product in ARCHIVE_PRODUCTS:
78
+ rows = await fetch_archive(client, product, 2025, "Italy")
79
+ if rows is None:
80
+ continue
81
+ fires = select(rows) # vegetation fires, nominal confidence or better
82
+ print(
83
+ product.slug,
84
+ len(rows),
85
+ "detections",
86
+ dict(sorted(Counter(r.detection_type for r in rows).items())),
87
+ "->",
88
+ len(fires),
89
+ "fires",
90
+ )
91
+
92
+
93
+ asyncio.run(main())
94
+ ```
95
+
96
+ ```
97
+ modis 5076 detections {0: 3414, 1: 21, 2: 1635, 3: 6} -> 3315 fires
98
+ viirs-snpp 23349 detections {0: 17533, 1: 633, 2: 4277, 3: 906} -> 14880 fires
99
+ ```
100
+
101
+ The archive runs up to the previous year or so; for recent days use the area
102
+ API with a free [MAP_KEY](https://firms.modaps.eosdis.nasa.gov/api/map_key/):
103
+
104
+ ```python
105
+ from firms_client import fetch_area, select
106
+
107
+ rows = await fetch_area(client, MAP_KEY, "VIIRS_SNPP_NRT", (6.0, 36.0, 19.0, 47.6), days=3)
108
+ fires = select(rows, min_frp_mw=1.0)
109
+ ```
110
+
111
+ ### Selecting fires
112
+
113
+ `select(rows, vegetation_only=True, min_confidence="nominal", min_confidence_pct=None, min_frp_mw=0.0)`:
114
+
115
+ - `vegetation_only` drops volcanoes, industry and offshore (`type` 1-3);
116
+ a row without `type` is kept, since it cannot be judged;
117
+ - VIIRS rows are judged on their level; MODIS percentages on
118
+ `min_confidence_pct` when given, otherwise mapped to levels with the
119
+ FIRMS guidance (below 30 low, 30-79 nominal, 80+ high);
120
+ - a missing confidence is kept: losing a real fire is worse than keeping a
121
+ doubtful pixel.
122
+
123
+ Two things no filter fixes: crop-residue burning is a real vegetation fire
124
+ (`type` 0), and FIRMS is presence-only, so no detection does not mean
125
+ nothing burnt.
126
+
127
+ ### Bring your own HTTP
128
+
129
+ `archive_url`, `area_url`, `is_hotspot_csv` and `parse_csv` are pure.
130
+
131
+ ## Data
132
+
133
+ FIRMS data are provided by NASA LANCE / FIRMS and are free to use; please
134
+ acknowledge "NASA FIRMS" in anything you publish. The test fixtures are a
135
+ few rows of the 2025 Italian archives.
136
+
137
+ Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
138
+ which uses the archives as the fire history of Italy and the area API as a
139
+ wildfire trigger.
140
+
141
+ ## Development
142
+
143
+ ```bash
144
+ uv sync
145
+ make check
146
+ ```
147
+
148
+ ## License
149
+
150
+ Code: [Apache-2.0](./LICENSE).
@@ -0,0 +1,125 @@
1
+ # firms-client
2
+
3
+ Async Python client for [NASA FIRMS](https://firms.modaps.eosdis.nasa.gov/)
4
+ active-fire detections (MODIS since 2000, VIIRS since 2012): the **open
5
+ per-country archives**, the near-real-time **area API**, and the parsing
6
+ that tells a vegetation fire from a steelworks.
7
+
8
+ [![ci](https://github.com/agent-engineering-studio/firms-client/actions/workflows/ci.yml/badge.svg)](https://github.com/agent-engineering-studio/firms-client/actions/workflows/ci.yml)
9
+ [![PyPI](https://img.shields.io/pypi/v/firms-client)](https://pypi.org/project/firms-client/)
10
+
11
+ One dependency: `httpx`.
12
+
13
+ ## Why a library
14
+
15
+ | You might think | What is true |
16
+ |---|---|
17
+ | the archive needs an Earthdata login and arrives by e-mail | yearly CSVs per country are **static and open**: no account, no key |
18
+ | every satellite has a country archive | `modis` (2000-) and `viirs-snpp` (2012-) do; `viirs-noaa20` / `noaa21` do not |
19
+ | high confidence means fire | a steelworks is hot for real and comes through at **high** confidence |
20
+ | a confidence filter is enough | only the `type` column says *what* burned: 0 vegetation, 1 volcano, 2 industry, 3 offshore |
21
+ | confidence is one format | MODIS writes a 0-100 percentage, VIIRS `l`/`n`/`h` or `low`/`nominal`/`high` |
22
+ | a missing year is an empty file | it is a 404 with a JSON body; an error with status 200 is caught too |
23
+ | a bad MAP_KEY returns JSON | it is HTTP **400** with plain text `Invalid MAP_KEY.` |
24
+
25
+ On Italy, about a quarter of the VIIRS detections are not vegetation fires.
26
+ Without `type == 0`, the most "burnt" square kilometre in the country was
27
+ the ILVA steelworks in Taranto, with 3,308 fire-days.
28
+
29
+ All checked against the live service on 3 November 2026.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pip install firms-client
35
+ ```
36
+
37
+ ## Use
38
+
39
+ The yearly archive of a country, no key needed:
40
+
41
+ ```python
42
+ import asyncio
43
+ from collections import Counter
44
+
45
+ import httpx
46
+
47
+ from firms_client import ARCHIVE_PRODUCTS, fetch_archive, select
48
+
49
+
50
+ async def main() -> None:
51
+ async with httpx.AsyncClient(timeout=120) as client:
52
+ for product in ARCHIVE_PRODUCTS:
53
+ rows = await fetch_archive(client, product, 2025, "Italy")
54
+ if rows is None:
55
+ continue
56
+ fires = select(rows) # vegetation fires, nominal confidence or better
57
+ print(
58
+ product.slug,
59
+ len(rows),
60
+ "detections",
61
+ dict(sorted(Counter(r.detection_type for r in rows).items())),
62
+ "->",
63
+ len(fires),
64
+ "fires",
65
+ )
66
+
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ ```
72
+ modis 5076 detections {0: 3414, 1: 21, 2: 1635, 3: 6} -> 3315 fires
73
+ viirs-snpp 23349 detections {0: 17533, 1: 633, 2: 4277, 3: 906} -> 14880 fires
74
+ ```
75
+
76
+ The archive runs up to the previous year or so; for recent days use the area
77
+ API with a free [MAP_KEY](https://firms.modaps.eosdis.nasa.gov/api/map_key/):
78
+
79
+ ```python
80
+ from firms_client import fetch_area, select
81
+
82
+ rows = await fetch_area(client, MAP_KEY, "VIIRS_SNPP_NRT", (6.0, 36.0, 19.0, 47.6), days=3)
83
+ fires = select(rows, min_frp_mw=1.0)
84
+ ```
85
+
86
+ ### Selecting fires
87
+
88
+ `select(rows, vegetation_only=True, min_confidence="nominal", min_confidence_pct=None, min_frp_mw=0.0)`:
89
+
90
+ - `vegetation_only` drops volcanoes, industry and offshore (`type` 1-3);
91
+ a row without `type` is kept, since it cannot be judged;
92
+ - VIIRS rows are judged on their level; MODIS percentages on
93
+ `min_confidence_pct` when given, otherwise mapped to levels with the
94
+ FIRMS guidance (below 30 low, 30-79 nominal, 80+ high);
95
+ - a missing confidence is kept: losing a real fire is worse than keeping a
96
+ doubtful pixel.
97
+
98
+ Two things no filter fixes: crop-residue burning is a real vegetation fire
99
+ (`type` 0), and FIRMS is presence-only, so no detection does not mean
100
+ nothing burnt.
101
+
102
+ ### Bring your own HTTP
103
+
104
+ `archive_url`, `area_url`, `is_hotspot_csv` and `parse_csv` are pure.
105
+
106
+ ## Data
107
+
108
+ FIRMS data are provided by NASA LANCE / FIRMS and are free to use; please
109
+ acknowledge "NASA FIRMS" in anything you publish. The test fixtures are a
110
+ few rows of the 2025 Italian archives.
111
+
112
+ Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
113
+ which uses the archives as the fire history of Italy and the area API as a
114
+ wildfire trigger.
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ uv sync
120
+ make check
121
+ ```
122
+
123
+ ## License
124
+
125
+ Code: [Apache-2.0](./LICENSE).
@@ -0,0 +1,98 @@
1
+ [project]
2
+ name = "firms-client"
3
+ version = "0.1.0"
4
+ description = "Client for NASA FIRMS active fires: open per-country archives, NRT area API, detection types"
5
+ readme = "README.md"
6
+ keywords = [
7
+ "firms",
8
+ "nasa",
9
+ "wildfire",
10
+ "active fire",
11
+ "hotspot",
12
+ "modis",
13
+ "viirs",
14
+ "remote sensing",
15
+ ]
16
+ requires-python = ">=3.12"
17
+ license = "Apache-2.0"
18
+ license-files = ["LICENSE"]
19
+ classifiers = [
20
+ "Development Status :: 4 - Beta",
21
+ "Intended Audience :: Science/Research",
22
+ "Topic :: Scientific/Engineering :: GIS",
23
+ "Framework :: AsyncIO",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Typing :: Typed",
29
+ ]
30
+ dependencies = ["httpx>=0.27"]
31
+
32
+ [[project.authors]]
33
+ name = "Giuseppe Zileni"
34
+ email = "giuseppe.zileni@gmail.com"
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/agent-engineering-studio/firms-client"
38
+ Issues = "https://github.com/agent-engineering-studio/firms-client/issues"
39
+ Changelog = "https://github.com/agent-engineering-studio/firms-client/blob/main/CHANGELOG.md"
40
+
41
+ [build-system]
42
+ requires = ["uv_build>=0.13.6,<0.14"]
43
+ build-backend = "uv_build"
44
+
45
+ [dependency-groups]
46
+ dev = [
47
+ "mypy>=1.13",
48
+ "pytest>=8.3",
49
+ "pytest-cov>=6.0",
50
+ "ruff>=0.8",
51
+ ]
52
+
53
+ [tool.ruff]
54
+ line-length = 100
55
+ target-version = "py312"
56
+
57
+ [tool.ruff.lint]
58
+ select = [
59
+ "E",
60
+ "F",
61
+ "W",
62
+ "I",
63
+ "N",
64
+ "UP",
65
+ "B",
66
+ "C4",
67
+ "SIM",
68
+ "ARG",
69
+ "PTH",
70
+ "RUF",
71
+ ]
72
+
73
+ [tool.ruff.lint.per-file-ignores]
74
+ "tests/**" = [
75
+ "ARG",
76
+ "B018",
77
+ ]
78
+
79
+ [tool.mypy]
80
+ strict = true
81
+ python_version = "3.12"
82
+ files = [
83
+ "src",
84
+ "tests",
85
+ ]
86
+ warn_unused_ignores = true
87
+ warn_redundant_casts = true
88
+
89
+ [tool.pytest.ini_options]
90
+ testpaths = ["tests"]
91
+ addopts = "--strict-markers"
92
+
93
+ [tool.coverage.run]
94
+ source = ["firms_client"]
95
+
96
+ [tool.coverage.report]
97
+ fail_under = 90
98
+ show_missing = true
@@ -0,0 +1,71 @@
1
+ [project]
2
+ name = "firms-client"
3
+ version = "0.1.0"
4
+ description = "Client for NASA FIRMS active fires: open per-country archives, NRT area API, detection types"
5
+ readme = "README.md"
6
+ keywords = ["firms", "nasa", "wildfire", "active fire", "hotspot", "modis", "viirs", "remote sensing"]
7
+ requires-python = ">=3.12"
8
+ license = "Apache-2.0"
9
+ license-files = ["LICENSE"]
10
+ authors = [
11
+ { name = "Giuseppe Zileni", email = "giuseppe.zileni@gmail.com" },
12
+ ]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Science/Research",
16
+ "Topic :: Scientific/Engineering :: GIS",
17
+ "Framework :: AsyncIO",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = [
25
+ "httpx>=0.27",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/agent-engineering-studio/firms-client"
30
+ Issues = "https://github.com/agent-engineering-studio/firms-client/issues"
31
+ Changelog = "https://github.com/agent-engineering-studio/firms-client/blob/main/CHANGELOG.md"
32
+
33
+ [build-system]
34
+ requires = ["uv_build>=0.13.6,<0.14"]
35
+ build-backend = "uv_build"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "mypy>=1.13",
40
+ "pytest>=8.3",
41
+ "pytest-cov>=6.0",
42
+ "ruff>=0.8",
43
+ ]
44
+
45
+ [tool.ruff]
46
+ line-length = 100
47
+ target-version = "py312"
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "ARG", "PTH", "RUF"]
51
+
52
+ [tool.ruff.lint.per-file-ignores]
53
+ "tests/**" = ["ARG", "B018"]
54
+
55
+ [tool.mypy]
56
+ strict = true
57
+ python_version = "3.12"
58
+ files = ["src", "tests"]
59
+ warn_unused_ignores = true
60
+ warn_redundant_casts = true
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
64
+ addopts = "--strict-markers"
65
+
66
+ [tool.coverage.run]
67
+ source = ["firms_client"]
68
+
69
+ [tool.coverage.report]
70
+ fail_under = 90
71
+ show_missing = true
@@ -0,0 +1,58 @@
1
+ """Client for NASA FIRMS active-fire detections."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ from firms_client.client import fetch_archive, fetch_archive_csv, fetch_area
6
+ from firms_client.errors import FirmsError
7
+ from firms_client.hotspots import (
8
+ ACTIVE_VOLCANO,
9
+ OFFSHORE,
10
+ STATIC_LAND_SOURCE,
11
+ VEGETATION_FIRE,
12
+ ConfidenceLevel,
13
+ Hotspot,
14
+ confidence_level,
15
+ is_hotspot_csv,
16
+ parse_csv,
17
+ select,
18
+ )
19
+ from firms_client.sources import (
20
+ ARCHIVE_PRODUCTS,
21
+ MODIS,
22
+ NRT_SOURCES,
23
+ VIIRS_SNPP,
24
+ ArchiveProduct,
25
+ BBox,
26
+ archive_url,
27
+ archive_years,
28
+ area_url,
29
+ )
30
+
31
+ __version__ = version("firms-client")
32
+
33
+ __all__ = [
34
+ "ACTIVE_VOLCANO",
35
+ "ARCHIVE_PRODUCTS",
36
+ "MODIS",
37
+ "NRT_SOURCES",
38
+ "OFFSHORE",
39
+ "STATIC_LAND_SOURCE",
40
+ "VEGETATION_FIRE",
41
+ "VIIRS_SNPP",
42
+ "ArchiveProduct",
43
+ "BBox",
44
+ "ConfidenceLevel",
45
+ "FirmsError",
46
+ "Hotspot",
47
+ "__version__",
48
+ "archive_url",
49
+ "archive_years",
50
+ "area_url",
51
+ "confidence_level",
52
+ "fetch_archive",
53
+ "fetch_archive_csv",
54
+ "fetch_area",
55
+ "is_hotspot_csv",
56
+ "parse_csv",
57
+ "select",
58
+ ]
@@ -0,0 +1,58 @@
1
+ """Async fetches over :mod:`firms_client.sources` and :mod:`firms_client.hotspots`.
2
+
3
+ They take your ``httpx.AsyncClient``: timeouts, retries and pooling stay
4
+ yours, and transport errors propagate.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from datetime import date
10
+ from typing import TYPE_CHECKING
11
+
12
+ from firms_client.errors import FirmsError
13
+ from firms_client.hotspots import Hotspot, is_hotspot_csv, parse_csv
14
+ from firms_client.sources import ArchiveProduct, BBox, archive_url, area_url
15
+
16
+ if TYPE_CHECKING:
17
+ import httpx
18
+
19
+
20
+ async def fetch_archive_csv(
21
+ client: httpx.AsyncClient, product: ArchiveProduct, year: int, country: str
22
+ ) -> str | None:
23
+ """The raw yearly CSV, or ``None`` when that year is not published."""
24
+ response = await client.get(archive_url(product, year, country))
25
+ if response.status_code == 404:
26
+ return None
27
+ response.raise_for_status()
28
+ if not is_hotspot_csv(response.text):
29
+ raise FirmsError(f"FIRMS archive did not return a CSV: {response.text[:200]!r}")
30
+ return response.text
31
+
32
+
33
+ async def fetch_archive(
34
+ client: httpx.AsyncClient, product: ArchiveProduct, year: int, country: str
35
+ ) -> list[Hotspot] | None:
36
+ """One year of a country's archive, parsed; ``None`` when not published."""
37
+ text = await fetch_archive_csv(client, product, year, country)
38
+ return parse_csv(text) if text is not None else None
39
+
40
+
41
+ async def fetch_area(
42
+ client: httpx.AsyncClient,
43
+ map_key: str,
44
+ source: str,
45
+ bbox: BBox,
46
+ *,
47
+ days: int = 1,
48
+ on_date: date | None = None,
49
+ ) -> list[Hotspot]:
50
+ """Detections of ``source`` over ``bbox``. A bad key or source raises :class:`FirmsError`."""
51
+ response = await client.get(area_url(map_key, source, bbox, days=days, on_date=on_date))
52
+ if response.status_code != 200 or not is_hotspot_csv(response.text):
53
+ if response.status_code == 200 and not response.text.strip():
54
+ return []
55
+ raise FirmsError(
56
+ f"FIRMS area API (HTTP {response.status_code}): {response.text[:200].strip()}"
57
+ )
58
+ return parse_csv(response.text)
@@ -0,0 +1,2 @@
1
+ class FirmsError(Exception):
2
+ """FIRMS answered, but not with a hotspot CSV (bad MAP_KEY, unknown source, …)."""
@@ -0,0 +1,194 @@
1
+ """FIRMS hotspot CSVs: parsing, confidence, and what the satellite saw.
2
+
3
+ The archives and the APIs share one CSV layout per instrument, with two
4
+ differences a parser has to absorb:
5
+
6
+ * **confidence** is a 0-100 percentage for MODIS and a level for VIIRS,
7
+ written ``l``/``n``/``h`` in some products and ``low``/``nominal``/``high``
8
+ in others;
9
+ * the 4 µm brightness is ``brightness`` for MODIS and ``bright_ti4`` for
10
+ VIIRS.
11
+
12
+ The column that matters most is ``type``: what the hotspot is.
13
+
14
+ ===== =================================================
15
+ ``0`` presumed vegetation fire
16
+ ``1`` active volcano
17
+ ``2`` other static land source (industry, gas flares)
18
+ ``3`` offshore
19
+ ===== =================================================
20
+
21
+ A confidence filter cannot do this job: a steelworks is genuinely hot and
22
+ comes through at **high** confidence. On the Italian archive about a quarter
23
+ of the VIIRS detections are not vegetation fires, and without ``type == 0``
24
+ the most "burnt" square kilometre in Italy was the ILVA steelworks in
25
+ Taranto, with 3,308 fire-days. Crop-residue burning is ``0`` too: it is a
26
+ real vegetation fire, and only land cover can set it apart.
27
+
28
+ FIRMS is presence-only: no hotspot does not mean nothing burnt.
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ import csv
34
+ import io
35
+ from collections.abc import Iterable
36
+ from dataclasses import dataclass
37
+ from datetime import date
38
+ from typing import Literal
39
+
40
+ ConfidenceLevel = Literal["low", "nominal", "high"]
41
+
42
+ VEGETATION_FIRE = 0
43
+ ACTIVE_VOLCANO = 1
44
+ STATIC_LAND_SOURCE = 2
45
+ OFFSHORE = 3
46
+
47
+ _LEVELS: dict[str, ConfidenceLevel] = {
48
+ "l": "low",
49
+ "low": "low",
50
+ "n": "nominal",
51
+ "nominal": "nominal",
52
+ "h": "high",
53
+ "high": "high",
54
+ }
55
+ _RANK: dict[ConfidenceLevel, int] = {"low": 0, "nominal": 1, "high": 2}
56
+
57
+
58
+ @dataclass(frozen=True, slots=True)
59
+ class Hotspot:
60
+ """One detection. ``acq_time`` is UTC ``HHMM`` as an integer (``126`` = 01:26)."""
61
+
62
+ latitude: float
63
+ longitude: float
64
+ acq_date: date
65
+ acq_time: int
66
+ confidence: str | None
67
+ frp_mw: float | None
68
+ brightness_k: float | None
69
+ daynight: str | None
70
+ satellite: str | None
71
+ instrument: str | None
72
+ detection_type: int | None
73
+
74
+ @property
75
+ def is_vegetation_fire(self) -> bool | None:
76
+ """``type == 0``; ``None`` when the row does not say."""
77
+ return None if self.detection_type is None else self.detection_type == VEGETATION_FIRE
78
+
79
+
80
+ def parse_csv(text: str) -> list[Hotspot]:
81
+ """Every well-formed row; rows without coordinates, date or time are skipped."""
82
+ out: list[Hotspot] = []
83
+ for raw in csv.DictReader(io.StringIO(text)):
84
+ row = {str(k).strip().lower(): (v or "").strip() for k, v in raw.items() if k}
85
+ lat, lon = _float(row.get("latitude")), _float(row.get("longitude"))
86
+ if lat is None or lon is None:
87
+ continue
88
+ try:
89
+ day = date.fromisoformat(row.get("acq_date", "")[:10])
90
+ hhmm = int(row.get("acq_time", ""))
91
+ except ValueError:
92
+ continue
93
+ if not 0 <= hhmm <= 2359:
94
+ continue
95
+ kind = _float(row.get("type"))
96
+ out.append(
97
+ Hotspot(
98
+ latitude=lat,
99
+ longitude=lon,
100
+ acq_date=day,
101
+ acq_time=hhmm,
102
+ confidence=row.get("confidence") or None,
103
+ frp_mw=_float(row.get("frp")),
104
+ brightness_k=_float(row.get("bright_ti4")) or _float(row.get("brightness")),
105
+ daynight=row.get("daynight") or None,
106
+ satellite=row.get("satellite") or None,
107
+ instrument=row.get("instrument") or None,
108
+ detection_type=int(kind) if kind is not None else None,
109
+ )
110
+ )
111
+ return out
112
+
113
+
114
+ def is_hotspot_csv(text: str) -> bool:
115
+ """True only for a real hotspot CSV: an error body may come with any status."""
116
+ head = text.lstrip()[:400].lower()
117
+ return "latitude" in head and "longitude" in head and "acq_date" in head
118
+
119
+
120
+ def confidence_level(
121
+ raw: str | None, *, nominal_from_pct: int = 30, high_from_pct: int = 80
122
+ ) -> ConfidenceLevel | None:
123
+ """A VIIRS level as is; a MODIS percentage mapped by the two thresholds.
124
+
125
+ The defaults follow the FIRMS MODIS guidance (below 30 low, 30-79
126
+ nominal, 80 and above high). ``None`` when the value is missing or
127
+ unreadable.
128
+ """
129
+ if raw is None or not raw.strip():
130
+ return None
131
+ token = raw.strip().lower()
132
+ if token in _LEVELS:
133
+ return _LEVELS[token]
134
+ try:
135
+ pct = float(token)
136
+ except ValueError:
137
+ return None
138
+ if pct >= high_from_pct:
139
+ return "high"
140
+ return "nominal" if pct >= nominal_from_pct else "low"
141
+
142
+
143
+ def select(
144
+ hotspots: Iterable[Hotspot],
145
+ *,
146
+ vegetation_only: bool = True,
147
+ min_confidence: ConfidenceLevel = "nominal",
148
+ min_confidence_pct: int | None = None,
149
+ min_frp_mw: float = 0.0,
150
+ ) -> list[Hotspot]:
151
+ """Keep the detections that look like fires.
152
+
153
+ * ``vegetation_only`` drops ``type`` 1-3 (volcanoes, industry, offshore);
154
+ a row without ``type`` is kept, since it cannot be judged;
155
+ * the confidence bar is ``min_confidence`` for VIIRS levels, and
156
+ ``min_confidence_pct`` for MODIS percentages when given (otherwise the
157
+ percentage is mapped with :func:`confidence_level`). A missing
158
+ confidence is kept: dropping a real fire is worse than keeping a
159
+ doubtful pixel;
160
+ * ``min_frp_mw`` drops weaker detections, and those without FRP, when
161
+ above zero.
162
+ """
163
+ out = []
164
+ for h in hotspots:
165
+ if vegetation_only and h.is_vegetation_fire is False:
166
+ continue
167
+ if not _confident(h.confidence, min_confidence, min_confidence_pct):
168
+ continue
169
+ if min_frp_mw > 0 and (h.frp_mw is None or h.frp_mw < min_frp_mw):
170
+ continue
171
+ out.append(h)
172
+ return out
173
+
174
+
175
+ def _confident(raw: str | None, minimum: ConfidenceLevel, min_pct: int | None) -> bool:
176
+ if raw is None or not raw.strip():
177
+ return True
178
+ token = raw.strip().lower()
179
+ if min_pct is not None and token not in _LEVELS:
180
+ try:
181
+ return float(token) >= min_pct
182
+ except ValueError:
183
+ return True
184
+ level = confidence_level(raw)
185
+ return level is None or _RANK[level] >= _RANK[minimum]
186
+
187
+
188
+ def _float(raw: str | None) -> float | None:
189
+ if raw is None or not raw.strip():
190
+ return None
191
+ try:
192
+ return float(raw)
193
+ except ValueError:
194
+ return None
File without changes
@@ -0,0 +1,66 @@
1
+ """Where FIRMS publishes hotspots, and what needs a key.
2
+
3
+ **Per-country archives, open.** The download portal asks for an Earthdata
4
+ login and delivers by e-mail, but FIRMS also serves static yearly CSVs per
5
+ country, with no account::
6
+
7
+ https://firms.modaps.eosdis.nasa.gov/data/country/{product}/{year}/{product}_{year}_{country}.csv
8
+
9
+ Checked on 2026-11-03 for Italy: ``modis`` from 2000 and ``viirs-snpp`` from
10
+ 2012, both up to 2025; ``viirs-noaa20`` and ``viirs-noaa21`` are not
11
+ published per country at all. A year not (yet) published answers 404 with a
12
+ JSON body. The archives are standard processing (SP) and carry ``type``.
13
+
14
+ **Area API, with a MAP_KEY.** Near-real-time detections over a bbox, free
15
+ key from https://firms.modaps.eosdis.nasa.gov/api/map_key/::
16
+
17
+ https://firms.modaps.eosdis.nasa.gov/api/area/csv/{MAP_KEY}/{SOURCE}/{w,s,e,n}/{days}[/{YYYY-MM-DD}]
18
+
19
+ A bad key or source is HTTP 400 with plain text (``Invalid MAP_KEY.``).
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from dataclasses import dataclass
25
+ from datetime import date
26
+
27
+ ARCHIVE_BASE = "https://firms.modaps.eosdis.nasa.gov/data/country"
28
+ AREA_API_BASE = "https://firms.modaps.eosdis.nasa.gov/api/area/csv"
29
+
30
+ #: Area API sources (``VIIRS_SNPP_NRT``, ``MODIS_SP``, …).
31
+ NRT_SOURCES = ("VIIRS_SNPP_NRT", "VIIRS_NOAA20_NRT", "VIIRS_NOAA21_NRT", "MODIS_NRT")
32
+
33
+ #: (west, south, east, north), degrees.
34
+ BBox = tuple[float, float, float, float]
35
+
36
+
37
+ @dataclass(frozen=True, slots=True)
38
+ class ArchiveProduct:
39
+ """A product published as per-country yearly archives."""
40
+
41
+ slug: str
42
+ first_year: int
43
+
44
+
45
+ MODIS = ArchiveProduct(slug="modis", first_year=2000)
46
+ VIIRS_SNPP = ArchiveProduct(slug="viirs-snpp", first_year=2012)
47
+ ARCHIVE_PRODUCTS = (MODIS, VIIRS_SNPP)
48
+
49
+
50
+ def archive_url(product: ArchiveProduct, year: int, country: str) -> str:
51
+ """The yearly CSV of ``country`` (English name, as FIRMS writes it: ``Italy``)."""
52
+ return f"{ARCHIVE_BASE}/{product.slug}/{year}/{product.slug}_{year}_{country}.csv"
53
+
54
+
55
+ def archive_years(product: ArchiveProduct, *, until: int) -> list[int]:
56
+ """The years worth asking for, from the product's first."""
57
+ return list(range(product.first_year, until + 1))
58
+
59
+
60
+ def area_url(
61
+ map_key: str, source: str, bbox: BBox, *, days: int = 1, on_date: date | None = None
62
+ ) -> str:
63
+ """The area API URL: ``days`` back from ``on_date`` (or from today)."""
64
+ area = ",".join(f"{c:g}" for c in bbox)
65
+ url = f"{AREA_API_BASE}/{map_key}/{source}/{area}/{days}"
66
+ return f"{url}/{on_date.isoformat()}" if on_date is not None else url