hub/README.md

185 lines
6.9 KiB
Markdown
Raw Permalink Normal View History

2024-11-19 11:25:01 -05:00
## 1. Creating the City Model from a GeoJSON File
Start by using the `GeometryFactory` class to create a city model from a GeoJSON file. This class reads building geometries and attributes from the file and constructs a city model.
```python
city = GeometryFactory(
"geojson",
input_file,
height_field="height",
year_of_construction_field="contr_year",
function_field="function_c",
adjacency_field="adjacency",
function_to_hub=Dictionaries().montreal_function_to_hub_function
).city
```
- `"geojson"`: Specifies the format of the input file.
- `input_file`: The path to your GeoJSON file.
- `height_field="height"`: The attribute in the GeoJSON file that contains the building height.
- `year_of_construction_field="contr_year"`: The attribute for the building's year of construction.
- `function_field="function_c"`: The attribute for the building's function or usage.
- `adjacency_field="adjacency"`: The attribute indicating whether the building is attached or detached.
- `function_to_hub`: A dictionary that maps the building functions to standardized functions used by HUB.
The `city` object now contains all the buildings from the GeoJSON file with their associated attributes.
---
## 2. Enriching the City with Construction Details
Use the `ConstructionFactory` to enrich the city model with construction details and calculation of the thermal zones and total floor area.
```python
ConstructionFactory('nrcan', city).enrich()
```
- `'nrcan'`: Specifies the source of construction data, in this case, NRCan.
- `city`: The city model created in the previous step.
---
## 3. Assigning Energy Demands Using Archetypes
Finally, we assign energy demands to each building using the `ResultFactory` class and an archetype-based demand model. This basically maps buildings to predefined archetypes and assigning corresponding energy demand profiles.
```python
ResultFactory('archetypes', city, demand_file).enrich()
```
- `'archetypes'`: Specifies the handler we are using which in this case is archetype-based demand model.
- `city`: The city.
- `demand_file`: The path to the CSV file containing the archetype demand profiles.
---
## 4. Rules for Finding Archetypes and Assigning Demands
This mapping is based on the following building attributes:
- **Function**
- **Height**
- **Adjacency**: Whether the building is attached or is detached.
- **Year of Construction**
### **Mapping Rules**:
Based on the building's function, height, and adjacency:
- **Residential Buildings** ('residential', 'multifamily house', 'single family house'):
- **Single Family House**:
- Height less than 9 meters.
2024-11-19 11:25:01 -05:00
- Adjacency: 'detached'.
- `usage = 'Single Family'`.
- **Row House**:
- Height less than 9 meters.
2024-11-19 11:25:01 -05:00
- Adjacency: 'attached'.
- `usage = 'Row house'`.
- **Duplex/Triplex**:
- Height between 9 and 11 meters.
- Adjacency: 'attached'.
2024-11-19 11:25:01 -05:00
- `usage = 'Duplex/triplex'`.
- **Small MURBs** (Multi-Unit Residential Buildings):
- Height between 9 and 11 meters.
- Adjacency: 'detached'.
2024-11-19 11:25:01 -05:00
- `usage = 'Small MURBs'`.
- **Medium MURBs**:
- Height between 11 and 16 meters.
2024-11-19 11:25:01 -05:00
- `usage = 'Medium MURBs'`.
- **Large MURBs**:
- Height greater than 16 meters.
2024-11-19 11:25:01 -05:00
- `usage = 'Large MURBs'`.
- **Office Buildings** ('office', 'office and administration'):
- `usage = 'Office'`.
- **Commercial Buildings** ('commercial', 'retail shop without refrigerated food', 'retail shop with refrigerated food', 'stand alone retail', 'strip mall'):
- If adjacency is 'attached':
- `usage = 'Commercial attached'`.
- Else:
- `usage = 'Commercial detached'`.
#### Determine Building Vintage (`vintage`):
Based on the building's year of construction:
- **Pre-1947**:
- `year <= 1947`.
- `vintage = 'Pre 1947'`.
- **1947-1983**:
- `1947 < year <= 1983`.
- `vintage = '1947-1983'`.
- **1984-2010**:
- `1983 < year <= 2010`.
- `vintage = '1984-2010'`.
- **Post-2010**:
- `year > 2010`.
- `vintage = 'Post 2010'`.
Combine usage and vintage to create the key:
```python
archetype_key = f"{usage} {vintage}"
```
This key is used to look up the corresponding demand profiles in the archetype demand file.
---
### Assigning Demands:
1. **Lookup Demand Profiles**:
Using the `archetype_key`, retrieve the hourly demand profiles from the `demand_file`. Each archetype has associated hourly demands for different energy uses.
2. **Scale Demands by Floor Area**:
Multiply the demand values by the building's total floor area.
3. **Assign Demands to Building**:
Set the building's demand attributes:
```python
building.heating_demand = [value * area for value in demand['Heating']]
building.cooling_demand = [value * area for value in demand['Cooling']]
building.domestic_hot_water_heat_demand = [value * area for value in demand['DHW']]
building.appliances_electrical_demand = [value * area for value in demand['Equipment']]
building.lighting_electrical_demand = [value * area for value in demand['Lighting']]
```
---
### Example:
For a residential building with the following attributes:
- **Function**: 'residential'
- **Height**: 9 meters
- **Adjacency**: 'attached'
- **Year of Construction**: 1986
#### **Mapping Steps**:
1. **Usage**:
- Height is between 6 and 10 meters.
- Adjacency is 'attached'.
- Therefore, `usage = 'Small MURBs'`.
2. **Vintage**:
- Year is 1986, which falls in 1984-2010.
- Therefore, `vintage = '1984-2010'`.
3. **Archetype Key**:
- `archetype_key = 'Small MURBs 1984-2010'`.
## 4. Determining Height Thresholds for Residential Buildings
To find the correct height thresholds for residential buildings, we performed an analysis where:
1. **Height Thresholds:** The thresholds for `Single Family`, `Row House`, and `Duplex/Triplex` were varied systematically across a range of values (`single_max` from 4 to 17 meters, `duplex_max` from `single_max` + 2 to `single_max` + 12 meters).
2. **Classification:** Buildings were classified into categories based on the varying height thresholds and adjacency.
3. **Comparison:** The number of buildings in each category was compared with official statistics from **Statistics Canada** ([link to StatCan website](https://www150.statcan.gc.ca/t1/tbl1/en/tv.action?pid=9810001901)).
4. **Evaluation:** The Mean Absolute Error (MAE) between the classified counts and the census data was calculated for each threshold combination.
### **Result**
The analysis identified the optimal thresholds that minimized the error between the classified and census counts. The following heatmap illustrates the results, where the darkest cells represent the combinations with the least MAE. Based on the heatmap, thresholds of `9` meters for `single_max` and `11` meters for `duplex_max` yielded the best fit.
![MAE% Heatmap](scripts/mae_percent_of_total.png)
After determining the optimal height thresholds, these values were used to refine building archetype classification and improve energy demand predictions across the city model.