Skip to content

Commit

Permalink
merge campus-decarb (#2)
Browse files Browse the repository at this point in the history
* streamlit cloud hack

* path hack print

* add logger

* streamlit hack

* add supabase dev

* add power plants

* add power plants and fix seeding and migrations

* create npm scripts
  • Loading branch information
szvsw authored Feb 12, 2024
1 parent a61715f commit 3b26b97
Show file tree
Hide file tree
Showing 22 changed files with 1,509 additions and 311 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

node_modules/
16 changes: 11 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"isort.args": ["--profile", "black"],
"isort.args": [
"--profile",
"black"
],
"jupyter.notebookFileRoot": "${workspaceFolder}",
"python.envFile": "${workspaceFolder}/.env"
"python.envFile": "${workspaceFolder}/.env",
"terminal.integrated.env.windows": {
"PYTHONPATH": "${workspaceFolder}"
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
Materials for MIT Campus Decarbonization Study

![Technology Overview](./figures/technology-overview.drawio.png)

## Setup

1. Install npm, conda (maybe docker)
2. npm i
3. npm run conda-setup
4. npx supabase init (?? maybe) && npx supabase login && npx supabase link
5. npm run db-refresh
Binary file added data/5out.hdf
Binary file not shown.
133 changes: 133 additions & 0 deletions data/mit_buildings_info.csv

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions data/seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import math

import numpy as np
import pandas as pd
from sqlmodel import Session

from lib.models import (
Building,
BuildingSimulationResult,
DemandScenario,
DemandScenarioBuilding,
DesignVector,
PowerPlant,
PowerPlantScenario,
engine,
)

df = pd.read_csv("data/mit_buildings_info.csv")
results_df = pd.read_hdf("data/5out.hdf", key="results")
with Session(engine) as session:
ds = DemandScenario(
name="Test Data Scenario", description="Test Data Scenario", year_available=2030
)
dv = DesignVector(name="Test Design Vector")
bsrs = []

for i, row in df.iterrows():
building = Building(
name=row["BUILDING_NAME_LONG"],
building_number=row["BUILDING_NUMBER"],
group_level_1=row["BUILDING_GROUP_LEVEL1"],
usage=row["CLUSTER_NUM"],
gfa=(
row["EXT_GROSS_AREA"] if not math.isnan(row["EXT_GROSS_AREA"]) else None
),
height=(
row["BUILDING_HEIGHT"]
if not math.isnan(row["BUILDING_HEIGHT"])
else None
),
year=(
row["YEAR_CONST_BEGAN"]
if not math.isnan(row["YEAR_CONST_BEGAN"])
else None
),
)
bsr = BuildingSimulationResult(
demand_scenario_building=DemandScenarioBuilding(
building=building, demand_scenario=ds, design_vector=dv
),
heating=results_df[
f"Zone Ideal Loads Supply Air Total Heating Energy"
].values.tolist(),
cooling=results_df[
f"Zone Ideal Loads Supply Air Total Cooling Energy"
].values.tolist(),
lighting=results_df[f"Zone Lights Electricity Energy"].values.tolist(),
equipment=results_df[
f"Zone Electric Equipment Electricity Energy"
].values.tolist(),
)
bsrs.append(bsr)
session.add_all(bsrs)

pv = PowerPlant(
name="Photovoltaics",
description="Photovoltaic Panels on the roof",
nominal_capacity=100,
nominal_cost=0.01,
nominal_emissions_factor=0,
)
grid = PowerPlant(
name="Grid",
description="The municipal power grid",
nominal_capacity=99999,
nominal_cost=0.24,
nominal_emissions_factor=23,
)
cup = PowerPlant(
name="CUP",
description="The campus combined utility plant",
nominal_capacity=40000, # 40 MW
nominal_cost=0.01,
nominal_emissions_factor=0,
)
session.add_all([pv, grid, cup])

t = np.linspace(0, 365 * 2 * np.pi, 8761)
t = t[:-1]
ts = pd.date_range(start="2020-01-01", end="2020-12-31", freq="h")[:-1]
y = np.sin(t - 2 * np.pi / 3).clip(0, 1) * ((-np.cos(t / 365) + 1) / 4 + 0.5)

pv_50 = PowerPlantScenario(
power_plant=pv,
name="50% PV Coverage",
description="50% of the available roof space is covered in PV panels",
year_available=2030,
capacities=y * 500,
emissions_factors=np.zeros(8760),
cost_factors=np.zeros(8760),
)
pv_70 = PowerPlantScenario(
power_plant=pv,
name="75% PV Coverage",
description="75% of the available roof space is covered in PV panels",
year_available=2040,
capacities=y * 75,
emissions_factors=np.zeros(8760),
cost_factors=np.zeros(8760),
)
session.add_all([pv_50, pv_70])
session.commit()
6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: mit-campus-decarbonization
dependencies:
- python=3.9
- pip
- pip:
- -r requirements.txt
Loading

0 comments on commit 3b26b97

Please sign in to comment.