Project 2: Climate Simulator

Due Dates

Summary

In this project, we’re building a simplified climate simulator for Earth. The Earth is facing grave climate change challenges, and we want to build a program that can look forward and predict the changes that the Earth’s climate might take depending on various factors.

Naturally, the simulation we’re creating is somewhat over-simplified compared to real models. Climate science is complex, and while we’ve designed the project with input from real climate science, we’ve tried to strike a balance between the reality and the program-design skills the course has taught you so far.

In this project, you’ll develop components of a graphical climate change simulator and use it to observe the effects of various possible national emissions policies.

Context

Environmental scientists have determined a near-linear relationship between tonnes of carbon dioxide (CO2) and global surface temperature increases. In other words, the more CO2 we produce, the hotter our globe will be. Based on the most recent work from the Intergovernmental Panel on Climate Change (IPCC), if global temperatures increase 3.0°C from pre-industrial levels, global catastrophes like droughts, peak biodiversity losses, and extreme temperature changes will continue to unravel and exacerbate all across the world. To read more about the adverse impacts of rising global temperature levels, see the report.

By building a graphical simulator, we can see how much various countries contribute to global warming over time. We will also be implementing various policies that will impact how much CO2 a country emits.

The simulator will primarly be based on these two figures from the IPCC:

Global Temperature and Carbon Emissions

This first image represents the linear relationship between carbon emitted over time and global surface temperature increases.

Impact of 1.5 and 2.0 degree temperature increases

This second image demonstrates that the climbing global temperatures will carry disproportionate impacts on local regions across the globe.

Project Components

The climate change simulator you’re developing will have several components:

Learning goals

From a technical skills perspective, this project will give you experience with:

Project tasks

  1. In this class, all projects will be in a group format, where you will have one or more partners to collaborate with, depending on the project. For this project, you will have one group partner to work with.

    We will announce the partner matchings by Wednesday, October 11th. A TA will email you and your partner to set up a Design Check meeting. Make sure you and your project partner both attend the Design Check! (We need this information for grading purposes.)

  2. Read through this document in its entirety.
  3. Setup: Download the project’s stencil code from here.
  4. Design Check: Complete the Design Check questions due by Oct. 18th at 10pm EST
  5. Implement and test the simulator and the Baseline country policy.
  6. Implement and test the rest of the country policies listed, and make any necessary changes to the simulator.
  7. Refer to the course design recipe and apply it to your functions.
  8. Write tests for your simulator. (This is a great opportunity to practice good testing. For instance, make sure your tests don’t only use one particular policy class—exercise them all.)

When writing code, please follow the testing and style guide.

VSCode setup

In order to edit the project files using VSCode, you should:

If you are having any trouble with this process, please post on EdStem!

Project Component Details

The project includes several components: the simulator (which you will write), the country policies (which you will write), and the display (which is provided to you).

The display

The display is implemented for you in display.py. It has two buttons: the play/pause button, which starts calling the simulator’s advance_year method 10 times per second until it is paused, and the step button, which calls advance_year once. The rest of the interface displays the countries and temperatures reported by the simulator, as well as the current year.

You can run the display by running python3 main.py in your VSCode terminal. If that doesn’t work, try using python main.py instead. This initializes the display, the simulator, and two policies that have been hardcoded (you will need to change this as part of the assignment!). It should look like the following:

As you’re working with all these different modules, keep in mind the way they depend on each other:

The simulator

The simulator is implemented as a class Simulator in the simulator.py file. The simulator tracks the amount of cumulative carbon emissions (in gigatonnes, or, GtCO2) in the atmosphere and the average temperature of each country. The Display calls the Simulator’s advance_year function to simulate the passing of one year in time. The Display also calls the Simulator’s report function to generate a report of the countries on Earth and their current temperatures.

The add_country method

This method is implemented for you in the stencil code. The add_country method is called by the Main class. It adds a country’s name to the simulator’s country_names list. It also adds to the country_policies dictionary, where the country’s name is the key and the relevant policy is the value. Finally, it adds to the country_temperatures dictionary, where the country’s name is the key and the average_temp of that country is the value.

The advance_year method

In the stencil code, advance_year simulates the passing of one year in time when called. During the year, carbon is both emitted by countries and absorbed by natural processes. As a result of these emissions, the global and regional temperatures change. For this method, you should complete the following:

Note: Think about how you can use helper functions to assist the computations you are making in advance_year!

The report method

The report method of the simulator generates a report for the graphical display to use. It is formatted as a list of dictionaries representing data for each country. The list should be in the same order as the simulator’s country_names list. Each dictionary should have two keys:

In the stencil code, report always returns a fixed list. You should modify the stencil so that it actually reports the current state of the simulation, using the above equations.

Testing

Your advance_year and report methods should have tests in test_simulator.py. You may find it useful to create one or more special policy classes to use for testing; these should also be in test_simulator.py.

The policies

The policies we want you to create are defined as stencil classes in policies.py. An informal description of each policy is:

The stencil code includes an __init__ method for each policy, which takes as an argument baseline, which represents the initial emissions rate.

For each policy, you will need to:

Many policies reduce or increase emissions over time, so you will need to track of past emissions as part of some policy objects’ state. Also, think about how you can use principles of polymorphism to make the emit function take in the same arguments, while making sure each policy instance has access to the information it needs to compute the country’s emissions.

Every policy should have tests in test_policies.py.

Design Check

For the design check, you should submit a README.txt file with blocked out comments answering the following questions:

  1. Suppose United States has adopted the TaxEmissions policy (where emissions are reduced by 5% each year by what they were the previous year). The baseline (year0) CO2 emissions for the U.S. is 6.5Gt and the cumulative CO2 emissions for year0 is 2300Gt. The baseline (year0) temperature for the U.S. is 10.0 degrees Celsius. Round your answers to three decimal places.
    • A) Provide the year1 and year2 U.S. C02 emissions
    • B) Provide the year1 and year2 cumulative CO2 emissions, provided that other countries in the world have emitted 54Gt in year1 and 62Gt in year2. Take into account the amount of carbon absorbed by the atmosphere (see above).
    • C) Provide the year1 and year2 global surface temperature increases from baseline.
    • D) Provide the year1 and year2 United States temperatures (see equation above). Note that y in the equation will give you the temperature increase from baseline.
  2. What states will the simulator need to track? Be specific about the data structures you will use to track each piece of state. For example, how would you keep track of the temperatures for all countries?
  3. Why does each policy’s emit method need to take in the same arguments?
  4. What arguments should the emit methods take (there may be multiple correct answers)? Write at least one emit method/function.
  5. Think about the implementation of the simulator’s advance_year method, and write some helper functions in pseudocode that can assist with the computations you are making.

README Questions

In addition to late day information, your final README.txt should answer the following questions.

Imagine augmenting your simulator to be a higher-accuracy, more realistic simulation for the actual climate and atmosphere on Earth. Detail the full process you’d take to create a more accurate model and the advantages/disadvantages of your design choices. Feel free to draw inspiration from similar simulations that exist. Consider addressing:

Emphasize the differences between a realistic simulation for Earth and the basic one that you implemented for this project. What ethical considerations must you take into account given the real impact that a widely-used simulation might have?

Testing

Finally, make sure to test your simulator and each of the policies! This is a great opportunity to practice good testing. For instance, make sure your tests don’t only use one particular policy class—exercise them all.

If you would like, you can also add more countries other than the ones we have provided to use for testing. Refer to this spreadsheet for a list of other countries and information needed about them (average temperature, annual/baseline carbon emissions, and an equation for regional temperature change). Post on Ed if you have any questions about this!

Documentation

It is essential to properly document your test cases and begin applying the design recipe to your work. When documenting your tests, each test case should provivide an explanation of what the test is suppposed to be testing, which can be done through the use of comments/annotations.

In terms of applying the design recipe, it is imperative that you consistently follow each step of the design recipe outlined in the course website. This includes performing a thorough problem analysis, defining/choosing data structures based on the data you are working with and writing function specifications.

Handin

You may submit as many times as you want. Only your latest submission will be graded. This means that if you submit after the deadline, you will be using a late day – so do NOT submit after the deadline unless you plan on using late days.

The README template can be found here.

Please follow the design and clarity guide–part of your grade will be for code style and clarity. Additionally, you should be adhering to the course design recipe. After completing the homework, you will submit:

Because all we need are the files, you do not need to submit the whole project folder. As long as the file you create has the same name as what needs to be submitted, you’re good to go!

Only one of your partners should submit the project on Gradescope. Make sure to add your partner as a Group Member on your Gradescope submission so that you both can see the submission. Please DO NOT write your partner’s name in the README when listing other collaborators’ cslogins.

If you are using late days, make sure to make a note of that in your README. Remember, you may only use a maximum of 3 late days per assignment, and both you and your partner must have late days to use them. If the assignment is late (and you do NOT have anymore late days) no credit will be given.

Please don’t put your name anywhere in any of the handin files–we grade assignments anonymously!

Hand in your work on Gradescope. Use the Gradescope account associated with your anonymous ID which you set up during HW0. The guide for setting that up and enrolling in gradescope can be found in the Setup guide here.