common module
This module contains definitions for global attributes, functions, and classes that might be used anywhere in the package.
- Attributes:
HORIZON_DEFAULT (int): Default value for ‘’. PERIOD_LENGTH_DEFAULT (int): Default number of years per period. MIN_AGE_DEFAULT (int): Default value for core.Curve.xmin. MAX_AGE_DEFAULT (int): Default value for core.Curve.xmax. CURVE_EPSILON_DEFAULT (float): Defalut value for core.Curve.epsilon. AREA_EPSILON_DEFAULT = 0.01
- common.clean_vector_data(src_path: str, dst_path: str, dst_name: str, prop_names: list[str], clean: bool = True, tolerance: float = 0.0, preserve_topology: bool = True, logfn: str = 'clean_stand_shapefile.log', max_records: int | None = None, theme0: str | None = None, prop_types: list[tuple[str, str]] | None = None, driver: str = 'ESRI Shapefile', dst_epsg: int | None = None, update_area_prop: str = '') tuple[str, str][source]
Clean vector data obtained from a shapefile and reproject to a destination shapefile.
- Parameters:
src_path – Path to the source shapefile.
dst_path – Path to the destination shapefile.
dst_name – The name for the destination shapefile.
prop_names – List of property names.
clean – If True, performs cleaning; otherwise only reprojects.
tolerance – Adjusts the level of geometry modifications.
preserve_topology – If True, preserves topology.
logfn – Filename for the log file to store cleaned info.
max_records – Maximum number of records to process.
theme0 – Theme value for the cleaned shapefile.
prop_types – List of tuples showing property types.
driver – Driver for writing shapefiles.
dst_epsg – EPSG code for the destination CRS.
update_area_prop – Property that includes updated area information.
- Returns:
Tuple of paths (cleaned shapefile path, error shapefile path).
- common.harv_cost(piece_size: Any, is_finalcut: Any, is_toleranthw: Any, partialcut_extracare: bool = False, A: float = 1.97, B: float = 0.405, C: float = 0.169, D: float = 0.164, E: float = 0.202, F: float = 13.6, G: float = 8.83, K: float = 0.0, rv: bool = False) Any[source]
Returns harvest cost.
- Parameters:
piece_size (float) – Piece size.
is_finalcut (bool) – Treatment type (final cut or not).
is_toleranthw (bool) – Stand type (tolerant hardwood or not).
partialcut_extracare (bool) – Partialcut “extra care” flag.
A (float) – Series of regression coefficients (A, B, C, D, E, F, G, K, all with defaults that are extracted from MERIS technical documentation; also see Sebastien Lacroix, BMMB).
rv (bool) – Types of variables (default: Variables are deterministic).
- common.harv_cost_rv(tv_mu, tv_sigma, N_mu, N_sigma, psr, is_finalcut, is_toleranthw, partialcut_extracare=False, tv_min=50.0, N_min=200.0, ps_min=0.05, E_fromintegral=False, e=0.01, n=1000)[source]
Returns harvest cost.
- Parameters:
is_finalcut (bool) – Treatment type (final cut or not).
is_toleranthw (bool) – Stand type (tolerant hardwood or not).
partialcut_extracare (bool) – Partialcut “extra care” flag.
A (float) – Series of regression coefficients (A, B, C, D, E, F, G, K, all with defaults that are extracted from MERIS technical documentation; also see Sebastien Lacroix, BMMB).
rv (bool) – Types of variables (default: Variables random variates).
Can use either PaCAL numerical integration (sssslow!), or custom numerical integration using Monte Carlo sampling (default).
- common.harv_cost_wec(piece_size, is_finalcut, is_toleranthw, sigma, nsigmas=3, **kwargs)[source]
Estimate harvest cost with error correction.
- Parameters:
piece_size (float) – Mean piece size.
is_finalcut (bool) – True if harvest treatment is final cut, False otherwise.
is_toleranthw (bool) – True if tolerant hardwood cover type, False otherwise.
sigma (bool) – Standard deviation of piece size estimator.
nsigmas (int) – Number of standard deviations to model on either side of the mean (default 3).
binw (float) – Width of bins for weighted numerical integration, in multiples of sigma (default 1.0).
- common.hash_dt(dt: tuple[~typing.Any, ...], dtype: <MagicMock id='140298615736992'> = <MagicMock id='140298617672320'>, nbytes: int = 4) int[source]
Hash the development type and return an integer value.
- Parameters:
dt – Development type tuple.
dtype – The type of the output file (default is rasterio.int32).
nbytes – The number of bytes to consider from the hash (default is 4).
- Returns:
Integer hash value.
- common.hex_id(obj: Any, digest_size: int = 10) str[source]
Convert an object to a hexadecimal string via SHA-1 hashing.
- Parameters:
obj – The object to hash.
digest_size – Number of digest bytes to truncate to (unused).
- Returns:
Hexadecimal digest string.
- common.is_num(s: Any) bool[source]
Check whether the given input has a numerical value.
- Parameters:
s – Input value to test.
- Returns:
Trueiffloat(s)succeeds,Falseotherwise.
- common.piece_size_ratio(treatment_type, cover_type, piece_size_ratios)[source]
Returns piece size ratio.
Assume Action.is_harvest in [0, 1, 2, 3]
Assume cover_type in [‘r’, ‘m’, ‘f’]
- Return vr/vp ratio, where
vr is mean piece size of harvested stems, and
vp is mean piece size of stand before harvesting.
- common.rasterize_stands(shp_path: str, tif_path: str, theme_cols: list[str], age_col: str, blk_col: str = '', age_divisor: float = 1.0, d: float = 100.0, dtype: <MagicMock id='140298615752176'> = <MagicMock id='140298617531392'>, compress: str = 'lzw', round_coords: bool = True, value_func: ~collections.abc.Callable[[~typing.Any], str] = <function <lambda>>, cap_age: int | None = None, verbose: bool = False) dict[int, tuple[str, ...]][source]
Rasterize stand data and store the data as a TIFF file.
- Parameters:
shp_path – Path to the source shapefile.
tif_path – Path to the resulting TIFF file.
theme_cols – List of theme columns.
age_col – Age column name.
blk_col – Block identifier column name.
age_divisor – A number to scale stand age values.
d – The pixel size of the raster.
dtype – The type of the output file (default is rasterio.int32).
compress – The compression method (default is lzw).
round_coords – If True, rounds the coordinates of the output file.
value_func – A function applied to theme columns.
cap_age – Maximum stand age (optional).
verbose – Verbosity flag (defaults to False).
- Returns:
Dictionary mapping hash values to development type tuples.
- common.reproject(f: dict[str, Any], srs_crs: dict[str, Any], dst_crs: dict[str, Any]) dict[str, Any][source]
Reproject a geometry from a source coordinate reference system (CRS) to a destination CRS.
- Parameters:
f – Feature dictionary with
geometryandpropertieskeys.srs_crs – Source CRS dictionary.
dst_crs – Destination CRS dictionary.
- Returns:
The feature dictionary with the reprojected geometry.
- common.reproject_vector_data(src_path: str, snk_path: str, snk_epsg: int, driver: str = 'ESRI Shapefile') None[source]
Reproject vector data from a source shapefile to a destination shapefile using ESRI Shapefile as the default driver.
- Parameters:
src_path – Path to the source shapefile.
snk_path – Path to the destination shapefile.
snk_epsg – EPSG code for the destination CRS.
driver – The driver for writing the shapefiles.
- common.sylv_cred(P, vr, vp, formula)[source]
This function returns sylviculture credit ($ per hectare).
- Parameters:
P (float) – Volume harvested per hectare.
vr (float) – Mean piece size of harvested stems.
vp (float) – mean piece size of stand before harvesting.
formula – formula index (1 to 7).
- common.sylv_cred_formula(treatment_type, cover_type)[source]
Returns sylviculture credit formula index.
- Parameters:
treatment_type (str) – Treatment type.
cover_type (str) – Cover type.
- common.sylv_cred_rv(P_mu, P_sigma, tv_mu, tv_sigma, N_mu, N_sigma, psr, treatment_type=None, cover_type=None, formula=None, P_min=20.0, tv_min=50.0, N_min=200.0, ps_min=0.05, E_fromintegral=False, e=0.01, n=1000)[source]
This function returns sylviculture credit ($ per hectare).
- Parameters:
P (float) – Volume harvested per hectare.
vr (float) – Mean piece size of harvested stems.
vp (float) – mean piece size of stand before harvesting.
formula – formula index (1 to 7).
Note
Assumes that variables (P, vr, vp) are random variates (returns expected value of function, using PaCAL packages to model random variates, assuming normal distribution for all three variables). Can use either PaCAL numerical integration (sssslow!), or custom numerical integration using Monte Carlo sampling (default).
- common.timed(func: Callable[[...], Any]) Callable[[...], Any][source]
Record the execution time of a function.
- Parameters:
func – The function to be timed.
- Returns:
Wrapped function that prints execution time.
- common.warp_raster(src: <MagicMock id = '140298615751600'>, dst_path: str, dst_crs: dict[str, str] | None=None) None[source]
Warp a raster from its original CRS to a new CRS.
- Parameters:
src – The source rasterio dataset to be warped.
dst_path – The path to save the warped raster.
dst_crs – The destination CRS in rasterio format (default is EPSG:4326).