brails.inferers.nlcd_inferer.nlcd_to_coarse_land_cover module
Ruleset that maps USGS NLCD classes to a coarser land cover categories.
Convert detailed USGS NLCD classes to a set of coarse categories. |
- class brails.inferers.nlcd_inferer.nlcd_to_coarse_land_cover.NLCDToCoarseLandCover
Bases:
InferenceEngine
Convert detailed USGS NLCD classes to a set of coarse categories.
This class maps USGS National Land Cover Dataset (NLCD) classes to one of five coarse categories:
'Open'
,'Light Suburban'
,'Suburban'
,'Light Trees'
, or'Trees'
.It operates exclusively on the
'land_cover'
field of each asset in an inventory and adds a new field'LandCover'
containing the mapped coarse category. Missing or unmapped values are assigned a placeholder (default:'Unknown'
).To use
NLCDToCoarseLandCover
, include the following lines in your code:from brails import Importer importer = Importer() nlcd_inferer = importer.get_class(NLCDToCoarseLandCover)
- infer(input_inventory)
Update each asset in the inventory with a coarse land cover category.
The method reads the
'land_cover'
field of each asset, maps it to a coarse category using the provided mapping, and writes the result to the'coarse_land_cover'
field. If the original value is missing or unmapped, a placeholder is used.- Parameters:
asset_inventory (AssetInventory) – An inventory object containing assets with a
'land_cover'
field.
Example
>>> from brails import Importer >>> from brails.types.asset_inventory import Asset, AssetInventory >>> importer = Importer() >>> inv = AssetInventory() >>> _ = inv.add_asset('A1', Asset( ... 'A1', ... [[-105.0, 40.0]], ... {'land_cover': 'Evergreen Forest'} ... )) >>> _ = inv.add_asset('A2', Asset( ... 'A2', ... [[-104.9, 39.5]], ... {'land_cover': 'Grasslands/Herbaceous'} ... )) >>> _ = inv.add_asset('A3', Asset( ... 'A3', ... [[-105.1, 39.7]], ... {'land_cover': 'Desert'} # unmapped ... )) >>> _ = inv.add_asset('A4', Asset( ... 'A4', ... [[-104.8, 40.2]], ... {} # missing ... )) >>> nlcd_inferer = importer.get_class('NLCDToCoarseLandCover')() >>> updated_inv = nlcd_inferer.infer(inv) >>> for asset_id, asset in updated_inv.inventory.items(): ... print(asset_id, asset.features['LandCover']) A1 Trees A2 Open A3 Unknown A4 Unknown