Assignment 1, CSC202, Spring 2023
1 Getting Started
2 Requirements
3 A note about automated testing
4 A note about your email address
5 Basic Model
6 Functions over Data
6.1 One Trace Table
7 Projection
8 Import restrictions
9 Handin instructions
8.9.900

Assignment 1, CSC202, Spring 2023

In this assignment, we’re going to check in on our 101 skills and just a few new 202 skills by building a few pieces of a (tiny corner of a) simple climate model.

1 Getting Started

To get started on the first project, use this GitHub Classroom invitation link. If you’ve already started the project, it’s probably easiest to copy the code into the file created by the invitation.

2 Requirements

For each function required in this assignment, you should follow the design recipe, as described in this document. Specifically, each function should come with a purpose statement, types for both parameters and return type, and a full set of tests.

3 A note about automated testing

We will be using some automated testing in order to check the correctness of your code. For this reason, it’s important that names be spelled as specified, and that fields and parameters occur in the order specified in the text.

You should use an @dataclass(frozen=True) decorator to define all classes created in this assignment.

4 A note about your email address

We need to be able to link your GitHub ID to your cal poly email address.

In order to do this, we’re asking you to include a definition for calpoly_email_addresses in your main.py file. It should be bound to a list of strings. Here’s an example:

calpoly_email_addresses = ["zignog@calpoly.edu"]

5 Basic Model

To keep things simple-ish to begin with, we’re going model the surface of the earth as being broken up in to rectangular-ish regions of the globe, bounded by two lines of longitude and two lines of latitude. (These would be perfect rectangles on a mercator projection of the globe.)

Develop the GlobeRect class, that represents a region of the globe bounded by a lower latitude, an upper latitude, a western longitude, and an eastern longitude. The latitudes must be numbers between -90 and 90 inclusive (representing degrees of latitude), and the longitudes must be numbers between 0.0 and 360.0 representing degrees east longitude. The lower latitude must be less than the upper longitude. You do not need to enforce this. Note that the western longitude definitely does not have to be less than the eastern longitude. Can you see why?

Next, develop the Region class, that contains a GlobeRect describing the area of the region, the name of the region, and the terrain, which can be "ocean", "mountains", "forest", or "other" (see, I told you it was simplified!).

Finally, develop the RegionCondition class, which contains a Region, a year (int), a population (int, # of people), and its rate of greenhouse gas emissions (in tons of CO2 equivalent per year, a float).

Develop at four examples of a RegionCondition. Two of these should be major metropolitan centers, anywhere on earth. One of them should be a substantial fraction of an ocean (not a complete ocean, since I’m not aware of any major oceans that are rectangular). The last one should include Cal Poly, and should not include San Jose, Santa Barbara, Bakersfield, or too much ocean.

For each of these, estimates of all of the features are acceptable; years should be precise, lat/long coordinates should be within about 5% of the total included latitude or longitude, and for other measurements you should try to be within a factor of 10 of the correct numbers. The greenhouse gas emissions are going to be the hardest part, don’t spend more than five or ten minutes trying to ascertain the right answer.

give the name example_regions to a python list containing these regions.

6 Functions over Data

First, develop the emissions_per_capita method of the RegionCondition class that computes the tons of CO2-equivalent emitted per person living in the region per year.

Next, develop the area method of the GlobeRect class, that returns the area of the described part of the globe in square kilometers. Feel free to consult textbooks or other people in this computation.

Next, develop the emissions_per_square_km method of the RegionCondition, that computes the tons of CO2-equivalent emissions per square kilometer for the region.

Next, develop the densest function, that accepts a python list of RegionConditions and returns the name of the region that has the most people per square kilometer.

6.1 One Trace Table

Provide a trace table for a call to your densest function, when called with your example_regions list. You may abbreviate values using their global names, if they have them. For instance, if a variable foo has a value that has the global name reg1, then you can write this binding as foo = reg1.

7 Projection

Finally, we’re going to do just the simplest possible projection. Specifically, we’re going to assume that emissions grow proportionally with population for a given area, and each terrain type is going to be associated with a fixed annual growth rate.

Develop the project_condition function, that accepts a RegionCondition and a number of years, and returns a new RegionCondition that estimates the condition of the region after the specified number of years has passed. The population (and therefore the emissions) should grow by an annual growth rate that is determined by the type of terrain.

For an ocean region, the population should grow by 0.01% annually. For a mountain region, the population should grow by 0.05% annually. For a forest region, the population should grow by -0.001% annually. For an "other" region, the population should grow by 0.003% annually.

Note that ensuring full coverage for your tests will definitely be easier if you divide this problem into multiple helper functions, so that you can test certain functions individually, rather than (say) having to formulate a full RegionCondition object for every different kind of terrain.

Also, note that this problem is asking you to produce a new RegionCondition; you should definitely not need to mutate (change) any fields of any existing objects.

8 Import restrictions

In order to make it possible to test and analyze your code, it’s important that we be able to run it in a consistent environment.

Specifically, we will run your code with Python 3.10, in an environment that includes the NumPy package. Please do not import packages other than typing, unittest, numpy or dataclass, and please do not import the __future__ package.

9 Handin instructions

Just push to github classroom.