Extents and warnings#
The frozen pydantic value objects that describe where and when a request covers. A backend's _create_grid()
returns a SpatialExtent and its _check_input_dates() returns a TemporalExtent; the base class captures them
into self.space and self.time.
These are values, not dicts — they are immutable, and SpatialExtent is comparable and hashable.
TemporalExtent is neither, because its dates field holds a DatetimeIndex. hash() always raises
TypeError. == is worse than simply failing: it returns True when both extents share the same
dates object, and raises ValueError ("truth value of an array ... is ambiguous") when they hold
equal-but-distinct ones — so it appears to work until it doesn't. Compare the scalar fields
(start_date, end_date, resolution) rather than the object.
SpatialExtent#
earthlens.base.SpatialExtent
#
Bases: BaseModel
Geographic bounding box (WGS84) for a download request.
Backend-agnostic. Coordinates are in degrees:
- latitude in
[-90, 90](south negative, north positive) - longitude in
[-180, 180](west negative, east positive)
Each concrete data source converts this to whatever format its
protocol expects (CDS: [north, west, south, east]; CHIRPS:
per-row clipping; S3: prefix filter; GEE:
ee.Geometry.Rectangle(west, south, east, north)). For
projected coordinates, define a separate ProjectedExtent
type — do not reuse this one with metric values.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude_min |
float
|
Inclusive south edge of the bbox, in degrees. |
latitude_max |
float
|
Inclusive north edge of the bbox, in degrees. |
longitude_min |
float
|
Inclusive west edge of the bbox, in degrees. |
longitude_max |
float
|
Inclusive east edge of the bbox, in degrees. |
resolution |
float | None
|
Grid cell size in degrees, applied to both
latitude and longitude. |
Source code in libs/core/src/earthlens/base/abstractdatasource.py
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 420 421 422 423 424 425 426 427 428 429 430 | |
east
property
#
Eastern edge of the bbox (== longitude_max).
north
property
#
Northern edge of the bbox (== latitude_max).
south
property
#
Southern edge of the bbox (== latitude_min).
west
property
#
Western edge of the bbox (== longitude_min).
__eq__(other)
#
Compare two extents by bbox + resolution, ignoring geometry.
Overrides pydantic's field-wise equality, which would otherwise
evaluate GeoDataFrame == GeoDataFrame (a non-boolean pandas
result) and raise for a polygon-aoi= extent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
and resolution; |
Source code in libs/core/src/earthlens/base/abstractdatasource.py
estimate_pixel_dims(scale_m)
#
Return (width_px, height_px) of this bbox sampled at scale_m metres.
Thin wrapper over :func:earthlens.base.spatial.estimate_pixel_dims
so every backend can pre-flight a request size without reaching
into another subpackage. Useful e.g. for GEE's 32768-px
synchronous-export cap or for any "will this download blow up?"
check before queuing a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale_m
|
float
|
Output pixel size in metres. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/core/src/earthlens/base/abstractdatasource.py
from_pairs(lat_lim, lon_lim, resolution=None)
classmethod
#
Build from the legacy [min, max] pair shape.
:class:AbstractDataSource.__init__ accepts lat_lim /
lon_lim as constructor kwargs in the public API; this
classmethod adapts that shape to the four named fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
resolution
|
float | None
|
Grid cell size in degrees. Defaults to
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SpatialExtent |
SpatialExtent
|
A validated, frozen instance. |
Source code in libs/core/src/earthlens/base/abstractdatasource.py
TemporalExtent#
earthlens.base.TemporalExtent
#
Bases: BaseModel
Per-instance temporal context produced by :meth:check_input_dates.
Replaces the self.time dict that earlier versions of
:class:AbstractDataSource accepted from subclass overrides. The
frozen pydantic model enforces presence of every consumer-visible
field at construction time, so a subclass that returns a malformed
container fails fast instead of surfacing as KeyError deep
inside the download loop.
Attributes:
| Name | Type | Description |
|---|---|---|
start_date |
Any
|
Inclusive start of the requested window. Typed
:data: |
end_date |
Any
|
Inclusive end of the requested window. |
resolution |
str
|
Spacing between consecutive entries in
:attr: |
dates |
Any
|
The :class: |
Source code in libs/core/src/earthlens/base/abstractdatasource.py
PolygonAoiWarning#
Raised as a warning when a polygon aoi= is reduced to its bounding box because the chosen backend cannot clip to
a polygon. Backends advertise the capability through SUPPORTS_POLYGON_AOI — see
Base contracts.
earthlens.base.PolygonAoiWarning
#
Bases: UserWarning
A polygon aoi= was reduced to its bounding box by the chosen backend.
Issued when a request passes a real polygon area of
interest to a backend whose SUPPORTS_POLYGON_AOI is False. The
download still succeeds, but it covers the polygon's bounding box, so
cells outside the polygon are included. That is the most dangerous kind of
wrong result — a valid raster of the right variable over roughly the right
area — so it is surfaced rather than left silent.
A dedicated class (rather than a bare UserWarning) so callers can filter
or escalate exactly this case:
Examples:
- Turn the silent degradation into an error for a strict pipeline:
- It is a
UserWarning, so existing broad filters still catch it: