You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by "Kontinuation (via GitHub)" <gi...@apache.org> on 2024/03/21 04:20:22 UTC
[PR] [SEDONA-406] Raster deserializer for PySpark (#116) [sedona]
Kontinuation opened a new pull request, #1281:
URL: https://github.com/apache/sedona/pull/1281
## Did you read the Contributor Guide?
- Yes, I have read [Contributor Rules](https://sedona.apache.org/latest-snapshot/community/rule/) and [Contributor Development Guide](https://sedona.apache.org/latest-snapshot/community/develop/)
## Is this PR related to a JIRA ticket?
- Yes, the URL of the associated JIRA ticket is https://issues.apache.org/jira/browse/SEDONA-406. The PR name follows the format `[SEDONA-XXX] my subject`.
## What changes were proposed in this PR?
### API changes
This PR adds a new class `SedonaRaster` to sedona python package. Raster objects in sedona will be converted to `SedonaRaster` objects in python when collecting raster objects in PySpark:
```python
rows = df_rast.collect()
rast = rows[0]['rast'] # rast is a SedonaRaster object
# You can get the metadata of raster by accessing the properties of SedonaRaster objects
print(rast.width, rast.height)
print(rast.affine_trans)
print(rast.crs_wkt)
# You can get the band data as numpy array
arr = rast.as_numpy()
# You can also get a rasterio DatasetReader object
ds = rast.as_rasterio()
# Please close the SedonaRaster after using it to free up resources allocated for the rasterio DatasetReader object
rast.close()
```
Users can define PandasUDFs taking raster object as parameter. Please use the `deserialize` function in `sedona.raster.raster_serde` module to deserialize the bytes to `SedonaRaster` object before processing it. Please note that this only works with Spark >= 3.4.0.
```python
# A Python Pandas UDF that takes a geometry as input
@pandas_udf(IntegerType())
def pandas_udf_raster_as_param(s: pd.Series) -> pd.Series:
from sedona.raster import raster_serde
def func(x):
with raster_serde.deserialize(x) as raster:
arr = raster.as_numpy()
return int(np.sum(arr))
return s.apply(func)
spark.udf.register("pandas_udf_raster_as_param", pandas_udf_raster_as_param)
```
### Internal changes
* Changed the serialization format of RasterUDT to a language-neutral format
* Notably, CRS is now serialized to WKT instead of using the Java serializer.
* This also significantly improved the performance of raster serialization/deserialization, since the new Kryo serailizer is way faster than Java serializer we used before.
* Added a raster deserializer for PySpark
## How was this patch tested?
Added new tests
## Did this PR include necessary documentation updates?
- **TODO**: We need to document the usage of `SedonaRaster` and `raster_serde`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on code in PR #1281:
URL: https://github.com/apache/sedona/pull/1281#discussion_r1534884075
##########
docs/setup/compile.md:
##########
@@ -73,11 +73,20 @@ For example,
export SPARK_HOME=$PWD/spark-3.0.1-bin-hadoop2.7
export PYTHONPATH=$SPARK_HOME/python
```
-2. Compile the Sedona Scala and Java code with `-Dgeotools` and then copy the ==sedona-spark-shaded-{{ sedona.current_version }}.jar== to ==SPARK_HOME/jars/== folder.
+2. Put JAI jars to ==SPARK_HOME/jars/== folder.
+```
+export JAI_CORE_VERSION="1.1.3"
Review Comment:
These jars are already in geotools-wrapper, so we can instead put the geotools-wrapper jar to the `$SPARK_HOME/jars/` folder, and build spark-shaded jar without `-Dgeotools`. However, this won't be able to test dependency changes such as adding jiffle as a new dependency.
I can update the document to use geotools-wrapper instead of directly using JAI jars, since it is much easier (no need to rebuild with `-Dgeotools` for testing sedona python), and covers most cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #1281:
URL: https://github.com/apache/sedona/pull/1281
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1281:
URL: https://github.com/apache/sedona/pull/1281#discussion_r1534414711
##########
docs/setup/compile.md:
##########
@@ -73,11 +73,20 @@ For example,
export SPARK_HOME=$PWD/spark-3.0.1-bin-hadoop2.7
export PYTHONPATH=$SPARK_HOME/python
```
-2. Compile the Sedona Scala and Java code with `-Dgeotools` and then copy the ==sedona-spark-shaded-{{ sedona.current_version }}.jar== to ==SPARK_HOME/jars/== folder.
+2. Put JAI jars to ==SPARK_HOME/jars/== folder.
+```
+export JAI_CORE_VERSION="1.1.3"
Review Comment:
Should we put these jars in geotools-wrapper?
##########
docs/tutorial/raster.md:
##########
@@ -583,6 +583,44 @@ SELECT RS_AsPNG(raster)
Please refer to [Raster writer docs](../../api/sql/Raster-writer) for more details.
+## Collecting raster Dataframes and working with them locally in Python
Review Comment:
Can you add one more section to explain how to write a regular Python User Defined Function (not Pandas UDF) to work on the raster type? I understand that the UDF cannot return a raster type directly since we only have a Python deserializer, but with the `RS_MakeRaster()` + NumPy array, we can still construct the raster type. It is important to show this workflow. Maybe we can show this in a separate Doc PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on code in PR #1281:
URL: https://github.com/apache/sedona/pull/1281#discussion_r1534884075
##########
docs/setup/compile.md:
##########
@@ -73,11 +73,20 @@ For example,
export SPARK_HOME=$PWD/spark-3.0.1-bin-hadoop2.7
export PYTHONPATH=$SPARK_HOME/python
```
-2. Compile the Sedona Scala and Java code with `-Dgeotools` and then copy the ==sedona-spark-shaded-{{ sedona.current_version }}.jar== to ==SPARK_HOME/jars/== folder.
+2. Put JAI jars to ==SPARK_HOME/jars/== folder.
+```
+export JAI_CORE_VERSION="1.1.3"
Review Comment:
These jars are already in geotools-wrapper, so we can instead put the geotools-wrapper jar to the `$SPARK_HOME/jars/` folder, and build spark-shaded jar without `-Dgeotools`. However, this won't be able to test geotools dependency changes such as adding jiffle as a new dependency.
I can update the document to use geotools-wrapper instead of directly using JAI jars, since it is much easier (no need to rebuild with `-Dgeotools` for testing sedona python), and covers most of the cases.
##########
docs/setup/compile.md:
##########
@@ -73,11 +73,20 @@ For example,
export SPARK_HOME=$PWD/spark-3.0.1-bin-hadoop2.7
export PYTHONPATH=$SPARK_HOME/python
```
-2. Compile the Sedona Scala and Java code with `-Dgeotools` and then copy the ==sedona-spark-shaded-{{ sedona.current_version }}.jar== to ==SPARK_HOME/jars/== folder.
+2. Put JAI jars to ==SPARK_HOME/jars/== folder.
+```
+export JAI_CORE_VERSION="1.1.3"
Review Comment:
These jars are already in geotools-wrapper, so we can instead put the geotools-wrapper jar to the `$SPARK_HOME/jars/` folder, and build spark-shaded jar without `-Dgeotools`. However, this won't be able to test geotools dependency changes such as adding jiffle as a new dependency.
I can update the document to use geotools-wrapper instead of directly using JAI jars, since it is much easier (no need to rebuild with `-Dgeotools` for testing sedona python), and covers most cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on code in PR #1281:
URL: https://github.com/apache/sedona/pull/1281#discussion_r1534884261
##########
docs/tutorial/raster.md:
##########
@@ -583,6 +583,44 @@ SELECT RS_AsPNG(raster)
Please refer to [Raster writer docs](../../api/sql/Raster-writer) for more details.
+## Collecting raster Dataframes and working with them locally in Python
Review Comment:
New section added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark (#116) [sedona]
Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on PR #1281:
URL: https://github.com/apache/sedona/pull/1281#issuecomment-2011344854
The R test failure is unrelated to this PR. The recent updates of sparklyr or dplyr caused this problem. See https://github.com/sparklyr/sparklyr/issues/3429.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [SEDONA-406] Raster deserializer for PySpark [sedona]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1281:
URL: https://github.com/apache/sedona/pull/1281#discussion_r1534984717
##########
docs/setup/compile.md:
##########
@@ -73,11 +73,20 @@ For example,
export SPARK_HOME=$PWD/spark-3.0.1-bin-hadoop2.7
export PYTHONPATH=$SPARK_HOME/python
```
-2. Compile the Sedona Scala and Java code with `-Dgeotools` and then copy the ==sedona-spark-shaded-{{ sedona.current_version }}.jar== to ==SPARK_HOME/jars/== folder.
+2. Put JAI jars to ==SPARK_HOME/jars/== folder.
+```
+export JAI_CORE_VERSION="1.1.3"
Review Comment:
This is fine then. We don't need to update this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org