Skip to content

bug: raster_from_array() on a rotated modelgrid produces a raster with rotation in the opposite direction of modelgrid #2553

@jknightusgs

Description

@jknightusgs

Describe the bug
The raster_from_array() function results in a raster object that is rotated in the opposite direction of the modelgrid object that the function uses to generate the transform.

To Reproduce
Steps to reproduce the behavior:

  1. Produce a model with a structured grid rotated 47 degrees clockwise (angrot= -47)
  2. use raster_from_array() to export any model attribute (we used model top)

Expected behavior
exported raster should align with exported modelgrid shapefile. In our case it should be rotated 47 degrees clockwise.

Screenshots
having trouble uploading screenshots. will try to upload in a response to this post.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser Edge
  • Version Flopy 3.9.3

Additional context
I modified the function in flopy/utils/Raster.py to change the sign of the angrot variable it takes from the modelgrid object and provides to the Affine.rotation() function. This results in a raster that aligns with the modelgrid object.

        if angrot != 0:
             # transform *= Affine.rotation(angrot)
             transform *= Affine.rotation(-angrot)

This is puzzling though because the Affine.rotation() doc string specifies that the rotation angle should be negative for clockwise rotation, which is the same standard used by the modelgrid object.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions