Assignment 1, CSC202, Spring 2024
1 Getting Started
2 Requirements
3 A note about automated testing
3.1 A note about the previous section
4 A note about your email address
5 Basic Model
6 Functions over Data
7 Projection
8 Import restrictions
9 Handin instructions
9.1 Checking that you Submitted
8.12

Assignment 1, CSC202, Spring 2024🔗

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.

3.1 A note about the previous section🔗

Wait, hold on, did you read the earlier section? It’s important to declare your classes in the specified style; if you don’t, then all of our test cases may well fail, and your assignment could get a score of zero.

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 lo_lat, an upper latitude hi_lat, a western longitude west_long, and an eastern longitude east_long. 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 rect, the name of the region name, and the terrain 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 region, a year (int) year, a population (int, # of people) pop, and its rate of greenhouse gas emissions (in tons of CO2 equivalent per year, a float) ghg_rate.

Develop 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_region_conditions to a python list containing these regions, in this order.

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. Please be careful, there are quite a number of corner cases here.

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.

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.11.7, 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🔗

Your only deliverable for this assignment is the "main.py" file, which you should submit by pushing to the repository created for you by GitHub classroom.

Please note that the repository also contains a file called "basic-tests.py", and these tests are run automatically when you push to GitHub. These tests don’t verify that your code is correct, they simply verify that you have defined the right functions, and that they have the right number of arguments, and that they return the right kind of thing. These tests exist because it’s very sad when you are supposed to develop a function named (say) "success" and you accidentally name it (say) "succcess" and then all of the tests fail.

You can run these tests yourself, using

python3 basic-tests.py

... or by running this file in your favorite IDE.

These tests are also run for you when you push to GitHub, and you should see either a green check next to your submission if the tests passed, or a red X if they didn’t pass.

In general, files that don’t pass the basic tests may receive a score of zero on the assignment.

Please note that editing the "basic-tests.py" file is a terrible idea; the whole point of "basic-tests.py" is to ensure that the post-submission tests run correctly; editing this file is like using chewing gum to stick the needle of your thermometer to 80 degrees — it won’t actually make our tests pass, it will just obscure the real signal.

9.1 Checking that you Submitted🔗

If you’re not familiar with the overly complex nature of git, it’s very very possible to do all the work and commit it locally but fail to push it to GitHub classroom, in which case it will appear to us that you’ve done no work at all, which is very sad.

In order to check that your work is checked in, use the GitHub web interface to ensure that the version of the code that appears on GitHub is the most updated version, and that it passes all of the basic tests.