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

Parameter.spatial_extent throws AttributeError #676

Closed
Pratichhya opened this issue Dec 3, 2024 · 4 comments
Closed

Parameter.spatial_extent throws AttributeError #676

Pratichhya opened this issue Dec 3, 2024 · 4 comments

Comments

@Pratichhya
Copy link
Contributor

When using Paramtere.spatial_extent in a UDP:

spatial_extent = Parameter.spatial_extent(
        name="spatial_extent",
        description="Limits the data to process to the specified bounding box or polygons."
        )

It throws an error:

......... 
in load_collection
    if spatial_extent.schema.get("type") != "object":
       ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

Seems that schema for Parameter.spatial_extent indeed is a List and not a Dict: https://github.com/Open-EO/openeo-python-client/blob/master/openeo/api/process.py#L310

@HansVRP
Copy link
Contributor

HansVRP commented Dec 4, 2024

Could you share the code where you generate the UDP?

@soxofaan soxofaan added the bug label Dec 4, 2024
@soxofaan
Copy link
Member

soxofaan commented Dec 4, 2024

FYI: this problem can easily be reproduced from this test:

def test_build_parameterized_cube_basic(con100, recwarn):
layer = Parameter.string("layer", description="Collection Id")
dates = Parameter.string("dates", description="Temporal extent")
bbox = Parameter("bbox", schema="object", description="bbox")
cube = con100.load_collection(layer).filter_temporal(dates).filter_bbox(bbox)
assert cube.flat_graph() == {
"loadcollection1": {
"process_id": "load_collection",
"arguments": {"id": {"from_parameter": "layer"}, "temporal_extent": None, "spatial_extent": None},
},
"filtertemporal1": {
"process_id": "filter_temporal",
"arguments": {"data": {"from_node": "loadcollection1"}, "extent": {"from_parameter": "dates"}},
},
"filterbbox1": {
"process_id": "filter_bbox",
"arguments": {"data": {"from_node": "filtertemporal1"}, "extent": {"from_parameter": "bbox"}},
"result": True,
}
}
assert recwarn.list == []

change the bbox to Parameter.spatial_extent()

@Pratichhya
Copy link
Contributor Author

@soxofaan thank you.
@HansVRP , this was how my udp looked liked:

def generate():
    spatial_extent = Parameter.spatial_extent(
        name="spatial_extent", 
        description="Limits the data to process to the specified bounding box or polygons.\\n\\nFor raster data, the process loads the pixel into the data cube if the point at the pixel center intersects with the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC).\\nFor vector data, the process loads the geometry into the data cube if the geometry is fully within the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC). Empty geometries may only be in the data cube if no spatial extent has been provided.\\n\\nEmpty geometries are ignored.\\nSet this parameter to null to set no limit for the spatial extent."
        )
    
    temporal_extent = Parameter.temporal_interval(
        name="temporal_extent", 
        description="Temporal extent specified as two-element array with start and end date/date-time."
        )
    biopar_type = Parameter.string(
        name="biopar_type",
        description="BIOPAR type [FAPAR,LAI,FCOVER,CCC,CWC]",
        default="FAPAR",
        values=["FAPAR", "LAI", "FCOVER", "CCC", "CWC"],
    )

    cube = connection.load_collection(
        collection_id="SENTINEL2_L2A",
        bands=[
        "B03",
        "B04",
        "B08",
        "sunAzimuthAngles",
        "sunZenithAngles",
        "viewAzimuthMean",
        "viewZenithMean"
        ],
        temporal_extent=temporal_extent,
        spatial_extent=spatial_extent,
    )
    scl = connection.load_collection(
        collection_id="SENTINEL2_L2A",
        bands=["SCL"],
        temporal_extent=temporal_extent,
        spatial_extent=spatial_extent,
    )

    mask = scl.process("to_scl_dilation_mask", data=scl)
    cube = cube.mask(mask)

    udf = openeo.UDF.from_file(
        Path(__file__).parent / "biopar_udf.py",
        runtime="Python",
        context={"biopar_type": {"from_parameter": "biopar_type"}},
    )

    biopar = cube.reduce_dimension(
        dimension="bands",
        reducer=udf,
    )
    biopar = biopar.add_dimension("bands", label=biopar_type, type="bands")
    

    return build_process_dict(
        process_graph=cube,
        process_id="biopar",
        description=(Path(__file__).parent / "README.md").read_text(),
        parameters=[
            spatial_extent,
            temporal_extent,
            biopar_type,
        ]
    )


if __name__ == "__main__":
    print(json.dumps(generate(), indent=2))`

@soxofaan
Copy link
Member

soxofaan commented Dec 5, 2024

fixed with 179a852

@soxofaan soxofaan closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants