<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Analysis of Temoa Utopia results using pyam
The file temoa_utopia_pyam.xlsx used in this notebook is created by running the "Utopia" model
$ python temoa_model/ --config=temoa_model/config_sample
Running Temoa exports the results (among other formats) in an Excel format compatible
with the IAMC timeseries template
used by the IPCC WG3, the Energy Modeling Forum, and numerous EU Horizon 2020 projects
(read more).
The pyam package provides a suite of tools for analysis and visualization
of energy systems scenarios based on that format - read the docs!
Step1:  Visualization of CO2 emissions by species and sectors
The first plot shows the aggregate CO2 and NOx emissions over the model horizon.
Step2:  The next plot shows the CO2 emissions by sector.
Step3:  Or if you prefer stacked bar charts...
Step4:  Further analysis of emissions
So you want to "look" at the actual values of some timeseries?
Here, we first select aggregate CO2 and the emissions by each technology starting with 'IMP'
(because the other technologies are zero anyway, as we have seen from the plots above).
Step5:  The next cell uses the pyam.cumulative function
to compute the emissions on the timeseries data selected above.
Step6:  And just to prove the usefulness of this function
Step7:  Exporting to different file formats
You can use pyam to export your data in different file formats,
for example as a frictionless data package!
<ASSISTANT_TASK:>
Python Code:
import pyam
df = pyam.IamDataFrame('temoa_utopia_test_run_model/test_run_pyam.xlsx')
Explanation: Analysis of Temoa Utopia results using pyam
The file temoa_utopia_pyam.xlsx used in this notebook is created by running the "Utopia" model
$ python temoa_model/ --config=temoa_model/config_sample
Running Temoa exports the results (among other formats) in an Excel format compatible
with the IAMC timeseries template
used by the IPCC WG3, the Energy Modeling Forum, and numerous EU Horizon 2020 projects
(read more).
The pyam package provides a suite of tools for analysis and visualization
of energy systems scenarios based on that format - read the docs!
End of explanation
df.filter(variable='Emissions|*', level=0).plot()
Explanation: Visualization of CO2 emissions by species and sectors
The first plot shows the aggregate CO2 and NOx emissions over the model horizon.
End of explanation
df.filter(variable='Emissions|co2|*').plot.bar()
Explanation: The next plot shows the CO2 emissions by sector.
End of explanation
df.filter(variable='Emissions|co2|*').plot.bar(stacked=True)
Explanation: Or if you prefer stacked bar charts...
End of explanation
co2 = df.filter(variable=['Emissions|co2', 'Emissions|co2|IMP*']).timeseries()
co2
Explanation: Further analysis of emissions
So you want to "look" at the actual values of some timeseries?
Here, we first select aggregate CO2 and the emissions by each technology starting with 'IMP'
(because the other technologies are zero anyway, as we have seen from the plots above).
End of explanation
co2.apply(pyam.cumulative, first_year=1990, last_year=2010, axis=1)
Explanation: The next cell uses the pyam.cumulative function
to compute the emissions on the timeseries data selected above.
End of explanation
co2.apply(pyam.cumulative, first_year=1995, last_year=2010, axis=1)
Explanation: And just to prove the usefulness of this function:
it also works if you select a first_year argument that is not a native model year!
End of explanation
df.to_datapackage('utopia.zip')
Explanation: Exporting to different file formats
You can use pyam to export your data in different file formats,
for example as a frictionless data package!
End of explanation
<END_TASK>