Skip to content

Web-tiling step fails to convert raster to Python Imaging Library image #14

@julietcohen

Description

@julietcohen

While processing the Circum-Arctic permafrost and ground ice map, the web-tiling step failed with the error: cannot convert float NaN to integer. This occurred within viz-raster/pdgraster/WebImage.py, when we convert a raster to a Python Imaging Library image. Within to_image(), we create a no_data_mask that represents the values within the image data that have no data (0 in this case) and we replace all those values with np.nan. See the code here.

This issue is described in the layer issue in this comment.

This issue was resolved by adding a step within to_image() that converts image_data to float before we create the no_data_mask.

to_image()
    def to_image(self, image_data):
        """
            Create a PIL image from the pixel values.

            Parameters
            ----------
            pixel_values : pandas.DataFrame
                A dataframe with a pixel_row, pixel_col, and values column.

            Returns
            -------
            PIL.Image
                A PIL image.
        """

        min_val = self.min_val
        max_val = self.max_val
        nodata_val = self.nodata_val
        image_data = image_data.copy()
        rgba_list = self.rgba_list
        height = self.height
        width = self.width

        image_data = image_data.astype(float)
        no_data_mask = image_data == nodata_val

        # set the nodata value to np.nan
        if(len(no_data_mask)):
            image_data[no_data_mask] = np.nan
...

Since the solution has already been resolved, the purpose of creating this issue is to associate the bug with the viz-raster package and the branch to fix this bug. Here we can document if the added step has any unexpected consequences when processing other datasets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In Review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions