Skip to content

Commit

Permalink
Merge pull request #271 from os-climate/minimal-deps
Browse files Browse the repository at this point in the history
Remove dependencies relevant only to ITR-examples
  • Loading branch information
ModeSevenIndustrialSolutions authored Oct 24, 2023
2 parents 38f5bc6 + b3ec115 commit 08189d8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 119 deletions.
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ classifiers = [
]
dependencies = [
"autoapi>=2.0.1",
"dash==2.11.1",
"dash-bootstrap-components==1.4.2",
"diskcache==5.6.1",
"flask==2.2.5",
"iam-units>=2022.10.27",
"jupyterlab==4.0.4",
"matplotlib==3.7.2",
"multiprocess==0.70.14",
"numpy==1.24.3",
"openpyxl==3.0.10",
"openscm-units==0.5.2",
Expand Down
112 changes: 0 additions & 112 deletions test/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@

from utils import gen_company_data, DequantifyQuantity, assert_pint_series_equal

import plotly.express as px
import plotly.graph_objects as go


def print_expected(target_df, company_data):
target_indexes = target_df.index.to_list()
Expand All @@ -56,28 +53,6 @@ def print_expected(target_df, company_data):
)


# https://stackoverflow.com/a/62853540/1291237
from plotly.subplots import make_subplots

subfig = make_subplots(specs=[[{"secondary_y": True}]])

# # create two independent figures with px.line each containing data from multiple columns
# fig = px.line(df, y=df.filter(regex="Linear").columns, render_mode="webgl",)
# fig2 = px.line(df, y=df.filter(regex="Log").columns, render_mode="webgl",)
#
# fig2.update_traces(yaxis="y2")
#
# subfig.add_traces(fig.data + fig2.data)
# subfig.layout.xaxis.title="Time"
# subfig.layout.yaxis.title="Linear Y"
# subfig.layout.yaxis2.type="log"
# subfig.layout.yaxis2.title="Log Y"
# # recoloring is necessary otherwise lines from fig und fig2 would share each color
# # e.g. Linear-, Log- = blue; Linear+, Log+ = red... we don't want this
# subfig.for_each_trace(lambda t: t.update(line=dict(color=t.marker.color)))
# subfig.show()


# For this test case, we prime the pump with known-aligned emissions intensities.
# We can then construct companies that have some passing resemplemnce to these, and then verify alignment/non-alignment
# as expected according to how we tweak them company by company.
Expand Down Expand Up @@ -328,26 +303,6 @@ def test_target_netzero(self):
ei_df_t=ei_df_t,
)

plot_dict = {
# "Trajectory": (co_productions * co_ei_trajectory).cumsum(),
f"{c.company_id} - {c.company_name}": self.base_company_data._convert_projections_to_series(
c, "projected_targets"
)
for c in company_data
}
target_df = pd.DataFrame(plot_dict)

fig = px.line(
target_df.pint.dequantify().droplevel(1, axis=1),
y=[k for k in plot_dict.keys()],
labels={
"index": "Year",
"value": f"{intensity.u:~P}",
"variable": "test_target_netzero",
},
)
# fig.show()

# print_expected(target_df, [company_ag, company_ah, company_ai, company_aj])
expected_ag = pd.Series(
PA_(
Expand Down Expand Up @@ -742,26 +697,6 @@ def test_target_2030(self):
ei_df_t=ei_df_t,
)

plot_dict = {
# "Trajectory": (co_productions * co_ei_trajectory).cumsum(),
f"{c.company_id} - {c.company_name}": self.base_company_data._convert_projections_to_series(
c, "projected_targets"
)
for c in company_data
}
target_df = pd.DataFrame(plot_dict)

fig = px.line(
target_df.pint.dequantify().droplevel(1, axis=1),
y=[k for k in plot_dict.keys()],
labels={
"index": "Year",
"value": f"{intensity.u:~P}",
"variable": "test_target_2030",
},
)
# fig.show()

# print_expected(target_df, [company_ag, company_ah, company_ai, company_aj])
expected_ag = pd.Series(
PA_(
Expand Down Expand Up @@ -1157,26 +1092,6 @@ def test_target_overlaps(self):
ei_df_t=ei_df_t,
)

plot_dict = {
# "Trajectory": (co_productions * co_ei_trajectory).cumsum(),
f"{c.company_id} - {c.company_name}": self.base_company_data._convert_projections_to_series(
c, "projected_targets"
)
for c in company_data
}
target_df = pd.DataFrame(plot_dict)

fig = px.line(
target_df.pint.dequantify().droplevel(1, axis=1),
y=[k for k in plot_dict.keys()],
labels={
"index": "Year",
"value": f"{intensity.u:~P}",
"variable": "test_target_overlaps",
},
)
# fig.show()

# print_expected(target_df, company_data)
expected_ag = pd.Series(
PA_(
Expand Down Expand Up @@ -1690,7 +1605,6 @@ def compute_scope_targets(c, projection_type, projection_years):
def _pint_cumsum(ser: pd.Series) -> pd.Series:
return ser.pint.m.cumsum().astype(ser.dtype)

# fig = px.line(df, x='id', y='value', color='variable')
cumsum_units = "Mt CO2e"
target_dict = {
f"Target: {c.company_id} - {c.company_name}": compute_scope_targets(c, "projected_targets", co_pp.columns)
Expand Down Expand Up @@ -1727,32 +1641,6 @@ def _pint_cumsum(ser: pd.Series) -> pd.Series:
axis=1,
)
)
dequantified_df = target_df.pint.dequantify().droplevel(1, axis=1)
# May have uncertainties...or some columns may be Float64
dequantified_df = dequantified_df.apply(
lambda col: col if col.dtype == "float64" else ITR.nominal_values(col).astype(np.float64)
)
fig_target = px.line(dequantified_df, y=dequantified_df.filter(regex="Target:").columns)
fig_trajectory = px.line(dequantified_df, y=dequantified_df.filter(regex="Trajectory:").columns)
fig_trajectory.update_traces(line={"dash": "dash"})
fig_target_cumulative = px.line(dequantified_df, y=dequantified_df.filter(regex="TargetCumulative:").columns)
fig_target_cumulative.update_traces(yaxis="y2")
fig_trajectory_cumulative = px.line(
dequantified_df,
y=dequantified_df.filter(regex="TrajectoryCumulative:").columns,
)
fig_trajectory_cumulative.update_traces(yaxis="y2", line={"dash": "dash"})
subfig = make_subplots(specs=[[{"secondary_y": True}]])
subfig.add_traces(
fig_target.data + fig_trajectory.data + fig_target_cumulative.data + fig_trajectory_cumulative.data
)
# subfig.for_each_trace(lambda t: t.update(line=dict(color=t.marker.color)))
# subfig.show()

# fig = px.line(target_df.pint.dequantify().droplevel(1, axis=1), y=[k for k in plot_dict.keys()],
# labels={'index':'Year', 'value':f"{intensity_s1s2.u:~P}", 'variable':'test_different_starting_dates_intensity'})
# fig.show()

self.data_warehouse = DataWarehouse(self.base_company_data, self.base_production_bm, self.OECM_EI_S3_bm)
companies = self.data_warehouse.get_preprocessed_company_data(company_index)

Expand Down

0 comments on commit 08189d8

Please sign in to comment.