88from __future__ import absolute_import
99from pyspark .sql .types import *
1010from pyspark .sql .column import Column , _to_java_column
11- from .context import _checked_context
11+ from .context import RFContext
1212
1313
1414THIS_MODULE = 'pyrasterframes'
1515
1616
1717def _context_call (name , * args ):
18- f = getattr ( _checked_context (), name )
18+ f = RFContext . active (). lookup ( name )
1919 return f (* args )
2020
2121
@@ -27,8 +27,7 @@ def _celltype(cellTypeStr):
2727def _create_assembleTile ():
2828 """ Create a function mapping to the Scala implementation."""
2929 def _ (colIndex , rowIndex , cellData , numCols , numRows , cellType ):
30- ctx = _checked_context ()
31- jfcn = getattr (ctx , 'assembleTile' )
30+ jfcn = RFContext .active ().lookup ('assembleTile' )
3231 return Column (jfcn (_to_java_column (colIndex ), _to_java_column (rowIndex ), _to_java_column (cellData ), numCols , numRows , _celltype (cellType )))
3332 _ .__name__ = 'assembleTile'
3433 _ .__doc__ = "Create a Tile from a column of cell data with location indices"
@@ -39,7 +38,7 @@ def _(colIndex, rowIndex, cellData, numCols, numRows, cellType):
3938def _create_arrayToTile ():
4039 """ Create a function mapping to the Scala implementation."""
4140 def _ (arrayCol , numCols , numRows ):
42- jfcn = getattr ( _checked_context (), 'arrayToTile' )
41+ jfcn = RFContext . active (). lookup ( 'arrayToTile' )
4342 return Column (jfcn (_to_java_column (arrayCol ), numCols , numRows ))
4443 _ .__name__ = 'arrayToTile'
4544 _ .__doc__ = "Convert array in `arrayCol` into a Tile of dimensions `numCols` and `numRows'"
@@ -50,7 +49,7 @@ def _(arrayCol, numCols, numRows):
5049def _create_convertCellType ():
5150 """ Create a function mapping to the Scala implementation."""
5251 def _ (tileCol , cellType ):
53- jfcn = getattr ( _checked_context (), 'convertCellType' )
52+ jfcn = RFContext . active (). lookup ( 'convertCellType' )
5453 return Column (jfcn (_to_java_column (tileCol ), _celltype (cellType )))
5554 _ .__name__ = 'convertCellType'
5655 _ .__doc__ = "Convert the numeric type of the Tiles in `tileCol`"
@@ -61,7 +60,7 @@ def _(tileCol, cellType):
6160def _create_makeConstantTile ():
6261 """ Create a function mapping to the Scala implementation."""
6362 def _ (value , cols , rows , cellType ):
64- jfcn = getattr ( _checked_context (), 'makeConstantTile' )
63+ jfcn = RFContext . active (). lookup ( 'makeConstantTile' )
6564 return Column (jfcn (value , cols , rows , cellType ))
6665 _ .__name__ = 'makeConstantTile'
6766 _ .__doc__ = "Constructor for constant tile column"
@@ -72,7 +71,7 @@ def _(value, cols, rows, cellType):
7271def _create_tileZeros ():
7372 """ Create a function mapping to the Scala implementation."""
7473 def _ (cols , rows , cellType = 'float64' ):
75- jfcn = getattr ( _checked_context (), 'tileZeros' )
74+ jfcn = RFContext . active (). lookup ( 'tileZeros' )
7675 return Column (jfcn (cols , rows , cellType ))
7776 _ .__name__ = 'tileZeros'
7877 _ .__doc__ = "Create column of constant tiles of zero"
@@ -83,7 +82,7 @@ def _(cols, rows, cellType = 'float64'):
8382def _create_tileOnes ():
8483 """ Create a function mapping to the Scala implementation."""
8584 def _ (cols , rows , cellType = 'float64' ):
86- jfcn = getattr ( _checked_context (), 'tileOnes' )
85+ jfcn = RFContext . active (). lookup ( 'tileOnes' )
8786 return Column (jfcn (cols , rows , cellType ))
8887 _ .__name__ = 'tileOnes'
8988 _ .__doc__ = "Create column of constant tiles of one"
@@ -94,7 +93,7 @@ def _(cols, rows, cellType = 'float64'):
9493def _create_rasterize ():
9594 """ Create a function mapping to the Scala rasterize function. """
9695 def _ (geometryCol , boundsCol , valueCol , numCols , numRows ):
97- jfcn = getattr ( _checked_context (), 'rasterize' )
96+ jfcn = RFContext . active (). lookup ( 'rasterize' )
9897 return Column (jfcn (_to_java_column (geometryCol ), _to_java_column (boundsCol ), _to_java_column (valueCol ), numCols , numRows ))
9998 _ .__name__ = 'rasterize'
10099 _ .__doc__ = 'Create a tile where cells in the grid defined by cols, rows, and bounds are filled with the given value.'
@@ -104,7 +103,7 @@ def _(geometryCol, boundsCol, valueCol, numCols, numRows):
104103def _create_reproject_geometry ():
105104 """ Create a function mapping to the Scala reprojectGeometry function. """
106105 def _ (geometryCol , srcCRSName , dstCRSName ):
107- jfcn = getattr ( _checked_context (), 'reprojectGeometry' )
106+ jfcn = RFContext . active (). lookup ( 'reprojectGeometry' )
108107 return Column (jfcn (_to_java_column (geometryCol ), srcCRSName , dstCRSName ))
109108 _ .__name__ = 'reprojectGeometry'
110109 _ .__doc__ = """Reproject a column of geometry given the CRS names of the source and destination.
@@ -114,6 +113,17 @@ def _(geometryCol, srcCRSName, dstCRSName):
114113 _ .__module__ = THIS_MODULE
115114 return _
116115
116+ def _create_explode_tiles ():
117+ """ Create a function mapping to Scala explodeTiles function """
118+ def _ (* args ):
119+ jfcn = RFContext .active ().lookup ('explodeTiles' )
120+ jcols = [_to_java_column (arg ) for arg in args ]
121+ return Column (jfcn (RFContext .active ().list_to_seq (jcols )))
122+ _ .__name__ = 'explodeTiles'
123+ _ .__doc__ = 'Create a row for each cell in Tile.'
124+ _ .__module__ = THIS_MODULE
125+ return _
126+
117127_rf_unique_functions = {
118128 'assembleTile' : _create_assembleTile (),
119129 'arrayToTile' : _create_arrayToTile (),
@@ -123,7 +133,8 @@ def _(geometryCol, srcCRSName, dstCRSName):
123133 'tileOnes' : _create_tileOnes (),
124134 'cellTypes' : lambda : _context_call ('cellTypes' ),
125135 'rasterize' : _create_rasterize (),
126- 'reprojectGeometry' : _create_reproject_geometry ()
136+ 'reprojectGeometry' : _create_reproject_geometry (),
137+ 'explodeTiles' : _create_explode_tiles ()
127138}
128139
129140
@@ -154,7 +165,6 @@ def _(geometryCol, srcCRSName, dstCRSName):
154165
155166_rf_column_functions = {
156167 # ------- RasterFrames functions -------
157- 'explodeTiles' : 'Create a row for each cell in Tile.' ,
158168 'tileDimensions' : 'Query the number of (cols, rows) in a Tile.' ,
159169 'envelope' : 'Extracts the bounding box (envelope) of the geometry.' ,
160170 'tileToIntArray' : 'Flattens Tile into an array of integers.' ,
@@ -280,7 +290,7 @@ def _(geometryCol, srcCRSName, dstCRSName):
280290def _create_column_function (name , doc = "" ):
281291 """ Create a mapping to Scala UDF for a column function by name"""
282292 def _ (* args ):
283- jfcn = getattr ( _checked_context (), name )
293+ jfcn = RFContext . active (). lookup ( name )
284294 jcols = [_to_java_column (arg ) for arg in args ]
285295 return Column (jfcn (* jcols ))
286296 _ .__name__ = name
@@ -292,7 +302,7 @@ def _(*args):
292302def _create_columnScalarFunction (name , doc = "" ):
293303 """ Create a mapping to Scala UDF for a (column, scalar) -> column function by name"""
294304 def _ (col , scalar ):
295- jfcn = getattr ( _checked_context (), name )
305+ jfcn = RFContext . active (). lookup ( name )
296306 return Column (jfcn (_to_java_column (col ), scalar ))
297307 _ .__name__ = name
298308 _ .__doc__ = doc
0 commit comments