andremun / pyInstanceSpace

A Python version of the InstanceSpace analysis toolkit
1 stars 0 forks source link

save_graph and save_to_csv failing #195

Closed dhjang03 closed 1 month ago

dhjang03 commented 1 month ago

In the backend, after running the instance space and try to save the result I am encountering error message in the postman.

Code calling instance space from the backend

def run_instance_space(zip_filename: str, paths: Path) -> None:
    """TODO: Add a description here."""
    instance_space: InstanceSpace | None = instance_space_from_directory(paths)

    if instance_space is None:
        raise ValueError("Failed to load instance space")

    csv_path: Path = paths / "csv"
    web_path: Path = paths / "web"
    png_path: Path = paths / "png"
    mat_path: Path = paths / "mat"

    _validate_path([csv_path, web_path, png_path, mat_path])

    model: Model = instance_space.build()

    model.save_for_web(web_path)
    model.save_graphs(png_path)
    model.save_to_csv(csv_path)
    model.save_to_mat(mat_path)
    model.save_zip(zip_filename, paths)

for save_graphs, I am getting "MultiPolygon object has no attribute exterior"

for save_csv, saving summary from Trace, Pilot, and Pythia fails. I message I got from postman is as below:

Hazel-Yi commented 1 month ago

could u give us steps to regenerate the err?

dhjang03 commented 1 month ago

could u give us steps to regenerate the err?

under this branch clone the matilda

git clone <https or ssh for MT-Updating-Matilda>

and check out to development branch

cd MT-Updating-Matida
git checkout development

back to root folder of the project then run the backend

poetry install
poetry run fastapi dev app/main.py

Submit request via web or postman. I am current using following metadata and option. metadata.csv options.json

If you are using postman

dhjang03 commented 1 month ago

Tried #170, but it fails when processing Trace.

ybguzel commented 1 month ago

This is not due to the PR. This is a polygon class issue. In trace, the polygons that are generated can be disconnected ( imagine two squares next to each other.) they are both valid outputs. In matlab, the would jointly be counted as a single polygon. Meanwhile in python, they are referred to as multipolygon. (ie: a shape which consists of multiple polygons). This is a fairly common occurrence.

If you encounter a multipolygon, make sure to use multipolgyon.geoms to access individual shapes.

neatht commented 1 month ago

If you encounter a multipolygon, make sure to use multipolgyon.geoms to access individual shapes.

The graph serialiser needs the same fix you did to the CSV and web serializers in your initial Trace PR. Do you have time today to do that?

ybguzel commented 1 month ago

Not untill 5-6pm. I have classes till 2, and then we have the final presentation meeting. Then I have another meeting. I can have a look at it at around 5.30

neatht commented 1 month ago

@CZLam7 ?

CZLam7 commented 1 month ago

hey I'm working in 15 and I finish at 7

CZLam7 commented 1 month ago

I cn look into after work today

ybguzel commented 1 month ago

Try to implement the following solution


  if good is not None and good.polygon is not None:  # make sure that the footprint polygon is not none. (IT CAN BE AND THATS FINE)
            boundaries = np.empty((1, 2))
            if isinstance(good.polygon, Polygon):
                # Extract the boundary coordinates of a single Polygon
                x, y = good.polygon.exterior.xy
                boundary_coords = np.array([x, y]).T
                boundaries = np.concatenate((boundaries, boundary_coords))

            elif isinstance(good.polygon, MultiPolygon):
                # Extract the boundary coordinates of each Polygon in MultiPolygon
                for poly in good.polygon.geoms:
                    x, y = poly.exterior.xy
                    boundary_coords = np.array([x, y]).T
                    boundaries = np.concatenate((boundaries, boundary_coords))
CZLam7 commented 1 month ago

Hey so is it fixed by someone?

CZLam7 commented 1 month ago

Try to implement the following solution

  if good is not None and good.polygon is not None:  # make sure that the footprint polygon is not none. (IT CAN BE AND THATS FINE)
            boundaries = np.empty((1, 2))
            if isinstance(good.polygon, Polygon):
                # Extract the boundary coordinates of a single Polygon
                x, y = good.polygon.exterior.xy
                boundary_coords = np.array([x, y]).T
                boundaries = np.concatenate((boundaries, boundary_coords))

            elif isinstance(good.polygon, MultiPolygon):
                # Extract the boundary coordinates of each Polygon in MultiPolygon
                for poly in good.polygon.geoms:
                    x, y = poly.exterior.xy
                    boundary_coords = np.array([x, y]).T
                    boundaries = np.concatenate((boundaries, boundary_coords))

@ybguzel has this been added and are there still more issue?

dhjang03 commented 1 month ago

Hey so is it fixed by someone?

csv part is fixed

CZLam7 commented 1 month ago

So graph hasnt been solved ?

CZLam7 commented 1 month ago

@dhjang03 when u add the code Yusuf pointed out above, does it solve the issue?

dhjang03 commented 1 month ago

I am just trying this now. Took a while to locate the line that is actually causing the issue