EarthLens#
The unified entry point (facade) for all data sources.
earthlens.earthlens.EarthLens
#
Facade that routes a download to the requested backend.
The class-level :attr:DataSources mapping resolves a string key
("chc", "amazon-s3", "ecmwf", or "gee" / its alias
"google-earth-engine") to the concrete
:class:AbstractDataSource subclass that owns the request shape,
authentication, and post-processing for that provider. Each
backend's SDK is an optional dependency, so :attr:DataSources
is a :class:_LazyRegistry: indexing it imports the backend on
demand and rewrites a missing SDK into a friendly
ImportError naming the extra to install
(e.g. pip install earthlens[ecmwf]).
Attributes:
| Name | Type | Description |
|---|---|---|
DataSources |
Class-level lazy registry of registered backends.
Keys are the user-facing names accepted by |
|
datasource |
Instance attribute set by :meth: |
Examples:
-
Inspect the registered backends:
- Asking for an unknown backend raises>>> from earthlens.earthlens import EarthLens >>> sorted(EarthLens.DataSources) ['amazon-s3', 'chc', 'chirps', 'cmems', 'ecmwf', 'gee', 'google-earth-engine']ValueError:
See Also
:class:earthlens.chc.CHIRPS: CHIRPS rainfall over FTP.
:class:earthlens.s3.S3: ERA5 on AWS public S3 bucket.
:class:earthlens.cmems.CMEMS: Copernicus Marine ocean
datasets via copernicusmarine.
:class:earthlens.ecmwf.ECMWF: ERA5 via the Copernicus
Climate Data Store (cdsapi).
:class:earthlens.gee.GEE: imagery from Google Earth Engine
(earthengine-api); keys "gee" / "google-earth-engine".
Source code in src/earthlens/earthlens.py
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 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 413 414 415 416 417 418 419 | |
__init__(variables, data_source='chc', temporal_resolution='daily', start=None, end=None, path='', lat_lim=None, lon_lim=None, fmt='%Y-%m-%d', **backend_kwargs)
#
Resolve the backend and construct it with the user's parameters.
Validates data_source against :attr:DataSources, fills in
whole-Earth defaults for missing lat_lim / lon_lim, and
instantiates the concrete backend bound to self.datasource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_source
|
str
|
Backend key — one of |
'chc'
|
temporal_resolution
|
str
|
|
'daily'
|
start
|
str | None
|
Inclusive start date as a string (parsed with
|
None
|
end
|
str | None
|
Inclusive end date as a string. Defaults to |
None
|
path
|
Path | str
|
Output directory. Created by the backend if it does not exist. Defaults to the current working directory. |
''
|
variables
|
dict[str, list[str]] | list[str]
|
Backend-specific variable specification. Shape depends on the backend:
Defaults to |
required |
lat_lim
|
list[float] | None
|
|
None
|
lon_lim
|
list[float] | None
|
|
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
**backend_kwargs
|
object
|
Extra keyword arguments forwarded
verbatim to the chosen backend's constructor — for
backend-specific options the facade does not name
explicitly (e.g. ECMWF's |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
AuthenticationError
|
If the backend cannot authenticate —
ECMWF (missing |
ImportError
|
If the chosen backend's optional SDK is not
installed (e.g. |
Examples:
-
The DataSources registry resolves the backend class before construction. Inspect what each key points to:
- An unknown>>> from earthlens.earthlens import EarthLens >>> EarthLens.DataSources["chc"].__name__ 'CHIRPS' >>> EarthLens.DataSources["chirps"].__name__ # alias 'CHIRPS' >>> EarthLens.DataSources["ecmwf"].__name__ 'ECMWF' >>> EarthLens.DataSources["gee"].__name__ 'GEE'data_sourceis rejected before any backend code runs:- Construct an ECMWF-backed facade. Marked>>> from earthlens.earthlens import EarthLens >>> EarthLens(variables=[], data_source="bogus") Traceback (most recent call last): ... ValueError: bogus not supported# doctest: +SKIPbecause it builds a real :class:cdsapi.Client, which requires~/.cdsapirc:>>> from earthlens.earthlens import EarthLens >>> earthlens = EarthLens( # doctest: +SKIP ... data_source="ecmwf", ... temporal_resolution="daily", ... start="2022-01-01", ... end="2022-01-01", ... variables={ ... "reanalysis-era5-single-levels": ["2m-temperature"], ... }, ... lat_lim=[4.0, 5.0], ... lon_lim=[-75.0, -74.0], ... path="examples/data/era5", ... )
See Also
:meth:download: Triggers the actual retrieval.
Source code in src/earthlens/earthlens.py
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 | |
download(progress_bar=True, aggregate=None, *args, **kwargs)
#
Delegate the download to the bound backend.
Forwards every argument verbatim to self.datasource.download.
Each backend's download accepts its own backend-specific
keyword arguments (for example, CHIRPS supports cores for
parallel FTP retrieval), so unrecognised kwargs propagate
through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Whether the backend should print a per-date
progress bar during the loop. Defaults to |
True
|
aggregate
|
AggregationConfig | None
|
Optional :class: |
None
|
*args
|
object
|
Forwarded positionally to |
()
|
**kwargs
|
object
|
Forwarded as keywords to |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Whatever the bound backend's |
Any
|
CHIRPS / S3 / ECMWF (they write files to |
Any
|
effect), or the list of written GeoTIFF paths / export |
Any
|
destination strings for the GEE backend. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
When the ECMWF backend cannot
authenticate against CDS (typically a missing
|
KeyError
|
When any backend receives an unknown variable code that the catalog cannot resolve. |
NotImplementedError
|
When |
Examples:
-
End-to-end CHIRPS download. Marked
# doctest: +SKIPbecause it makes a live FTP connection:- ECMWF download via the facade. Marked>>> from earthlens.earthlens import EarthLens >>> earthlens = EarthLens( # doctest: +SKIP ... data_source="chc", ... start="2009-01-01", ... end="2009-01-02", ... variables=["precipitation"], ... lat_lim=[4.19, 4.64], ... lon_lim=[-75.65, -74.73], ... path="examples/data/chirps", ... ) >>> earthlens.download() # doctest: +SKIP# doctest: +SKIPbecause CDS requires~/.cdsapircand the request blocks for minutes while the queue serves it:>>> from earthlens.earthlens import EarthLens >>> earthlens = EarthLens( # doctest: +SKIP ... data_source="ecmwf", ... start="2022-01-01", ... end="2022-01-01", ... variables={ ... "reanalysis-era5-single-levels": ["2m-temperature"], ... }, ... lat_lim=[4.0, 5.0], ... lon_lim=[-75.0, -74.0], ... path="examples/data/era5", ... ) >>> earthlens.download() # doctest: +SKIP
See Also
:meth:earthlens.chc.CHIRPS.download: CHIRPS
backend implementation, including the cores=
keyword for parallel retrieval.
:meth:earthlens.s3.S3.download: S3/ERA5 backend
implementation.
:meth:earthlens.ecmwf.ECMWF.download: ECMWF/CDS
backend implementation.
:meth:earthlens.gee.GEE.download: Google Earth Engine
backend implementation (export_via, the 32768-px
synchronous cap).
Source code in src/earthlens/earthlens.py
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 413 414 415 416 417 418 419 | |