acept.uhp_csv_io
Module for writing and reading .csv files for Urban Heat Pro (UHP).
UHP expects .csv files in one of the following two formats:
information;on;the;file;content;...
column1;column2;column3;column4;column5;...
value1;value2;value3;value4;value5;...
...
column1;column2;column3;column4;column5;...
unit1;unit2;unit3;unit4;unit5;...
value1;value2;value3;value4;value5;...
...
- Use this module to:
Write a DataFrame to a .csv file in the UHP format.
Read a .csv file in the UHP format and return a DataFrame.
Prepare the input .csv file with the buildings for UHP from a GeoDataFrame.
Save a GeoDataFrame with the buildings or a BBD query result to a .csv file in the format expected by UHP.
For buildings the format of the .csv file is:
field1;field2;field3;field4;field5;...
value1;value2;value3;value4;value5;...
...
- Buildings have the following required columns:
bid: ID of the building
area: The size of the area in m2
use: Use type of the building as a number from 0 to 3
free_walls: Number of free walls of the building
lat: Latitude in degrees
lon: Longitude in degrees
dist2hp: Distance to the heat pump in m
- These additional columns are optional:
year_class: TABULAR construction year class of the building as a number
size_class: TABULAR size class of the building as a number
floors: Number of floors
occupants: Number of occupants
dwellings: Number of dwellings
ref_level_roof: Refurbishment level of the roof
ref_level_wall: Refurbishment level of the walls
ref_level_floor: Refurbishment level of the floors
ref_level_window: Refurbishment level of the windows
- The refurbishment level is a number from 1 to 3:
1 = National minimum requirement
2 = Improved standard
3 = Ambitious standard
Module Contents
Functions
|
Writes a DataFrame to a .csv file in the format expected by UHP. |
|
Reads a .csv file in the format expected by UHP. |
Prepare buildings GeoDataFrame as input CSV for UrbanHeatPro. |
|
Save the buildings or a BBD query result to a .csv file in the format used by UrbanHeatPro in the /temp directory. |
- acept.uhp_csv_io.write_geopandas_to_uhp_csv(filepath: str, values_df: pandas.DataFrame, first_row_header: list, second_row_info: list = [], sep: str = ';') str[source]
Writes a DataFrame to a .csv file in the format expected by UHP.
Writes a .csv file to the given path with a header row, an optional second row with additional information on the data (e.g. units), followed by the data.
- Parameters:
filepath (str) – Path where to save the .csv file.
values_df (pandas.DataFrame) – DataFrame to save. The column names in the DataFrame are not written to the file. The order of the columns has to be the same as in the header rows.
first_row_header (list) – List of column names to be written to the first line of the file.
second_row_info (list) – Optional list of information for each column written to the second line of the file.
sep (str) – Column seperator in the .csv file. Default: ‘;’.
- Returns:
Path to the saved file.
- Return type:
- acept.uhp_csv_io.read_uhp_csv_to_dataframe(filepath: str, header_row: int | tuple[int, list] = 0, ignore_index: bool = True, additional_info: int | None = -1, sep: str = ';') tuple[pandas.DataFrame, list[Any]][source]
Reads a .csv file in the format expected by UHP.
Reads a .csv file with a header row, an optional second row with additional information on the data (e.g. units), and returns a DataFrame with the data and a list of additional information if requested. The column names are optionally renamed.
- Parameters:
filepath (str) – Path to the .csv file.
header_row (int | tuple[int, list]) – Row number of the header row, or a tuple with the row number and a list of new column names. Default: 0.
ignore_index (bool) – If True, the index is ignored. Default: True
additional_info (int | None) – Optional Integer indicating the row number of the row with additional information. If negative, the additional information is ignored. If None, no additional information exists. Default: -1.
sep (str) – Column seperator in the .csv file. Default: ‘;’.
- Raises:
ValueError – If header_row is not an int or a tuple of the form (int, list)
- Returns:
DataFrame with the data, and a list of additional information if requested.
- Return type:
tuple[pandas.DataFrame, list[Any]]
- acept.uhp_csv_io.prepare_buildings_for_uhp_csv(area_id: str | int, buildings: geopandas.GeoDataFrame, debug: bool = True) str[source]
Prepare buildings GeoDataFrame as input CSV for UrbanHeatPro.
Add missing fields and map the values to the UHP format. Writes the result to a .csv file in the format used by UrbanHeatPro in the respective /temp directory.
- Parameters:
buildings (geopandas.GeoDataFrame) – The GeoDataFrame of buildings.
debug (bool) – Whether to enable debug mode and print debug messages. Default: True.
- Raises:
ValueError – If the required column names are not in the buildings GeoDataFrame
- Returns:
The path to the saved UHP CSV file.
- Return type:
- acept.uhp_csv_io.save_buildings_to_temp_uhp_csv(plz_or_area_id: str, result_gdf: geopandas.GeoDataFrame, building_use: str = 'All', debug: bool = True) str[source]
Save the buildings or a BBD query result to a .csv file in the format used by UrbanHeatPro in the /temp directory.
- Parameters:
plz_or_area_id (str) – The queried PLZ or the ID of the area the buildings belong to.
building_use (str) – Use type of the buildings in the BBD query, default: ‘All’ selects all use types. Possible: ‘All’, ‘Residential’, ‘Industrial’, ‘Commercial’, ‘Public’, ‘Non-Residential’.
result_gdf (geopandas.GeoDataFrame) – GeoDataFrame with all buildings in result_gdf.
debug (bool) – Whether to enable debug mode and print debug messages. Default: True.
- Raises:
ValueError – if the required column names are not in the result_gdf
- Returns:
File path to the CSV file with the buildings.
- Return type: