Skip to content

Commit b8e1212

Browse files
committed
Register resample in Python API, update python tests
Signed-off-by: Jason T. Brown <jason@astraea.earth>
1 parent c491410 commit b8e1212

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

pyrasterframes/python/pyrasterframes/rasterfunctions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def _(data_tile, mask_tile, mask_value):
244244
'exp2': 'Compute 2 to the power of cell values',
245245
'exp10': 'Compute 10 to the power of cell values',
246246
'exp1m': 'Performs cell-wise exponential, then subtract one',
247-
247+
'resample': 'Resample tile to different size based on scalar factor or tile whose dimension to match',
248+
248249
# ------- JTS functions -------
249250
# spatial constructors
250251
'st_geomFromGeoHash': '',

pyrasterframes/python/tests/PyRasterFramesTests.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def test_general(self):
9898
.withColumn('sum', tile_sum(self.tileCol)) \
9999
.withColumn('stats', tile_stats(self.tileCol)) \
100100
.withColumn('envelope', envelope('bounds')) \
101-
.withColumn('ascii', render_ascii(self.tileCol))
101+
.withColumn('ascii', render_ascii(self.tileCol)) \
102+
.withColumn('log', log(self.tileCol)) \
103+
.withColumn('exp', exp(self.tileCol)) \
104+
.withColumn('round', round(self.tileCol))
102105

103106
df.show()
104107

@@ -201,6 +204,17 @@ def test_maskByValue(self):
201204
self.assertTrue(result)
202205

203206

207+
def test_resample(self):
208+
from pyspark.sql.functions import lit
209+
result = self.rf.select(
210+
tile_min(local_equal(
211+
resample(resample(self.rf.tile, lit(2)), lit(0.5)),
212+
self.rf.tile))
213+
).collect()[0][0]
214+
215+
self.assertTrue(result == 1) # short hand for all values are true
216+
217+
204218
def suite():
205219
functionTests = unittest.TestSuite()
206220
functionTests.addTest(RasterFunctionsTest('test_identify_columns'))
@@ -212,6 +226,7 @@ def suite():
212226
functionTests.addTest(RasterFunctionsTest('test_explode'))
213227
functionTests.addTest(RasterFunctionsTest('test_sql'))
214228
functionTests.addTest(RasterFunctionsTest('test_maskByValue'))
229+
functionTests.addTest(RasterFunctionsTest('test_resample'))
215230
return functionTests
216231

217232

0 commit comments

Comments
 (0)