Source code for pyforestry.base.timber.timber_base.timber
"""Basic container class for individual tree parameters."""fromtypingimportOptional
[docs]classTimber:"""Representation of a single tree with minimal attributes."""def__init__(self,species:str,diameter_cm:float,height_m:float,double_bark_mm:Optional[float]=None,crown_base_height_m:Optional[float]=None,over_bark:Optional[bool]=None,stump_height_m:Optional[float]=0.3,):self.species=species.lower()self.diameter_cm=diameter_cmself.height_m=height_mself.double_bark_mm=double_bark_mmself.crown_base_height_m=crown_base_height_mself.over_bark=over_barkself.stump_height_m=stump_height_mself.validate()
[docs]defvalidate(self)->None:"""Validate that the provided tree attributes are sensible."""ifself.height_m<=0:raiseValueError("Height must be larger than 0 m: {self.height_m}")ifself.diameter_cm<0:raiseValueError("Diameter must be larger or equal to than 0 cm: {self.diameter_cm}")if(self.crown_base_height_misnotNoneandself.height_misnotNoneandself.crown_base_height_m>=self.height_m):raiseValueError((f"Crown base height ({self.crown_base_height_m} m) cannot be "f"higher than tree height: {self.height_m} m"))ifself.stump_height_misnotNoneandself.stump_height_m<0:raiseValueError(f"Stump height must be larger or equal to 0 m: {self.stump_height_m}")