- Home
- Documentation
- API reference
- Corrections
- hyperproc.correct.mcd43
hyperproc.correct.mcd43¶
Source-derived reference
Generated from the current hyperproc 0.1.2 checkout.
Implementation: hyperproc/correct/mcd43.py. Signatures, defaults, docstrings, and expandable source are extracted statically; the module is not imported or executed. Names beginning with _ are implementation details, not a stable public API.
Use the function signature as the authority for individual parameter defaults and return annotations. Original docstrings sometimes group parameter names or wrap return descriptions across lines; these descriptions are preserved rather than inferred or rewritten.
Exported entry points¶
| Importable name | Definition |
|---|---|
hyperproc.correct.mcd43.MODIS_BANDS |
hyperproc.correct.mcd43.MODIS_BANDS |
hyperproc.correct.mcd43.MODIS_RANGES |
hyperproc.correct.mcd43.MODIS_RANGES |
hyperproc.correct.mcd43.MODIS_CENTRES |
hyperproc.correct.mcd43.MODIS_CENTRES |
hyperproc.correct.mcd43.KERNELS |
hyperproc.correct.mcd43.KERNELS |
hyperproc.correct.mcd43.PARAM_BANDS |
hyperproc.correct.mcd43.PARAM_BANDS |
hyperproc.correct.mcd43.Params |
hyperproc.correct.mcd43.Params |
hyperproc.correct.mcd43.cache_dir |
hyperproc.correct.mcd43.cache_dir |
hyperproc.correct.mcd43.fetch |
hyperproc.correct.mcd43.fetch |
hyperproc.correct.mcd43.read |
hyperproc.correct.mcd43.read |
hyperproc.correct.mcd43.grid_for |
hyperproc.correct.mcd43.grid_for |
hyperproc.correct.mcd43.bounds_of |
hyperproc.correct.mcd43.bounds_of |
hyperproc.correct.mcd43.date_of |
hyperproc.correct.mcd43.date_of |
hyperproc.correct.mcd43.resolution_of |
hyperproc.correct.mcd43.resolution_of |
hyperproc.correct.mcd43.step_for |
hyperproc.correct.mcd43.step_for |
hyperproc.correct.mcd43.available |
hyperproc.correct.mcd43.available |
MODIS MCD43A1 BRDF model parameters, the input to satellite BRDF normalisation.
MCD43A1 is a daily product: for every 500 m cell it gives the three weights of
the RossThick-LiSparseReciprocal model (iso, vol, geo) for MODIS
bands 1-7, fitted to all cloud-free observations in a 16-day window centred on
the date. Those weights describe the shape of the surface reflectance as a
function of Sun and view angle, which is exactly what a single hyperspectral
scene cannot know about itself.
from hyperproc.correct import mcd43
p = mcd43.fetch(bounds=(-121.0, 34.0, -119.8, 35.1), date="2023-04-22",
out_dir="cache/mcd43")
par = p.sample(lon, lat) # (..., 7 MODIS bands, 3 kernels)
Sources¶
source="gee"
Google Earth Engine, collection MODIS/061/MCD43A1 (plus MCD43A2
for the per-band quality and snow flags). Needs earthengine-api and a
one-off earthengine authenticate; recent versions also need a Cloud
project (project= or $EARTHENGINE_PROJECT). Downloaded in tiles
through getDownloadURL so no other client library is required.
source="local"
A GeoTIFF written by an earlier fetch, or any 21-band stack whose band
descriptions are the MCD43A1 parameter names.
Resolution¶
MCD43A1 is a 500 m product, and 1/240 degree (about 464 m) is its native step.
fetch(res=None), the default, adapts to the image: it never asks for a grid
finer than native, because upsampling adds no information that bilinear
sampling at each pixel's own coordinates does not already give, and it asks for
a coarser grid when the image pixels are coarser, so that MODIS cells are
averaged over the footprint instead of point-sampled. PACE OCI is the case
that needs this: its 1.2 km pixels each cover about six MODIS cells, and a
bilinear sample of the four nearest ones would alias. The coarse grids stay
whole multiples of the native step, so an aggregation always covers whole
MODIS cells. :func:resolution_of reports what a dataset asks for.
The download is cached: the same bounds, date and resolution give the same
file name under $HYPERPROC_CACHE_DIR/mcd43 (or out_dir), and an
existing file is reused unless overwrite=True.
Fill values¶
Earth Engine delivers masked cells as zero, and zero is a legal parameter value, so the image is unmasked to the product's own fill (32767) before the download and only that value counts as "no data". Valid parameters are scaled by 0.001 into reflectance units.
MODIS_RANGES = {1: (620.0, 670.0), 2: (841.0, 876.0), 3: (459.0, 479.0), 4: (545.0, 565.0), 5: (1230.0, 1250.0), 6: (1628.0, 1652.0), 7: (2105.0, 2155.0)}
module-attribute
¶
MODIS_BANDS = tuple(sorted(MODIS_RANGES))
module-attribute
¶
MODIS_CENTRES = {b: 0.5 * (lo + hi) for b, (lo, hi) in MODIS_RANGES.items()}
module-attribute
¶
KERNELS = ('iso', 'vol', 'geo')
module-attribute
¶
PARAM_BANDS = [f'BRDF_Albedo_Parameters_Band{b}_{k}' for b in MODIS_BANDS for k in KERNELS]
module-attribute
¶
QA_BANDS = [f'BRDF_Albedo_Band_Quality_Band{b}' for b in MODIS_BANDS] + ['Snow_BRDF_Albedo']
module-attribute
¶
COLLECTION = 'MODIS/061/MCD43A1'
module-attribute
¶
QA_COLLECTION = 'MODIS/061/MCD43A2'
module-attribute
¶
SCALE = 0.001
module-attribute
¶
FILL = 32767
module-attribute
¶
QA_FILL = 255
module-attribute
¶
RES_DEG = 1.0 / 240.0
module-attribute
¶
TILE = 512
module-attribute
¶
Params
dataclass
¶
A window of MCD43A1 parameters on a geographic grid.
| ATTRIBUTE | DESCRIPTION |
|---|---|
values |
TYPE:
|
transform |
affine of the grid,
TYPE:
|
crs |
always
TYPE:
|
date |
the acquisition date actually used,
TYPE:
|
quality |
TYPE:
|
snow |
TYPE:
|
Source code in hyperproc/correct/mcd43.py
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 | |
values: np.ndarray
instance-attribute
¶
transform: tuple
instance-attribute
¶
crs: str = 'EPSG:4326'
class-attribute
instance-attribute
¶
date: str = ''
class-attribute
instance-attribute
¶
quality: np.ndarray | None = None
class-attribute
instance-attribute
¶
snow: np.ndarray | None = None
class-attribute
instance-attribute
¶
path: Path | None = None
class-attribute
instance-attribute
¶
attrs: dict = field(default_factory=dict)
class-attribute
instance-attribute
¶
shape: tuple
property
¶
__init__(values: np.ndarray, transform: tuple, crs: str = 'EPSG:4326', date: str = '', quality: np.ndarray | None = None, snow: np.ndarray | None = None, path: Path | None = None, attrs: dict = dict()) -> None
¶
coverage() -> float
¶
masked(qa_max: int | None = 3, snow: bool = True) -> 'Params'
¶
A copy with low-quality and (optionally) snow-covered cells set to NaN.
| PARAMETER | DESCRIPTION |
|---|---|
qa_max
|
keep cells whose band quality is <= this. The default 3 keeps every retrieval, including magnitude inversions. That is deliberate: a magnitude inversion scales an archetype shape to the observed brightness, and a common factor on all three weights cancels in the c-factor ratio, so it costs far less here than it would in an albedo. Dropping them instead leaves holes that make neighbouring pixels inconsistent. Pass 1 for full inversions only; None keeps every cell including fill.
TYPE:
|
snow
|
drop cells flagged as snow-covered. A snow BRDF is a real measurement, but the surface it describes is usually gone by the time a different sensor sees it.
TYPE:
|
Source code in hyperproc/correct/mcd43.py
rowcol(lon, lat) -> tuple
¶
Fractional row/column of lon/lat in this grid, cell centres at .0.
Source code in hyperproc/correct/mcd43.py
sample(lon, lat, method: str = 'bilinear') -> np.ndarray
¶
Parameters at scattered points, shape lon.shape + (7, 3).
Sampling the parameters (rather than warping them to the image grid and reading back) keeps one code path for projected images and for swaths, where every pixel has its own longitude and latitude.
NaN cells are skipped and the remaining bilinear weights renormalised, so a point next to a gap still gets a value; a point whose four neighbours are all fill comes back NaN.
Source code in hyperproc/correct/mcd43.py
to_geotiff(path) -> Path
¶
Write the stack back out (21 parameter bands, then quality and snow).
Source code in hyperproc/correct/mcd43.py
cache_dir() -> Path
¶
read(path) -> Params
¶
Read a parameter stack written by :meth:Params.to_geotiff (or an equivalent).
Source code in hyperproc/correct/mcd43.py
bounds_of(ds) -> tuple
¶
Geographic bounds (w, s, e, n) of a hyperproc dataset, in degrees.
Uses the per-pixel lon/lat layers when the dataset has them (swath
grids), otherwise the map grid, reprojected to EPSG:4326 if needed.
Source code in hyperproc/correct/mcd43.py
date_of(source) -> str
¶
The acquisition date as YYYY-MM-DD.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
an open dataset, or a granule path or file name. A dataset's
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
nothing in the name or the attributes looks like a date. |
Source code in hyperproc/correct/mcd43.py
available(date: str, days: int = 0, collection: str = COLLECTION, project: str | None = None) -> str
¶
The date of the nearest MCD43A1 image within days of date.
A one-call connectivity and coverage check: it proves Earth Engine is reachable and that the scene's own date has a granule, without downloading anything.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
no image in the window (or Earth Engine is unreachable). |
Source code in hyperproc/correct/mcd43.py
resolution_of(ds) -> float
¶
The dataset's ground sample distance, in degrees.
Read from the map grid's own coordinates where there is one (converted
from metres for a projected CRS), otherwise from the spacing of the
per-pixel lon/lat layers of a swath. The larger of the two axes
wins, so the answer is never finer than the image really is.
Source code in hyperproc/correct/mcd43.py
step_for(ds=None, res: float | None = None) -> tuple
¶
Resolve the MODIS grid step to use, as (res, k).
k is how many native MODIS cells go into one output cell, so k = 1
means the product's own grid and k > 1 means an aggregation.
Source code in hyperproc/correct/mcd43.py
grid_for(bounds, res: float = RES_DEG, pad: float = 0.05) -> tuple
¶
Snap (w, s, e, n) outward onto a global res-degree grid.
Returns (transform, nx, ny). Snapping means two scenes that overlap ask
for the same cells, so the cache is shared and there is no half-pixel shift
between them.
Source code in hyperproc/correct/mcd43.py
_init_ee(project: str | None = None)
¶
Source code in hyperproc/correct/mcd43.py
_ee_image(ee, collection: str, bands: list, date: str, days: int)
¶
The image for date, or the nearest one within +/- days.
Source code in hyperproc/correct/mcd43.py
_aggregate(ee, img, k: int, transform: tuple, reducer: str = 'mean')
¶
Average k x k native MODIS cells into one output cell.
Done on the masked image, so cells with no retrieval never contribute to the mean; the caller unmasks to the fill value afterwards. Point-sampling a 500 m field at kilometre spacing would alias instead, which is why this exists at all (PACE OCI is the sensor that needs it).
Source code in hyperproc/correct/mcd43.py
_download(ee, img, bands: list, transform: tuple, nx: int, ny: int, fill: int, tile: int = TILE, verbose: bool = True, retries: int = 4) -> np.ndarray
¶
Pull a pinned grid out of Earth Engine, tile by tile, as (ny, nx, nband).
Source code in hyperproc/correct/mcd43.py
fetch(bounds=None, date: str | None = None, out_dir=None, *, ds=None, source: str = 'gee', res: float | None = None, pad: float = 0.05, days: int = 8, quality: bool = True, project: str | None = None, overwrite: bool = False, tile: int = TILE, verbose: bool = True) -> Params
¶
MCD43A1 parameters covering bounds on date, downloaded once and cached.
| PARAMETER | DESCRIPTION |
|---|---|
bounds
|
DEFAULT:
|
date
|
TYPE:
|
out_dir
|
where the GeoTIFF goes; default
DEFAULT:
|
ds
|
a hyperproc dataset to read the footprint and date from.
DEFAULT:
|
source
|
TYPE:
|
res
|
grid step in degrees. The default None adapts to
TYPE:
|
pad
|
degrees added around the footprint so bilinear sampling has neighbours at the edge.
TYPE:
|
days
|
how far to look for a granule if the exact date is missing.
TYPE:
|
quality
|
also fetch the MCD43A2 per-band quality and snow flags.
TYPE:
|
project
|
Earth Engine Cloud project.
TYPE:
|
overwrite
|
re-download even if the cached file exists.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Params
|
class: |
Source code in hyperproc/correct/mcd43.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |