Skip to content

Reduce / simplify ceremony to access ProjectedRasterTile in python #147

Closed

Description

@vpipkt

I commented in a PR about python TileUDT on the following code block there.

# rf_local_add(t, 0) is to force lazy eval; accessing tile.tile is to get at the actual Tile type vs PRT struct
df = self.spark.read.rastersource(self.img_uri).withColumn('tile2', rf_local_add_int(col('tile.tile'), 0))
# downstream we collect df in the python driver

The problem is that on the python side this rastersource tile column is actually a struct, so the user has to overcome the friction of use tile.tile to get the tile type.

The second challenge is the lazy evaluation. In the above snip if i did not add 0, I'd see the following error in the deserialize. Obviously we need to do some null checking but better would be a mechanism for the python side to request the evaluation of the cell values. Preferably this would happen without the user having to worry if the under the hood implementation is lazy.

/usr/local/rasterframes/pyrasterframes.zip/pyrasterframes/rf_types.py in deserialize(self, datum)
    416         cell_data_bytes = datum.cell_data.cells
    417         try:
--> 418             as_numpy = np.frombuffer(cell_data_bytes, dtype=cell_type.to_numpy_dtype())
    419             reshaped = as_numpy.reshape((rows, cols))
    420             t = Tile(reshaped, cell_type)

AttributeError: 'NoneType' object has no attribute '__buffer__'

Activity

  1. metasim commented on Jun 17, 2019

    @metasim
    Member

    @vpipkt
    WRT the first issue, you should be able to do rf_local_add_int(col('tile'), 0), as all the columnar functions are supposed to handle the PRT -> Tile conversion automatically.

  2. metasim commented on Jun 17, 2019

    @metasim
    Member

    WRT the second issue, I'd indeed like this to be automatic. I think adding a function to "reify" the tile in the JVM in this case should be straight forward. My hope was to inject a "fetch" instruction through the Catalyst optimizer, but I ran into some problems in the tree matching code.

  3. self-assigned this
    on Jun 17, 2019
  4. vpipkt commented on Jun 18, 2019

    @vpipkt
    MemberAuthor

    Yes I am able to do the rf_local_add(tile) I just don't want to :-D

    @vpipkt
    WRT the first issue, you should be able to do rf_local_add_int(col('tile'), 0), as all the columnar functions are supposed to handle the PRT -> Tile conversion automatically.

  5. metasim commented on Jun 18, 2019

    @metasim
    Member

    Related: #128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions