From 1e82c86853fb012971d23fc852c9a49a2babd40f Mon Sep 17 00:00:00 2001 From: ckmah Date: Wed, 5 Jun 2024 14:42:29 -0700 Subject: [PATCH] fix upscale and shift shapes order of operations --- bento/tools/_flux.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bento/tools/_flux.py b/bento/tools/_flux.py index b8f88fe..f59969c 100644 --- a/bento/tools/_flux.py +++ b/bento/tools/_flux.py @@ -497,26 +497,23 @@ def fluxmap( columns=["fluxmap"], ) - # Add back offsets - shapes["geometry"] = shapes["geometry"].translate(x_offset, y_offset) - # Remove background shape shapes["fluxmap"] = shapes["fluxmap"].astype(int) shapes = shapes[shapes["fluxmap"] != 0] # Group same fields as MultiPolygons shapes = shapes.dissolve("fluxmap")["geometry"] + + # Upscale to match original resolution, shift back to original coordinates + shapes = shapes.scale(xfact=1 / res, yfact=1 / res, origin=(0, 0)).translate( + x_offset, y_offset + ) + fluxmap_df[cell] = shapes fluxmap_df = pd.DataFrame.from_dict(fluxmap_df).T fluxmap_df.columns = "fluxmap" + fluxmap_df.columns.astype(str) - # Upscale to match original resolution - fluxmap_df = fluxmap_df.apply( - lambda col: gpd.GeoSeries(col).scale( - xfact=1 / res, yfact=1 / res, origin=(0, 0) - ) - ) pbar.update() pbar.set_description("Saving")