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

Update conversion.py #87

Merged
merged 1 commit into from Mar 11, 2022
Merged

Update conversion.py #87

merged 1 commit into from Mar 11, 2022

Conversation

mmann1123
Copy link
Collaborator

Code
Current in conversion.py

def polygon_to_array(
        self,
        polygon,
        col=None,
        data=None,
        ...
        dtype="uint16",
        ):
 ....

 if col:
            shapes = (
                (geom, value) for geom, value in zip(dataframe.geometry, dataframe[col])
                )
            
 else:
            shapes = dataframe.geometry.values

 varray = rasterize(
                    shapes,
                    out_shape=(dst_height, dst_width),
                    transform=dst_transform,
                    fill=fill,
                    default_value=default_value,
                    all_touched=all_touched,
                    dtype=dtype,
                )

Problem

  • ml.fit_predict attempted to recast model predictions to unit16.
  • this throws type error in rasterizer when prediction can't be recast

Solution

  • If 'col' is included, use rasterio.dtypes.get_minimum_dtype to update dtype.
  • The proposed solution is tesed and works for continuous and int dtypes
if col:
            shapes = (
                (geom, value) for geom, value in zip(dataframe.geometry, dataframe[col])
            )
            dtype=get_minimum_dtype(dataframe[col])
            
 else:
            shapes = dataframe.geometry.values

 varray = rasterize(
                shapes,
                out_shape=(dst_height, dst_width),
                transform=dst_transform,
                fill=fill,
                default_value=default_value,
                all_touched=all_touched,
                dtype=dtype,
            )

**Code**
in `conversion.py`
``` python 
        if col:
            shapes = ((geom,value) for geom, value in zip(dataframe.geometry, dataframe[col]))
            dtype = get_minimum_dtype(dataframe[col])

        else: 
            shapes = dataframe.geometry.values
            
        varray = rasterize(shapes,
                           out_shape=(dst_height, dst_width),
                           transform=dst_transform,
                           fill=fill,
                           default_value=default_value,
                           all_touched=all_touched,
                           dtype=dtype)
```
@mmann1123 mmann1123 mentioned this pull request Mar 3, 2022
@mmann1123 mmann1123 requested a review from jgrss March 10, 2022 19:51
@mmann1123 mmann1123 added the bug Something isn't working label Mar 10, 2022
@mmann1123
Copy link
Collaborator Author

@jgrss I think this is good to merge

@jgrss jgrss merged commit 6927f13 into main Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants