pyxccd.pyclassifier module

pyxccd.pyclassifier.generate_sample_num(label: ndarray, sample_parameters: dict) ndarray[source]

generate sample number for each land cover category using the method from the paper ‘Optimizing selection of training and auxiliary data for operational land cover classification for the LCMAP initiative’

Parameters:
  • label (np.ndarray) – a label map

  • sample_parameters (dict) – a dictionary must include “total_landcover_category”, “total_samples”, “max_category_samples”, and “min_category_samples”

Returns:

1-d array that stores the sample number for each label

Return type:

np.ndarray

pyxccd.pyclassifier.get_features(path: str) ndarray[source]

get block-based features

Parameters:

path (str) – Path for feature output

Returns:

2-d array for block-based features, (block_width*block_height, total feature)

Return type:

np.ndarray

class pyxccd.pyclassifier.PyClassifier(dataset_info: DatasetInfo, feature_outputs: list = ['a0', 'a1', 'b1'], logger: Logger | None = None, band_num: int = 7)[source]

Bases: object

predict_features(block_id: int, cold_block: ndarray, year_list_to_predict: list) ndarray[source]
Parameters:
  • block_id (int) – Block id, started from 1

  • cold_block (np.ndarray) – Block-based cold_rec_cg produced by COLD algorithms

  • year_list_to_predict (list) – A list of the years to extract features Note that the reason for not parsing cold_block to get year bounds is that the year range of blocks may vary from each other, so the year bounds are required to be defined from the tile level, not block level such as from ‘starting_end_date.txt’

Returns:

3d array, (len(year_list_to_predict), block_width*block_height, n_features)

Return type:

np.ndarray

train_rfmodel(full_feature_array: ndarray, label: ndarray)[source]

training a random forest model based on feature layers and a label map

Parameters:
  • full_feature_array (np.ndarray) – 3-d array for full feature layers, (nrows, ncols, feature_number)

  • label (np.ndarray) – 1-d array for a label map

Returns:

A sklearn random forest model

Return type:

class

classify_block(rf_model, tmp_feature: ndarray) ndarray[source]

classify feature block for a single year

Parameters:
  • rf_model (dict) – sklearn random forest model

  • tmp_feature (np.ndarray) – 2-d array for features, (block_width*block_height, n_features)

Returns:

2d array, a classification map, (block_height, block_width)

Return type:

np.ndarray

class pyxccd.pyclassifier.PyClassifierHPC(dataset_info: DatasetInfo, record_path: str, band_num: int = 7, year_list_to_predict=[1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021], tmp_path: str | None = None, output_path: str | None = None, feature_outputs: list = ['a0', 'a1', 'b1'], seedmap_path: str | None = None, rf_path: str | None = None, logger: Logger | None = None)[source]

Bases: PyClassifier

this class adds IO functions based on the HPC environment for the base class

is_finished_step1_predict_features()[source]
get_fullfeature_forcertainyear(year: int) list[source]

get

Parameters:

year (int) – Year to get a feature

Returns:

A list of all blocks as 3-d array (block_height, block_width, n_features)

Return type:

list

hpc_preparation()[source]
step1_feature_generation(block_id: int)[source]

generate feature based on COLD results

Parameters:

block_id (int) – the id of block

step2_train_rf(ref_year: int | None = None, rf_path: str | None = None)[source]

training a random forest model, and save it into rf_path

Parameters:
  • ref_year (int, optional) – The year to provide features which will be further connected to seed map, by default None

  • rf_path (str, optional) – Path to save random forest model , by default None. If none, will saved to rf_path

Raises:

ValueError – couldn’t locate seedmap that provide label maps

step3_classification(block_id: int)[source]

classify a block

Parameters:

block_id (int_) – the block id

Raises:

IOError – _description_

step3_classification_sccd(block_id: int)[source]

classifying based on sccd output

Parameters:

block_id (int) – block id

Raises:

IOError – couldn’t locate rf model file

step4_assemble(clean=True)[source]

assesmble all block-based classification results into one map

Parameters:

clean (bool, optional) – _description_, by default True

step4_assemble_sccd(clean=True)[source]

assessmble all block-based classification results based upon sccd into one map

Parameters:

clean (bool, optional) – _description_, by default True

is_finished_step4_assemble() bool[source]

check if step is finished

Return type:

bool