Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inversion of image outside of BBOX in STAC Browser #407

Open
Ruphai opened this issue Feb 19, 2024 · 8 comments
Open

Inversion of image outside of BBOX in STAC Browser #407

Ruphai opened this issue Feb 19, 2024 · 8 comments
Labels
bug Something isn't working mapping upstream
Milestone

Comments

@Ruphai
Copy link

Ruphai commented Feb 19, 2024

Issue

I currently have an collection uploaded to STAC Browser FastAPI here. The collection and corresponding items have been validated and show to work correctly and even loads into an xArray object using odc-stac. However, on STAC Browser, the visualization of the image is inverted outside of the bounding box, see sample images below. What do you suggest might be the cause of this inversion?

image

What the Original Collection looks like:

{
    "type": "Collection",
    "id": "CERRA_2m_temperature_2001",
    "stac_version": "1.0.0",
    "description": "The Copernicus European Regional ReAnalysis (CERRA) datasets provide spatially and         temporally consistent historical reconstructions of meteorological variables in the atmosphere         and at the surface. ",
    "links": [
        {
            "rel": "items",
            "href": "https://stac.eurac.edu/collection/CERRA_2m_temperature_2001/items",
            "type": "application/json"
        },
        {
            "rel": "parent",
            "href": "https://stac.eurac.edu",
            "type": "application/json"
        },
        {
            "rel": "self",
            "href": "https://stac.eurac.edu/collection/CERRA_2m_temperature_2001",
            "type": "application/json"
        },
        {
            "rel": "root",
            "href": "https://stac.eurac.edu",
            "type": "application/json"
        },
        {
            "rel": "license",
            "href": "https://cds.climate.copernicus.eu/api/v2/terms/static/licence-to-use-copernicus-products.pdf",
            "title": "License to use Copernicus Products"
        }
    ],
    "keywords": [
        "intertwin",
        "temperature",
        "cerra",
        "climate"
    ],
    "providers": [
        {
            "url": "https://cds.climate.copernicus.eu/cdsapp#!/dataset/10.24381/cds.622a565a",
            "name": "Copernicus",
            "roles": [
                "producer",
                "licensor"
            ]
        },
        {
            "url": "http://www.eurac.edu",
            "name": "Eurac EO",
            "roles": [
                "host"
            ]
        }
    ],
    "title": "CERRA sub-daily regional reanalysis data for the European Alps on single levels",
    "sci:citation": "Schimanke S., Ridal M., Le Moigne P., Berggren L., Und\u00e9n P., Randriamampianina R., Andrea U.,         Bazile E., Bertelsen A., Brousseau P., Dahlgren P., Edvinsson L., El Said A., Glinton M., Hopsch S.,         Isaksson L., Mladek R., Olsson E., Verrelle A., Wang Z.Q., (2021): CERRA sub-daily regional reanalysis         data for Europe on single levels from 1984 to present. Copernicus Climate Change Service (C3S) Climate         Data Store (CDS), DOI: 10.24381/cds.622a565a (Accessed on 15-02-2024)",
    "sci:doi": "https://doi.org/10.24381/cds.622a565a",
    "summaries": {
        "eo:bands": [
            {
                "name": "t2m"
            }
        ]
    },
    "stac_extensions": [
        "https://stac-extensions.github.io/projection/v1.1.0/schema.json",
        "https://stac-extensions.github.io/raster/v1.1.0/schema.json",
        "https://stac-extensions.github.io/eo/v1.1.0/schema.json",
        "https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
    ],
    "cube:dimensions": {
        "longitude": {
            "axis": "x",
            "type": "spatial",
            "extent": [
                5.084033,
                15.958283
            ],
            "reference_system": 4326
        },
        "latitude": {
            "axis": "y",
            "type": "spatial",
            "extent": [
                43.553066,
                50.064191
            ],
            "reference_system": 4326
        },
        "time": {
            "type": "temporal",
            "extent": [
                "2001-01-01T00:00:00.000000000",
                "2001-12-31T00:00:00.000000000"
            ]
        },
        "bands": {
            "type": "bands",
            "values": [
                "t2m"
            ]
        }
    },
    "extent": {
        "spatial": {
            "bbox": [
                [
                    5.050470499999999,
                    43.5195035,
                    15.9918455,
                    50.097753499999996
                ]
            ]
        },
        "temporal": {
            "interval": [
                [
                    "2001-01-01T00:00:00Z",
                    "2001-12-31T00:00:00Z"
                ]
            ]
        }
    },
    "license": "proprietary"
}

A sample item

{
    "type": "Feature",
    "stac_version": "1.0.0",
    "id": "20010101000000",
    "properties": {
        "datetime": "2001-01-01T00:00:00Z"
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [
                    5.050470499999999,
                    43.5195035
                ],
                [
                    15.9918455,
                    43.5195035
                ],
                [
                    15.9918455,
                    50.097753499999996
                ],
                [
                    5.050470499999999,
                    50.097753499999996
                ],
                [
                    5.050470499999999,
                    43.5195035
                ]
            ]
        ]
    },
    "links": [
        {
            "rel": "collection",
            "href": "https://stac.eurac.edu/collection/CERRA_2m_temperature_2001",
            "type": "application/json"
        },
        {
            "rel": "parent",
            "href": "https://stac.eurac.edu/collection/CERRA_2m_temperature_2001",
            "type": "application/json"
        },
        {
            "rel": "self",
            "href": "https://stac.eurac.edu/collection/CERRA_2m_temperature_2001/20010101000000",
            "type": "application/json"
        },
        {
            "rel": "root",
            "href": "https://stac.eurac.edu",
            "type": "application/json"
        }
    ],
    "assets": {
        "t2m": {
            "href": "https://eurac-eo.s3-eu-west-1.amazonaws.com/INTERTWIN/CERRA/t2m_20010101000000.tif",
            "type": "image/tiff; application=geotiff; profile=cloud-optimized",
            "proj:epsg": 4326,
            "proj:geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            5.050470499999999,
                            50.097753499999996
                        ],
                        [
                            15.9918455,
                            50.097753499999996
                        ],
                        [
                            15.9918455,
                            43.5195035
                        ],
                        [
                            5.050470499999999,
                            43.5195035
                        ],
                        [
                            5.050470499999999,
                            50.097753499999996
                        ]
                    ]
                ]
            },
            "proj:bbox": [
                5.050470499999999,
                50.097753499999996,
                15.9918455,
                43.5195035
            ],
            "proj:shape": [
                98,
                163
            ],
            "proj:transform": [
                0.067125,
                0.0,
                5.050470499999999,
                0.0,
                0.067125,
                43.5195035,
                0.0,
                0.0,
                1.0
            ],
            "proj:projjson": {
                "$schema": "https://proj.org/schemas/v0.4/projjson.schema.json",
                "type": "GeographicCRS",
                "name": "WGS 84",
                "datum": {
                    "type": "GeodeticReferenceFrame",
                    "name": "World Geodetic System 1984",
                    "ellipsoid": {
                        "name": "WGS 84",
                        "semi_major_axis": 6378137,
                        "inverse_flattening": 298.257223563
                    }
                },
                "coordinate_system": {
                    "subtype": "ellipsoidal",
                    "axis": [
                        {
                            "name": "Geodetic latitude",
                            "abbreviation": "Lat",
                            "direction": "north",
                            "unit": "degree"
                        },
                        {
                            "name": "Geodetic longitude",
                            "abbreviation": "Lon",
                            "direction": "east",
                            "unit": "degree"
                        }
                    ]
                },
                "id": {
                    "authority": "EPSG",
                    "code": 4326
                }
            },
            "raster:bands": [
                {
                    "data_type": "float32",
                    "scale": 1.0,
                    "offset": 0.0,
                    "sampling": "area",
                    "statistics": {
                        "mean": -1.6650447845458984,
                        "minimum": -21.023025512695312,
                        "maximum": 12.350738525390625,
                        "stddev": 5.345924377441406,
                        "valid_percent": 0.00626017278076875
                    },
                    "histogram": {
                        "count": 11,
                        "min": -21.023025512695312,
                        "max": 12.350738525390625,
                        "buckets": [
                            31,
                            128,
                            393,
                            1122,
                            3747,
                            3297,
                            3837,
                            1985,
                            833,
                            601
                        ]
                    }
                }
            ],
            "eo:bands": [
                {
                    "name": "t2m"
                }
            ]
        }
    },
    "bbox": [
        5.050470499999999,
        43.5195035,
        15.9918455,
        50.097753499999996
    ],
    "stac_extensions": [
        "https://stac-extensions.github.io/projection/v1.1.0/schema.json",
        "https://stac-extensions.github.io/raster/v1.1.0/schema.json",
        "https://stac-extensions.github.io/eo/v1.1.0/schema.json"
    ],
    "collection": "CERRA_2m_temperature_2001"
}

Possible cause

It seems this might be due to an inversion of the coords in the transformation matrix (especially in the Y axis)

A sample image

t2m_20010103000000.zip

@clausmichele
Copy link

@m-mohr It might be related to this: geotiffjs/geotiff.js#337

@m-mohr
Copy link
Collaborator

m-mohr commented Feb 22, 2024

Yes, might be. The first check should be whether the latest version of geotiff.js is used. I don't have th capacity to check this right now, but the fix must either be made in stac-layer or in geotiff.js anyway. Did you check whether this works correctly with ol-stac?

@m-mohr m-mohr added bug Something isn't working upstream labels Feb 22, 2024
@m-mohr m-mohr added this to the 3.3.0 milestone Mar 7, 2024
@m-mohr m-mohr modified the milestones: 3.3.0, 3.4.0 Sep 11, 2024
@m-mohr m-mohr added the mapping label Jan 7, 2025
@luipir
Copy link

luipir commented Jan 8, 2025

I've a similar but slightly different issue you can have a screenshot below where the image is translated and scaled not only flipped:
The image in the red circle
Screenshot from 2025-01-08 11-30-06
in a zoom is better visible the image:
Screenshot from 2025-01-08 11-33-05

The images is locally served, I double checked that stac item is correctly set in it's geometry and BBOX and it is correctly shown in QGIS or titiler viewer

I debugged vue stac-browser app and realised that StacLayer return a wrong BBOX in Map.vue that seems leading to the wrong transformation and scaling.

here the stac Item befor importin in the stac catalog
6018-lvl02-color.json.updated.json

and here the image (linked because if big) that I serve locally

note: checking with ol-stac if the issue is still present

@luipir
Copy link

luipir commented Jan 8, 2025

Seems ol-stac read correctly the extension but not do a correct render:
Screenshot from 2025-01-08 13-10-06

@m-mohr
Copy link
Collaborator

m-mohr commented Jan 8, 2025

Yes, that's also what I'm seing.

  • geotiff.js seems fine for now.
  • ol-stac seems to have issue rendering the bands correctly.
  • stac-layer seems to use a very outdated geotiff.js version and (through georaster-layer-for-leaflet, see https://github.com/GeoTIFF/georaster-layer-for-leaflet/issues) uses potentially a different projection methodology compared to ol-stac. So the issue might be sitting there, we had issues with it in the past.

Generally, the aim is to migrate to ol-stac soon, so it might not be worth the effort to invest into a fix in stac-layer right now. That means on the other hand that a fix may take a little longer.

@luipir
Copy link

luipir commented Jan 8, 2025

  • ol-stac seems to have issue rendering the bands correctly.

FYI this is the expected result (getting the raster served as COG and http loaded in qgis)

Screenshot from 2025-01-08 14-39-57

So, seems that the image in stac-browser has the correct 0 reference but 90 right had rotated and scaled respect that shown into #407 (comment)

@luipir
Copy link

luipir commented Jan 9, 2025

  • stac-layer seems to use a very outdated geotiff.js version and (through georaster-layer-for-leaflet, see https://github.com/GeoTIFF/georaster-layer-for-leaflet/issues) uses potentially a different projection methodology compared to ol-stac. So the issue might be sitting there, we had issues with it in the past.

just in case, testing with stac-layer@next instead of that packaged with 0.15.0

@m-mohr
Copy link
Collaborator

m-mohr commented Jan 9, 2025

@luipir I think that's a dead end. stac-layer@next primarily improved on the STAC side of things, not of the COG rendering. The issues come likely from georaster, which has open issues... For the meantime you could enable tilserver rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mapping upstream
Projects
None yet
Development

No branches or pull requests

4 participants