<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Compute degree-days for heating and cooling
This notebook shows how to compute degree-days for heating and/or cooling from the ambient temperature.  We compute degree-days with different base temperatures.  This is a very useful input for eg. multivarible analyses, like <a href="https
Step1:  Prepare dataset
Step2:  Degree-days work on daily data, so we want to resample our dataset to the daily mean.
Step3:  Compute degree days
Step4:  Plot weekly degree days
We resample the daily degree-days to weekly sums and plot the results.
<ASSISTANT_TASK:>
Python Code:
import opengrid as og
import pandas as pd
plt = og.plot_style()
Explanation: Compute degree-days for heating and cooling
This notebook shows how to compute degree-days for heating and/or cooling from the ambient temperature.  We compute degree-days with different base temperatures.  This is a very useful input for eg. multivarible analyses, like <a href="https://opengridcc.github.io/analysis/mvar" target="_parent">this one</a>.
Imports
End of explanation
# A dataset with hourly weather variables for Brussels (2016) is included in OpenGrid.  
# Note that the data contains also the last week of 2015. 
# This is required in order for the degree-days computation to work for the first days of January. 
dfw = og.datasets.get('weather_2016_hour')
# We only need temperature
temp = dfw.temperature
Explanation: Prepare dataset
End of explanation
temp = temp.resample('D').mean()
fig = temp.plot()
Explanation: Degree-days work on daily data, so we want to resample our dataset to the daily mean.
End of explanation
# set base temperatures
heating_base_temperatures = range(8, 18, 2) # 8, 10, 12, 14, 16, 18
cooling_base_temperatures = range(16, 26, 2) # 16, 18, ...
# compute degree days for each of the base temperatures and return them in a dataframe called DD
DD = og.library.weather.compute_degree_days(
    ts=temp,
    heating_base_temperatures=heating_base_temperatures,
    cooling_base_temperatures=cooling_base_temperatures
)
# restrict the dataframe to 2016
DD = DD.loc['2016']
Explanation: Compute degree days
End of explanation
DD_weekly = DD.resample('W').sum()
fig = DD_weekly.filter(like='HDD').plot()
fig.set_title('Weekly heating degree-days with different base temperatures')
plt.show()
fig = DD_weekly.filter(like='CDD').plot()
fig.set_title('Weekly cooling degree-days with different base temperatures')
plt.show()
Explanation: Plot weekly degree days
We resample the daily degree-days to weekly sums and plot the results.
End of explanation
<END_TASK>