# minimal planetscope cfg: map analytic SR to rgbnir and include udm2 if present
def make_ps_cfg(collection_id: str) -> dict:
return {
collection_id: {
"assets": {
r"regex:(?i).*AnalyticMS_SR.*\.tif$": {
"bands": {
"blue": {"band": 1, "nodata": 0},
"green": {"band": 2, "nodata": 0},
"red": {"band": 3, "nodata": 0},
"nir": {"band": 4, "nodata": 0},
}
},
# fallback: any GeoTIFF that is not a UDM2, map first 4 bands as RGBN
r"regex:(?i)^(?!.*udm).*\.tif$": {
"bands": {
"blue": {"band": 1, "nodata": 0},
"green": {"band": 2, "nodata": 0},
"red": {"band": 3, "nodata": 0},
"nir": {"band": 4, "nodata": 0},
}
},
r"regex:(?i).*udm2.*\.tif$": {
"bands": {
"udm2_clear": {"band": 1, "nodata": 0},
"udm2_snow": {"band": 2, "nodata": 0},
"udm2_shadow": {"band": 3, "nodata": 0},
"udm2_cloud": {"band": 6, "nodata": 0},
}
},
},
"default_measurements": ["red", "green", "blue", "nir"],
"default_crs": "EPSG:4326",
"default_resolution": [3, -3],
}
}
def fuse_first_nonzero(dst, src):
np.copyto(dst, src, where=(dst==0) & (src>0))
col_id = getattr(stac_items[0], "collection_id", None) or getattr(stac_items[0], "collection", None)
stac_cfg = make_ps_cfg(col_id)
xx = load(
stac_items,
bands=("red", "green", "blue"),
bbox=BBOX,
crs="EPSG:3857",
resolution=3,
groupby="solar_day",
chunks={}, # <-- use Dask
stac_cfg=stac_cfg,
fuse_func=fuse_first_nonzero
)
Thank you for your reply! The code above is how I have created a custom stac_cfg
and simple fuse function to create the mosaic policy. It did not make a difference, unfortunately. Below are the sample item JSON and the rio info respectively.
{
"type": "Feature",
"stac_version": "1.1.0",
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.1.0/schema.json",
"https://stac-extensions.github.io/projection/v2.0.0/schema.json"
],
"id": "20240921_074257_53_24a8",
"geometry": {
"type": "Polygon",
"coordinates": [
[
...
]
]
},
"bbox": [...],
"properties": {
"updated": "2024-09-25T16:32:13Z",
"created": "2024-09-21T14:19:09Z",
"gsd": 3.6,
"constellation": "planetscope",
"platform": "24a8",
"instruments": [
"PSB.SD"
],
"eo:cloud_cover": 34,
"view:off_nadir": 3.5,
"view:azimuth": 103.2,
"view:sun_azimuth": 147.2,
"view:sun_elevation": 41,
"pl:ground_control": true,
"pl:item_type": "PSScene",
"pl:pixel_resolution": 3,
"pl:publishing_stage": "finalized",
"pl:quality_category": "standard",
"pl:strip_id": "7591065",
"published": "2024-09-21T14:19:09Z",
"datetime": "2024-09-21T07:42:57.536745Z"
},
"links": [
{
"rel": "root",
"href": "s3://.../planet_labs/orders/catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "s3://.../planet_labs/orders/PSScene/PSScene_collection.json",
"type": "application/json"
},
{
"rel": "self",
"href": "s3://.../planet_labs/orders/004db224-bf6d-429c-a5ae-a0900ba0f5e0/PSScene/20240921_074257_53_24a8.json",
"type": "application/json"
},
{
"rel": "collection",
"href": "s3://.../planet_labs/orders/PSScene/PSScene_collection.json",
"type": "application/json"
}
],
"assets": {
"20240921_074257_53_24a8_metadata_json": {
"href": "s3://.../planet_labs/orders/004db224-bf6d-429c-a5ae-a0900ba0f5e0/PSScene/20240921_074257_53_24a8_metadata.json",
"type": "application/json",
"roles": [
"metadata"
]
},
"20240921_074257_53_24a8_3B_AnalyticMS_metadata_clip_xml": {
"href": "s3://.../planet_labs/orders/004db224-bf6d-429c-a5ae-a0900ba0f5e0/PSScene/20240921_074257_53_24a8_3B_AnalyticMS_metadata_clip.xml",
"type": "text/xml",
"pl:asset_type": "ortho_analytic_4b_xml",
"pl:bundle_type": "analytic_sr_udm2",
"roles": [
"metadata"
]
},
"20240921_074257_53_24a8_3B_AnalyticMS_SR_clip_file_format_tif": {
"href": "s3://.../planet_labs/orders/004db224-bf6d-429c-a5ae-a0900ba0f5e0/PSScene/20240921_074257_53_24a8_3B_AnalyticMS_SR_clip_file_format.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"pl:asset_type": "ortho_analytic_4b_sr",
"pl:bundle_type": "analytic_sr_udm2",
"raster:bands": [
{
"nodata": 0.0,
"data_type": "uint16",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 112.0,
"maximum": 8559.0
},
"scale": 0.0001
},
{
"nodata": 0.0,
"data_type": "uint16",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 137.0,
"maximum": 8894.0
},
"scale": 0.0001
},
{
"nodata": 0.0,
"data_type": "uint16",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 63.0,
"maximum": 9439.0
},
"scale": 0.0001
},
{
"nodata": 0.0,
"data_type": "uint16",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 28.0,
"maximum": 10115.0
},
"scale": 0.0001
}
],
"eo:bands": [
{
"name": "Blue",
"common_name": "blue",
"center_wavelength": 0.49,
"full_width_half_max": 0.05
},
{
"name": "Green",
"common_name": "green",
"center_wavelength": 0.565,
"full_width_half_max": 0.036
},
{
"name": "Red",
"common_name": "red",
"center_wavelength": 0.665,
"full_width_half_max": 0.03
},
{
"name": "Near-Infrared",
"common_name": "nir",
"center_wavelength": 0.865,
"full_width_half_max": 0.04
}
],
"proj:epsg": ...,
"proj:bbox": [
...
],
"proj:shape": [
...
],
"proj:transform": [
...
],
"roles": [
"data",
"reflectance"
]
},
"20240921_074257_53_24a8_3B_udm2_clip_file_format_tif": {
"href": "s3://.../planet_labs/orders/004db224-bf6d-429c-a5ae-a0900ba0f5e0/PSScene/20240921_074257_53_24a8_3B_udm2_clip_file_format.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"pl:asset_type": "ortho_udm2",
"pl:bundle_type": "analytic_sr_udm2",
"raster:bands": [
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 1.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 0.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 1.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 1.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 0.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 1.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 99.0
}
},
{
"data_type": "uint8",
"spatial_resolution": 3.0,
"statistics": {
"minimum": 0.0,
"maximum": 2.0
}
}
],
"eo:bands": [
{
"name": "B1",
"description": "Clear map (0: not clear, 1: clear)"
},
{
"name": "B2",
"description": "Snow map (0: no snow or ice, 1: snow or ice)"
},
{
"name": "B3",
"description": "Shadow map (0: no shadow, 1: shadow)"
},
{
"name": "B4",
"description": "Light haze map (0: no light haze, 1: light haze)"
},
{
"name": "B5",
"description": "Heavy haze map (0: no heavy haze, 1: heavy haze)"
},
{
"name": "B6",
"description": "Cloud map (0: no cloud, 1: cloud)"
},
{
"name": "B7",
"description": "Confidence map (percentage value: per-pixel algorithmic confidence in classification)"
},
{
"name": "B8",
"description": "Unusable pixels"
}
],
"proj:epsg": ...,
"proj:bbox": [
...
],
"proj:shape": [
...
],
"proj:transform": [
...
],
"roles": [
"data",
"snow-ice",
"cloud",
"cloud-shadow"
]
}
},
"collection": "psscene"
}
{
"driver": "GTiff",
"dtype": "uint16",
"nodata": 0.0,
"width": 2149,
"height": 1572,
"count": 4,
"crs": "EPSG:...",
"transform": [
...
],
"blockxsize": 512,
"blockysize": 512,
"tiled": true,
"compress": "lzw",
"interleave": "pixel"
}