planetsca.predict

This module contains functions for predicting snow covered area (SCA) in Planet imagery.

predict.check_inputs(planet_path: str | List[str], model: str | RandomForestClassifier, output_dirpath: str = '') int[source]

Check the inputs for the predict_sca function

Parameters:
  • planet_path (str or List[str]) – file path to a single PlanetScope surface reflectance (SR) image, a list of file paths, or path to a directory containing multiple SR images

  • model (Union[str, RandomForestClassifier]) – file path to a model joblib file, or an sklearn.ensemble RandomForestClassifier model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

Returns:

  • file_list (List[str]) – a list of filepaths to PlanetScope surface reflectance (SR) images

  • model (RandomForestClassifier) – an sklearn.ensemble RandomForestClassifier model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

predict.check_inputs_onnx(planet_path: str | List[str], model: str | ModelProto, output_dirpath: str = '') int[source]

Check the inputs for the predict_sca_onnx function

Parameters:
  • planet_path (str or List[str]) – file path to a single PlanetScope surface reflectance (SR) image, a list of file paths, or path to a directory containing multiple SR images

  • model (Union[str, onnx.onnx_ml_pb2.ModelProto]) – file path to a model onnx file, or an onnx.onnx_ml_pb2.ModelProto model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

Returns:

  • file_list (List[str]) – a list of filepaths to PlanetScope surface reflectance (SR) images

  • model (onnx.onnx_ml_pb2.ModelProto) – an onnx.onnx_ml_pb2.ModelProto model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

predict.predict_sca(planet_path: str | List[str], model: str | RandomForestClassifier, output_dirpath: str = '', nodata_flag: int = 9) str | List[str][source]

This function predicts binary snow cover from PlanetScope satellite images using an ONNX random forest model

Parameters:
  • planet_path (str or List[str]) – file path to a single PlanetScope surface reflectance (SR) image, a list of file paths, or path to a directory containing multiple SR images

  • model (Union[str, RandomForestClassifier]) – file path to a model joblib file, or an sklearn.ensemble RandomForestClassifier model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

  • nodata_flag (int) – the value used to represent no data in the predicted snow cover image, default value is 9

Returns:

sca_image_paths – list of file paths to the SCA images produced

Return type:

List[str]

predict.predict_sca_onnx(planet_path: str | List[str], model: str | ModelProto, output_dirpath: str = '', nodata_flag: int = 9) str | List[str][source]

This function predicts binary snow cover from PlanetScope satellite images using an ONNX random forest model

Parameters:
  • planet_path (str or List[str]) – file path to a single PlanetScope surface reflectance (SR) image, a list of file paths, or path to a directory containing multiple SR images

  • model (Union[str, onnx.onnx_ml_pb2.ModelProto]) – file path to a model onnx file, or an onnx.onnx_ml_pb2.ModelProto model object

  • output_dirpath (str) – the directory where output snow cover images will be stored

  • nodata_flag (int) – the value used to represent no data in the predicted snow cover image, default value is 9

Returns:

sca_image_paths – list of file paths to the SCA images produced

Return type:

List[str]

predict.predict_with_onnxruntime(model: ModelProto, X: array) array[source]

Run a prediction with an ONNX model

Parameters:
  • model (onnx.onnx_ml_pb2.ModelProto) – an onnx.onnx_ml_pb2.ModelProto model object

  • X (np.array) – an array of input data of shape (n_samples, 4)

Returns:

predictions – an array of predicted labels for snow (1) or no snow (0) of shape (n_samples, 4)

Return type:

np.array