pyxccd.common module

class pyxccd.common.DatasetInfo(n_rows: int, n_cols: int, n_block_x: int, n_block_y: int)[source]

Bases: object

Store information for the dataset to be processed

n_rows: int

The number of rows

n_cols: int

The number of columns

n_block_x: int

The block number in x direction

n_block_y: int

The block number in y direction

nblocks: int

The total block number, n_block_x * n_block_y

block_width: int

The width of a block, n_cols / n_block_x

block_height: int

The height of a block, n_rows / n_block_y

class pyxccd.common.SccdOutput(position, rec_cg, min_rmse, nrt_mode, nrt_model, nrt_queue)

Bases: tuple

: A namedtuple of standard S-CCD ouputs

min_rmse

numpy.ndarray. 1-d array of shape (nbands,). The minimum RMSE was obtained by temporal semivariogram. This array keeps fix with sccd_update since sccd_detect is first used.

nrt_mode

int.

(first digit)

0 - has predictability

1 - not has predictability

(second digit)

The current sccd operating mode for the pixel:

0 - void mode, not intialized yet

1 - monitoring mode

2 - queue mode. Once the break is detected, the mode is transition from monitoring to queue mode

3 - monitoring mode for snow

4 - queue mode for snow

5 - transition mode from monitoring to queue mode (keep nrt_model and nrt_queue both), keeping 15 days since the break is first detected

nrt_model

numpy.ndarray. 1-d structured array with nrt_model dtype

Current nrt model that will be used for NRT monitoring. Only valid for the monitoring modes (1/3/5/11)

nrt_queue

numpy.ndarray. 1-d array of structured array with nrt_queue dtype.

Observation collection to build initialization model for queue modes (2/4/5). Collected the observations in the queue until the CCDC initialization successes.

position

int. Location of each time series model. The position is computed as (i * (n_row-1) + j), e.g., the pos of (1000, 1) is 5000*(1000-1)+1

rec_cg

numpy.ndarray. 1-d structured array with rec_cg. Historical temporal segment info were obtained from S-CCD algorithm as a structured array

class pyxccd.common.cold_rec_cg(t_start: int32, t_end: int32, t_break: int32, pos: int32, num_obs: int32, category: int16, change_prob: int16, coefs: ndarray, rmse: ndarray, magntiude: ndarray)[source]

Bases: object

records of segments obtained from COLD algorithm as a structured array, a composition of simple datatypes

t_start: int32

Ordinal date when series model gets started

t_end: int32

Ordinal date when series model gets ended

t_break: int32

Ordinal date when the structural break (change) is detected

pos: int32

Location of each time series model (i * n_row + j), e.g., the pos of (1000, 1) is 5000*1000+1

num_obs: int32

Number of clear observations used for model estimation

category: int16

Quality of the model estimation (what model is used, what process is used)

(first digit)

0 - normal model (no change)

1 - change at the beginning of time series model

2 - change at the end of time series model

3 - disturbance change in the middle

4 - fmask fail scenario

5 - permanent snow scenario

6 - outside user mask

(second digit)

1 - model has only constant term

4 - model has 3 coefs + 1 const

6 - model has 5 coefs + 1 const

8 - model has 7 coefs + 1 const

change_prob: int16

Probability of a pixel that have undergone change (between 0 and 100)

coefs: ndarray

2-d array of shape (nbands, ncoefs). It keeps multispectral harmonic coefficients from the last lasso regression. If not flexible mode, the spectral bands are fix, including blue, green, red, nir, swir1, swir2, thermal (from row 1 to 7). If flexible mode, the rows follow the order of inputted bands.The columns correspond to the eight harmonic coefficients including intercept, slope, cos_annual, sin_annual, cos_semi, sin_semi, cos_trimodal, sin_trimodal (from col 1 to 8). Note that the slope has been multiplied by 10000.

rmse: ndarray

1-d array of shape (nbands,), multispectral RMSE of predicted and actiual observations

magntiude: ndarray

1-d array of shape (nbands,), multispectral median difference between model prediction and observations of a window of conse observations following detected breakpoint

class pyxccd.common.rec_cg(t_start: int32, t_break: int32, num_obs: int32, coefs: ndarray, rmse: ndarray, magnitude: ndarray)[source]

Bases: object

historical temporal segment info obtained from S-CCD algorithm as a structured array, a composition of simple datatypes

t_start: int32

Ordinal date when series model gets started.

t_break: int32

Ordinal date when the structural break (change) is detected.

num_obs: int32

the number of “good” observations used for model estimation.

coefs: ndarray

2-d array of shape (nbands, ncoefs) to keep multispectral harmonic coefficients from the last lasso regression. If not flexible mode, the spectral bands are fixed, including blue, green, red, nir, swir1, swir2 (from row 1 to 6).If flexible mode, the rows follow the order of inputted bands.The columns are six harmonic coefficients including intercept, slope, cos_annual, sin_annual, cos_semi, sin_semi, (from col 1 to 6). Note the slope has been multiplied by 10000, S-CCD uses 6-coefs model and 6 spectral bands.

rmse: ndarray

1-d array of shape (nbands,), multispectral RMSE of predicted and actiual observations.

magnitude: ndarray

1-d array of shape (nbands,), multispectral median difference between model prediction and observations of a window of conse observations following detected breakpoint.

class pyxccd.common.nrtqueue(clry: ndarray, clrx_since1982: int16)[source]

Bases: object

1-d array of structured type for queue modes (2/4/5). It was used to store the observations and the dates in the queue until the CCDC initialization condition is met.

clry: ndarray

1-d array of shape (nbands, 1), multispectral clear observation

clrx_since1982: int16

the date number since 1982/7/16, equal to ordinal date - 723742

class pyxccd.common.nrtmodel(t_start_since1982: int16, num_obs: int16, obs: ndarray, obs_date_since1982: ndarray, covariance: ndarray, nrt_coefs: ndarray, H: ndarray, rmse_sum: ndarray, norm_cm: int16, cm_angle: int16, anomaly_conse: int8)[source]

Bases: object

The sccd model for the monitoring modes (1/3/5/11), which allows NRT monitoring.

t_start_since1982: int16

Date number since 1982/7/16, equal to ordinal date - 723742.

num_obs: int16

Accumulated observation number for the current segment.

obs: ndarray

2-d array of shape (nbands, nobs). The 6 spectral bands follow the order (blue, green, red, nir, swir1, swir2) for last 8 observations

obs_date_since1982: ndarray

1-d array of shape (nobs,). The date number since 1982/7/16 for the last 8 observations.

covariance: ndarray

2-d array of shape (nbands, ncofs_cov) | (nbands, n_cov_coefs). The covariance matrix for six bands (blue, green, red, nir, swir1, swir2). Each band has a 6*6 matrix as the covariance matrix was flatten into 1d.

nrt_coefs: ndarray

2-d array of shape (nbands, ncoefs) | (nbands, ncoefs). Each row is for each spectral for six spectral bands (blue, green, red, nir, swir1, swir2). Each row has 6 coefficients for each band.

H: ndarray

1-d array of shape (nbands,). Observation noise for six bands (blue, green, red, nir, swir1, swir2).

rmse_sum: ndarray

1-d array of shape (nbands,). RMSE for six bands (blue, green, red, nir, swir1, swir2).

norm_cm: int16

The current normalized change magnitude for the last anomaly_conse spectral anomalies, multiplied by 100 and rounded.

cm_angle: int16

The included angle for the last anomaly_conse spectral anomalies, multiplied by 100 and rounded.

anomaly_conse: int8

The current anomaly number at the tail of the time series. between 1 and 8. The anomalies were defined as the obs that are larger than anomaly_pcg.

class pyxccd.common.anomaly(t_break: int32, coefs: ndarray, obs: ndarray, obs_date_since1982: ndarray, norm_cm: int16, cm_angle: int16)[source]

Bases: object

anomaly segments as a structured array. S-CCD overdetected the spectral anomalies as “anomalys” using conse =3 and threshold=anomaly_pcg, which is used to trained a retrospective machine learning model for NRT scenario.

t_break: int32

ordinal date when the anomaly break is detected

coefs: ndarray

2-d array of shape (nbands, ncoefs) to keep multispectral harmonic coefficients from the last lasso regression. Spectral bands include blue, green, red, nir, swir1, swir2, thermal (from row 1 to 7); eight harmonic coefficients include intercept, slope, cos_annual, sin_annual, cos_semi, sin_semi, cos_trimodal, sin_trimodal (from col 1 to 8). Note the slope has been multiplied by 10000.

obs: ndarray

2-d array of shape (nbands, nobs). The 6 spectral bands follow the order (blue, green, red, nir, swir1, swir2) for last 8 observations.

obs_date_since1982: ndarray

1-d array of shape (nobs,). The date number since 1982/7/16 for the last 8 observations.

norm_cm: int16

Normalized change magnitude for the last anomaly_conse spectral anomalies, multiplied by 100 and rounded.

cm_angle: int16

included angale fot the last anomaly_conse spectral anomalies, multiplied by 100 and rounded.

pyxccd.common.update_anomaly(output_rec_cg_anomaly, nbands, ncoefs)[source]