Sensor.Community — API reference#
Sensor.Community air-quality data source subpackage —
earthlens.sensor_community. Background, usage, and licence notes are
covered under the other pages in this section; this page is the rendered
API.
earthlens.sensor_community
#
Sensor.Community crowdsourced air-quality backend.
Returns readings from the Sensor.Community low-cost-sensor network as a
long-format pandas.DataFrame (one row per measurement), the same
tabular shape as earthlens.openaq.
This is a tabular backend: the result is per-row station observations,
not a gridded array, so SensorCommunity.OUTPUT_KIND is "tabular" and
the earthlens.earthlens.EarthLens facade rejects an aggregate=
argument for it.
The archive has one CSV per (sensor, day) but no bbox index, so the
backend discovers active sensors in the bbox via the live JSON API, then
fetches each discovered sensor's per-day archive CSV over the date range.
Historical coverage is therefore limited to sensors currently reporting
in the bbox. Readings are crowdsourced from low-cost sensors and licensed
under the ODbL; every download() emits a LicenseWarning.
Public surface (re-exported from this package):
SensorCommunity— the backend; instantiate with a date range, a bbox, andvariables=[pollutant, ...], then callSensorCommunity.download.Catalog— pydantic-backed loader for the bundledsensor_community_data_catalog.yamlpollutant dispatch table.Pollutant— one pollutant's dispatch row (name,column,sensor_types,units,display_name,group).LicenseWarning— emitted on everydownload()to flag the ODbL / low-cost-sensor quality caveat.CATALOG_PATH— path to the bundled pollutant YAML; monkey-patchable in tests.
Examples:
-
List the registered pollutants:
Catalog
#
Bases: AbstractCatalog
Pollutant catalog for the Sensor.Community backend.
Reads the bundled sensor_community_data_catalog.yaml (shipped as
package data) and exposes its pollutants: block as a map of
Pollutant rows. Instantiate with no arguments (Catalog());
model_post_init loads and validates the YAML in one pass.
Attributes:
| Name | Type | Description |
|---|---|---|
pollutants |
dict[str, Pollutant]
|
Map from the user-facing pollutant name to its
|
Examples:
- Resolve names to the union of serving sensor types and to CSV columns:
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
pollutants
property
#
The pollutant map — alias for the base datasets field.
Returns:
| Type | Description |
|---|---|
dict[str, Pollutant]
|
dict[str, Pollutant]: The same mapping stored in |
columns_for(names)
#
Return the CSV column -> pollutant name map for names.
Used at parse time to pull every requested pollutant's value out of one sensor CSV in a single pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
User-facing pollutant names to resolve. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: Each requested pollutant's CSV column mapped
to its name ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any name is unknown (via |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
get_catalog()
#
Return the pollutant map (satisfies the abstract contract).
Returns:
| Type | Description |
|---|---|
dict[str, Pollutant]
|
dict[str, Pollutant]: Same object as |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
get_pollutant(name)
#
Resolve a pollutant name to its Pollutant row.
Thin wrapper over the inherited get_dataset, which raises a
ValueError with a did-you-mean hint on an unknown name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A user-facing pollutant name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Pollutant |
Pollutant
|
The matching dispatch row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
load(catalog_path=None)
classmethod
#
Read the Sensor.Community pollutant catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the
module-level |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
sensor_types_for(names)
#
Return the union of serving sensor-type slugs for names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
User-facing pollutant names to resolve. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
set[str]: Every archive sensor-type slug whose CSV carries at least one of the requested pollutants. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any name is unknown (via |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
LicenseWarning
#
Bases: UserWarning
Warns that Sensor.Community data carries ODbL / quality obligations.
Sensor.Community measurements are crowdsourced from low-cost sensors
and licensed under the Open Database License (ODbL): redistribution
must keep the attribution and share-alike terms, and the readings are
not reference-grade. The backend emits this once per download() so a
downstream user is told rather than discovering it silently.
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
Pollutant
#
Bases: BaseModel
One Sensor.Community pollutant's dispatch row.
The user-facing name is the parent key in Catalog.pollutants and is
also stored on the row as name so a resolved Pollutant is
self-describing.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Short machine name ( |
column |
str
|
The CSV column this pollutant is read from ( |
sensor_types |
list[str]
|
Archive sensor-type slugs whose per-sensor CSV
carries |
units |
str
|
The reporting unit ( |
display_name |
str
|
Human-readable label for docs / plots ( |
group |
PollutantGroup
|
Coarse classification — |
Examples:
- Build a row directly:
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
SensorCommunity
#
Bases: AbstractDataSource
Sensor.Community air-quality backend (long-format tabular output).
Discovers active sensors in the request bbox via the live JSON API,
then fetches each sensor's per-day archive CSV over the date window,
returning a long-format pandas.DataFrame (one row per measurement).
There is no authentication — both hosts are public.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='raw', path=None, fmt='%Y-%m-%d', session=None, client=None, file_format='csv')
#
Initialise a Sensor.Community backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start of the observation window, as a string
parsed with |
required |
end
|
str
|
Inclusive end of the observation window. |
required |
variables
|
list[str]
|
List of pollutant names to fetch ( |
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Recorded for provenance; Sensor.Community
has no server-side rollup. Accepts |
'raw'
|
path
|
Path | str | None
|
Output directory for the written CSV / Parquet. Created by the parent class if absent. |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
session
|
Session | None
|
An existing |
None
|
client
|
SensorCommunityClient | None
|
A |
None
|
file_format
|
FileFormat
|
Output format — |
'csv'
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
download(progress_bar=True, limit=None)
#
Discover + fetch readings, write them to path, return the frame.
Emits a LicenseWarning (ODbL), runs the live-API discovery then
the per-sensor archive fetch under a tqdm bar, concatenates and
windows the readings to the exact date range, writes the
long-format result to path as CSV (or Parquet), and returns it.
An empty result returns — and writes — a schema-only DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Show the per-sensor |
True
|
limit
|
int | None
|
Cap on the total readings fetched, across every discovered
sensor. Applied as each sensor's frame arrives, so a sensor
past the cap never has its daily archive files downloaded.
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The long-format readings (schema columns,
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
earthlens.sensor_community.backend
#
Backend that fetches crowdsourced air-quality data from Sensor.Community.
SensorCommunity(AbstractDataSource) returns readings from the
Sensor.Community low-cost-sensor network as a long-format
pandas.DataFrame (one row per measurement), the same tabular shape as
earthlens.openaq.
This is a tabular backend: the result is per-row station observations,
not a gridded array, so OUTPUT_KIND = "tabular" and the
earthlens.earthlens.EarthLens facade rejects an aggregate= argument.
Transport (a search/fetch split, like OpenAQ). The archive has one CSV
per (sensor, day) but no bbox index, so _search first hits the live
JSON API (data.sensor.community) to discover which sensors are active
in the request bbox; _fetch then pulls each discovered sensor's
per-day archive CSV (archive.sensor.community) over the date range,
;-parses it, and extracts the requested pollutant columns. A missing
daily file is logged and skipped (never a silent gap). Because discovery
uses the live snapshot, historical coverage is limited to sensors
currently reporting in the bbox.
Data quality: readings are crowdsourced from low-cost sensors and
licensed under the ODbL; every download() emits a LicenseWarning.
Pollutant selection: variables is a list[str] of pollutant names
(["pm25"], ["pm25", "pm10"], ["temperature", "humidity"]), mapped
to CSV columns + serving sensor types via the bundled catalog.
SensorCommunity
#
Bases: AbstractDataSource
Sensor.Community air-quality backend (long-format tabular output).
Discovers active sensors in the request bbox via the live JSON API,
then fetches each sensor's per-day archive CSV over the date window,
returning a long-format pandas.DataFrame (one row per measurement).
There is no authentication — both hosts are public.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='raw', path=None, fmt='%Y-%m-%d', session=None, client=None, file_format='csv')
#
Initialise a Sensor.Community backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start of the observation window, as a string
parsed with |
required |
end
|
str
|
Inclusive end of the observation window. |
required |
variables
|
list[str]
|
List of pollutant names to fetch ( |
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Recorded for provenance; Sensor.Community
has no server-side rollup. Accepts |
'raw'
|
path
|
Path | str | None
|
Output directory for the written CSV / Parquet. Created by the parent class if absent. |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
session
|
Session | None
|
An existing |
None
|
client
|
SensorCommunityClient | None
|
A |
None
|
file_format
|
FileFormat
|
Output format — |
'csv'
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
download(progress_bar=True, limit=None)
#
Discover + fetch readings, write them to path, return the frame.
Emits a LicenseWarning (ODbL), runs the live-API discovery then
the per-sensor archive fetch under a tqdm bar, concatenates and
windows the readings to the exact date range, writes the
long-format result to path as CSV (or Parquet), and returns it.
An empty result returns — and writes — a schema-only DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Show the per-sensor |
True
|
limit
|
int | None
|
Cap on the total readings fetched, across every discovered
sensor. Applied as each sensor's frame arrives, so a sensor
past the cap never has its daily archive files downloaded.
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The long-format readings (schema columns,
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/backend.py
earthlens.sensor_community.catalog
#
Pollutant dispatch table for the Sensor.Community backend.
Sensor.Community archives one CSV per (sensor, day); each CSV's
measurement columns depend on the sensor type (particulate sensors
report P0/P1/P2, climate sensors report
temperature/humidity/pressure). Users pass earthlens pollutant
names in variables=[...]; this module maps each name to the CSV
column it lives in and the sensor_types (archive slugs) whose files
carry it.
Like the OpenAQ / AirNow / EEA provider tables it is deliberately tiny
and fixed, so there is no refresh / probe / audit tooling and no
tools/sensor_community/ directory; adding a pollutant later is a
hand-edit of one YAML row.
Catalog is a thin earthlens.base.AbstractCatalog subclass that loads
the bundled sensor_community_data_catalog.yaml and exposes each row as
a Pollutant. Resolve a single name with Catalog.get_pollutant
(raises with a did-you-mean hint on an unknown name), the union of the
sensor-type slugs for a list of names with Catalog.sensor_types_for,
or the column -> name reverse map for a list of names with
Catalog.columns_for. CATALOG_PATH is the path to the bundled YAML
and is monkey-patchable in tests.
Catalog
#
Bases: AbstractCatalog
Pollutant catalog for the Sensor.Community backend.
Reads the bundled sensor_community_data_catalog.yaml (shipped as
package data) and exposes its pollutants: block as a map of
Pollutant rows. Instantiate with no arguments (Catalog());
model_post_init loads and validates the YAML in one pass.
Attributes:
| Name | Type | Description |
|---|---|---|
pollutants |
dict[str, Pollutant]
|
Map from the user-facing pollutant name to its
|
Examples:
- Resolve names to the union of serving sensor types and to CSV columns:
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
pollutants
property
#
The pollutant map — alias for the base datasets field.
Returns:
| Type | Description |
|---|---|
dict[str, Pollutant]
|
dict[str, Pollutant]: The same mapping stored in |
columns_for(names)
#
Return the CSV column -> pollutant name map for names.
Used at parse time to pull every requested pollutant's value out of one sensor CSV in a single pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
User-facing pollutant names to resolve. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: Each requested pollutant's CSV column mapped
to its name ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any name is unknown (via |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
get_catalog()
#
Return the pollutant map (satisfies the abstract contract).
Returns:
| Type | Description |
|---|---|
dict[str, Pollutant]
|
dict[str, Pollutant]: Same object as |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
get_pollutant(name)
#
Resolve a pollutant name to its Pollutant row.
Thin wrapper over the inherited get_dataset, which raises a
ValueError with a did-you-mean hint on an unknown name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A user-facing pollutant name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Pollutant |
Pollutant
|
The matching dispatch row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
load(catalog_path=None)
classmethod
#
Read the Sensor.Community pollutant catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the
module-level |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
sensor_types_for(names)
#
Return the union of serving sensor-type slugs for names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
User-facing pollutant names to resolve. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
set[str]: Every archive sensor-type slug whose CSV carries at least one of the requested pollutants. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any name is unknown (via |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
Pollutant
#
Bases: BaseModel
One Sensor.Community pollutant's dispatch row.
The user-facing name is the parent key in Catalog.pollutants and is
also stored on the row as name so a resolved Pollutant is
self-describing.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Short machine name ( |
column |
str
|
The CSV column this pollutant is read from ( |
sensor_types |
list[str]
|
Archive sensor-type slugs whose per-sensor CSV
carries |
units |
str
|
The reporting unit ( |
display_name |
str
|
Human-readable label for docs / plots ( |
group |
PollutantGroup
|
Coarse classification — |
Examples:
- Build a row directly:
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/catalog.py
clear_catalog_cache()
#
Empty the module-level catalog parse cache (for tests that rewrite YAML).
earthlens.sensor_community._helpers
#
Client, parsing, and licence helpers for the Sensor.Community backend.
Sensor.Community exposes two hosts the backend needs:
- the live JSON API (
data.sensor.community) — the last ~5 minutes of every sensor globally, bbox-filterable, used to discover which sensors are active in the request bbox (the archive has no bbox index); - the archive (
archive.sensor.community) — one CSV per (sensor, day),<date>/<date>_<sensor_type>_sensor_<id>.csv,;-separated, used to fetch each discovered sensor's history over the date range.
SensorCommunityClient wraps an injectable requests.Session over both
hosts with 429/Retry-After back-off; a missing archive file (404)
returns None so the backend can log-and-skip without failing the whole
request. LicenseWarning flags the ODbL / crowdsourced-quality caveat.
LicenseWarning
#
Bases: UserWarning
Warns that Sensor.Community data carries ODbL / quality obligations.
Sensor.Community measurements are crowdsourced from low-cost sensors
and licensed under the Open Database License (ODbL): redistribution
must keep the attribution and share-alike terms, and the readings are
not reference-grade. The backend emits this once per download() so a
downstream user is told rather than discovering it silently.
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
SensorCommunityClient
#
Injectable client over the Sensor.Community live + archive hosts.
Delegates the transport (session, 429/Retry-After back-off) to
the shared earthlens.base.http.HttpClient, keeping only the
two-host request shaping: the live JSON snapshot and one per-sensor
archive CSV (404-tolerant).
Attributes:
| Name | Type | Description |
|---|---|---|
max_retries |
int
|
Maximum number of |
backoff_factor |
float
|
Base seconds for exponential back-off when no
|
timeout |
Timeout
|
Per-request timeout in seconds — a float or a |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
backoff_factor
property
#
Base seconds for exponential back-off (no Retry-After).
max_retries
property
#
Maximum 429 retries before the last error is raised.
timeout
property
#
Per-request timeout in seconds (a float or a (connect, read) pair).
__init__(*, session=None, max_retries=3, backoff_factor=1.0, timeout=60.0, sleep=time.sleep)
#
Build a client over both Sensor.Community hosts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session | None
|
An existing |
None
|
max_retries
|
int
|
Maximum |
3
|
backoff_factor
|
float
|
Base seconds for exponential back-off. |
1.0
|
timeout
|
Timeout
|
Per-request timeout in seconds — a float or a
|
60.0
|
sleep
|
Callable[[float], None]
|
The sleep function used between retries. Defaults to
|
sleep
|
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
archive_csv(date, sensor_type, sensor_id)
#
Fetch one per-sensor daily archive CSV, or None when absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
str
|
The archive day as |
required |
sensor_type
|
str
|
The archive sensor-type slug ( |
required |
sensor_id
|
str
|
The sensor's numeric id (as a string). |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The CSV text, or |
Raises:
| Type | Description |
|---|---|
HTTPError
|
On a non- |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
live_snapshot()
#
Fetch the live JSON API's last-~5-minute global sensor snapshot.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: The array of live measurement records
(each with |
Raises:
| Type | Description |
|---|---|
HTTPError
|
On a non- |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
empty_frame()
#
Return an empty DataFrame with the exact long-format schema.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Zero rows, |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
frame_from_csv(text, columns, units, default_sensor_type=None)
#
Reshape one per-sensor archive CSV into the backend's long schema.
For each requested pollutant whose CSV column is present, emits one
row per reading (station_id / sensor_type / lat / lon /
timestamp come from the CSV). Rows with a non-numeric value or
unparseable timestamp are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The |
required |
columns
|
dict[str, str]
|
CSV column -> pollutant name for the requested pollutants
( |
required |
units
|
dict[str, str]
|
Pollutant name -> reporting unit string. |
required |
default_sensor_type
|
str | None
|
The archive sensor-type slug known from
discovery, used for the |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The readings in the |
Source code in libs/providers/atmosphere/src/earthlens/sensor_community/_helpers.py
sensors_in_bbox(snapshot, lat_lim, lon_lim, wanted_types)
#
Filter a live snapshot to unique sensors in the bbox of wanted types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
list[dict[str, Any]]
|
The live JSON API records from |
required |
lat_lim
|
tuple[float, float]
|
|
required |
lon_lim
|
tuple[float, float]
|
|
required |
wanted_types
|
set[str]
|
Archive sensor-type slugs (lower-case) to keep. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: One entry per unique |