Skip to content

Commit

Permalink
fix upscale and shift shapes order of operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ckmah committed Jun 5, 2024
1 parent c1875ee commit 1e82c86
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions bento/tools/_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1e82c86

Please sign in to comment.