forked from databrickslabs/mosaic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python bindings for MosaicAnalyzer.
- Loading branch information
milos.colic
committed
Mar 15, 2024
1 parent
fc7bbfb
commit 7918a29
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .analyzer import MosaicAnalyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pyspark.sql import SparkSession, DataFrame, SQLContext | ||
from typing import * | ||
|
||
|
||
class MosaicAnalyzer: | ||
""" | ||
MosaicAnalyzer is a class that provides the ability to analyze spatial data | ||
and provide insights into the optimal resolution for the given dataset. | ||
This only works for geometries that have area > 0. | ||
""" | ||
|
||
def __init__(self, dataframe: DataFrame): | ||
""" | ||
Initialize the SpatialKNN model. | ||
""" | ||
|
||
self.spark = SparkSession.builder.getOrCreate() | ||
self.model = getattr( | ||
self.spark._jvm.com.databricks.labs.mosaic.sql, "MosaicAnalyzer" | ||
)(dataframe._jdf) | ||
|
||
def get_optimal_resolution(self, geometry_column: str): | ||
""" | ||
Get the optimal resolution for the given dataset. | ||
""" | ||
return self.model.getOptimalResolution(geometry_column) | ||
|
||
def get_optimal_resolution(self, geometry_column: str, nrows: int): | ||
""" | ||
Get the optimal resolution for the given dataset. | ||
""" | ||
return self.model.getOptimalResolution(geometry_column, nrows) | ||
|
||
def get_optimal_resolution(self, geometry_column: str, sample: float): | ||
""" | ||
Get the optimal resolution for the given dataset. | ||
""" | ||
return self.model.getOptimalResolution(geometry_column, sample) |