diff --git a/lcz_units_shp/lcz_10.dbf b/lcz_units_shp/lcz_10.dbf index 13f6466f5de8e15e240983bca4a0f126134d50b0..64db159186510394ba444b0412043585a9c7bd25 100644 Binary files a/lcz_units_shp/lcz_10.dbf and b/lcz_units_shp/lcz_10.dbf differ diff --git a/src/trees.py b/src/trees.py index 34cfc0a215a95c10558a9e4382760d5363b575ea..36eca6866a24d57c3edab8adceb7d23a16a84814 100644 --- a/src/trees.py +++ b/src/trees.py @@ -170,15 +170,18 @@ def calculate_tree_characteristics(shp_lcz_city, tree_dict, config): vary_tree_crown = config.get("vary_tree_crown", False) vary_tree_trunk = config.get("vary_tree_trunk", False) + # Check if tree_id_column exists in the DataFrame and if there are any tree IDs + if ( + tree_id_column not in shp_lcz_city.columns + or shp_lcz_city[tree_id_column].dropna().empty + ): + logger.info("No trees in LCZ-city.") + return shp_lcz_city + # Precompute randomized attributes if variation is enabled precomputed_characteristics = {} unique_tree_ids = shp_lcz_city[tree_id_column].dropna().unique() - # Check if there are any tree IDs and if not return LCZ-city - if len(unique_tree_ids) == 0: - logger.info("No trees in LCZ-city.") - return shp_lcz_city - # Logger infos logger.subinfo(f"Calculating characteristics for {len(unique_tree_ids)} trees.") if vary_tree_height: diff --git a/src/write_output.py b/src/write_output.py index 537e8d94b735e19f305788ace5c43054575ebcc6..d3b0b9398c8cd2c5f08513f3245795fd9aaa6607 100644 --- a/src/write_output.py +++ b/src/write_output.py @@ -143,6 +143,13 @@ def write_geotiff_from_shapefile(shp_lcz_city, config, base_filename="lcz_city") ) for attribute_column in attribute_columns: + # Check if the column exists in the shapefile + if attribute_column not in shp_lcz_city.columns: + logger.subinfo( + f"Column '{attribute_column}' specified in config.yml does not exist in the shapefile." + ) + continue + # Skip non-numeric columns if not np.issubdtype(shp_lcz_city[attribute_column].dtype, np.number): logger.subinfo(f"Skipping non-numeric column: {attribute_column}")