Due Dates

  • Design Checks due Oct. 19th 9pm ET
  • Project Code due Oct. 26th 9pm ET
  • Handin on Gradescope

Summary

In this project, we're building a simplified (and oversimplified! The climate science is complex, and we're only doing this to learn how we might simulate real-life situations using the program design skills we've learned so far.) Cilmate Simulator for Earth! The Earth is facing grave climate change challenges, and we want build a program that can look forward and predict the changes that the Earth's climate might take depending on various factors.

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.

To accelerate program development, environmental scientists have determined that the first version of the climate simulator can simulate a climate that is much simpler than the actual climate of Earth. On this model, there is one molecule that contributes to global temperature increases: the badicule (chemical formula BAd, boron aldebaranide). This is a temporary molecule we'll use as a single factor that contributes to temperature changes. (One can think of this as representing Carbon, too, but we've used an arbitrary name to represent any bad chemical that can cause damage here.)

Temperature on Earth is directly proportional to the amount of BAd in the atmosphere. Unfortunately, regions all over Earth have been emitting BAd. As temperatures on Earth increase, different nations will respond in different ways. Can Earth be saved?

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

  • The graphical display. It runs the simulator and presents a graphical portrayal of Earth (as shown in the image above!). We've provided this for you.
  • The simulator. This is the engine that simulates the process of time on Earth. It tracks the countries on Earth and their policies, the amount of BAd in the atmosphere, and the current year, and computes global temperatures. You'll implement the simulator.
  • Country policies. You'll implement a number of classes representing different possible policies. Every class will need to implement methods that the simulator calls in order to determine a country's emissions.

Learning goals

This project will give you experience:

  • Writing code across multiple modules
  • Creating classes and methods
  • Designing interactions between classes
  • Using polymorphism

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 13th. 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. 19th at 9pm EST
  5. Implement and test the simulator and the Baseline country policy.
  6. Implement and test the rest of the country policies (and make any necessary changes to the simulator).
  7. Write tests for your simulator.

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

Project components

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 simulator

The simulator is implemented as a class Simulator in the simulator.py file. The simulator tracks the amount of BAd in the atmosphere of Earth and the temperature of each country. The simulator's advance_year method is called by the display to simulate the passage of a year. The report method is called 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. It adds a country's name to the simulator's country_names list, and adds its corresponding policy to the simulator's policies dictionary.

The advance_year method

In the stencil code, advance_year just increments the current year. It will also need to:

  • Reduce the amount of BAd in the atmosphere by 1 ppm, to a minimum of 150 ppm. This simulates BAd being absorbed by natural processes.
  • Calculate each country's emissions by calling the emit method on each country's policy, passing any necessary arguments. (More on the emit method later.) Each country's emissions should be added the BAd total.
  • Calculate the temperature of each country. Country temperatures are calculated as follows:
    • The first country in the country_names list is the northernmost country. Its temperature should be the current BAd divided by 5.
    • Each subsequent country's temperature should be 5º greater than the previous temperature.
    • For example: if the countries are Canada, the United States, and Mexico and the current BAd is 150 ppm, the countries' temperatures should be 30º (in Canada), 35º (in the United States), and 40º (in Mexico).

If any country's temperature ever reaches the maximum temperature (self.max_temperature), the simulation should stop updating (i.e., don't increment the year or update any other state). This represents a failure to avert catastrophic climate change.

The report method

The report method generates a report for the graphical display. It is formatted as a list of hashtables representing country data (which should be in the same order as the simulator's country_names list). Each hashtable should have two keys:

  • "name", the country's name
  • "temperature", the country's current temperature

In the stencil code, report always returns the same report. You should fix it so that it actually reports the current state of the simulation.

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 are defined as classes in policies.py. The policies are as follows:

  • Baseline emits at a constant rate
  • Reducing reduces emissions by a constant amount every year to a minimum of zero
  • TemperaturePanic emits at a constant rate until the country's temperature is greater than a certain threshold, after which it reduces emissions at a constant rate to a minimum of zero
  • NeighborAverage tries to emit as much as its neighbors do:
    • If its neighbors are emitting less on average than it is, it reduces its emissions by a constant amount
    • Otherwise it raises its emissions by a constant amount

The stencil code includes an __init__ method for each policy, which takes as arguments the parameters for that policy. For instance, TemperaturePanic takes the initial emissions rate, the temperature threshold, and the rate at which it reduces its emissions once it starts panicking.

For each policy, you will need to:

  • Initialize the necessary data in __init__
  • Implement the emit method, which is called by the simulator once per year

You will have to determine the arguments the simulator should pass to the emit method. You should make sure you can implement all of the policies listed above using the information the simulator passes!

Many policies reduce or increase their emissions over time, so you will need to track past emissions as part of a policy object's state.

Every policy should have tests in test_policies.py.

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 a number of policies. You can edit it to experiment with different combinations of policies!

VSCode setup

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

  • Download the stencil code zip file (which is also linked to above in the Project tasks section). This unzips into a folder called climate_simulator. Move the zip file to a convenient location, and unzip climate_simulator.zip
  • Open the climate_simulator folder (from the zip file) in VSCode
  • Install the project's needed Python libraries:
    • Run the following commands in VSCode's terminal:
      pip3 install pytest
      pip3 install pygame==2.0.0.dev6
      
      If pip3 doesn't work, try using pip instead. If you have any trouble with this process, please post on EdStem!

Design Check

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

  1. What state will the simulator need to track? Be specific about the data structures you will use to track each piece of state.
  2. Why does each policy's emit method need to take in the same arguments? Think about the implementation of the simulator's advance_year method.
  3. What arguments should the emit methods take?

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, realistic pollution simulation for the actual climate and atmosphere on Earth. Detail the full process you’d take to create an accurate model and the advantages/disadvantages of your design choices. Feel free to draw inspiration from similar simulations that exist. Consider addressing:

  • Collecting data: what kind of data, where you’d source it from, assumptions/allowances you’d make, etc.
  • Constructing the simulation: variables to include, testing methods, consultations with experts to check its accuracy, etc.
  • Publicizing your work: how you will frame its purpose, the reactions of parties who may be affected, how it could be used in a positive or negative way, etc.

Emphasize the differences between this realistic simulation for Earth and one that contains only one arbitrary molecule, like in this assignment — what ethical considerations must you take into account given the real impact your final augmented product can have?

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. After completing the homework, you will submit:

  • README.txt
  • simulator.py
  • test_simulator.py
  • policies.py
  • test_policies.py

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. 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!

You can follow this step-by-step guide for submitting assignments through Gradescope here.