Skip to content

Commit

Permalink
delete
Browse files Browse the repository at this point in the history
  • Loading branch information
david-wei-01001 committed Dec 13, 2020
1 parent 44cba81 commit b67fb0e
Show file tree
Hide file tree
Showing 10 changed files with 22,228 additions and 87 deletions.
33 changes: 0 additions & 33 deletions climate_sea_level_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ class ClimateSeaLevelSystem:
# - _temperatures: a mapping from the date when a measure of the global
# temperature is made to the measurement.
# This represents all the temperatures in the system.
# - _sea_levels: a mapping from the date when a measure of the sea_level
# of a certain station is made to SeaLevel object.
# This represents all the sea-levels in the system.
# - _stations: a mapping from station name to Station object.
# This represents all the stations in the system.
# - _sea_level_dates: A set of all dates associated with each sea level measurement.

_temperatures: Dict[datetime.date, Temperature]
# _sea_levels: Dict[Tuple[datetime.date, str], SeaLevel]
_stations: Dict[str, Station]
_sea_level_dates: set

Expand All @@ -34,7 +30,6 @@ def __init__(self) -> None:
The system starts with no entities.
"""
self._temperatures = {}
# self._sea_levels = {}
self._stations = {}
self._sea_level_dates = set()

Expand All @@ -50,48 +45,20 @@ def get_dates(self) -> set:
"""Return the set containing all dates associated with sea level measurement."""
return self._sea_level_dates

# def find_min_temp(self) -> datetime.date:
# """Return the date of the first temperature measurements."""
# return min(self._temperatures.keys())

def add_temperature(self, temperature: Temperature) -> None:
"""Add the given temperature to this system.
Do NOT add the temperature if one with the same date already exists.
"""
# identifier = temperature.date
# if identifier in self._temperatures:
# return False
# self._temperatures[identifier] = temperature
# return True
identifier = temperature.date
if identifier not in self._temperatures:
self._temperatures[identifier] = temperature

# def add_sea_level(self, sea_level: SeaLevel) -> bool:
# """Add the given SeaLevel to this system.
#
# Do NOT add the sea_level if one with the same date and station already exists.
#
# Return whether the SeaLevel was successfully added to this system.
# """
# identifier = (sea_level.date, sea_level.station)
# if identifier in self._sea_levels:
# return False
# self._sea_levels[identifier] = sea_level
# return True

def add_station(self, station: Station) -> None:
"""Add the given station to this system.
Do NOT add the station if one with the same name already exists.
"""
# identifier = station.name
# if identifier in self._stations:
# return False
# self._stations[identifier] = station
# return True

identifier = station.name
if identifier not in self._stations:
self._stations[identifier] = station
Expand Down
1 change: 0 additions & 1 deletion data_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List, Any, Dict
from bs4 import BeautifulSoup
import requests
import datetime
from datapackage import Package


Expand Down
17 changes: 0 additions & 17 deletions entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,3 @@ class Station:
sea_level: dict
min_height: float
max_height: float


# @dataclass
# class SeaLevel:
# """Record the sea-level of a specific station at a specific date.
#
# Instance Variable:
# - date: The date at when the sea-level is recorded.
# - height: The recorded height of sea-level.
# - station: The name of the station at where the sea-level is measured
#
# Representation Invariance:
# - height > 0
# """
# date: datetime.date
# height: float
# station: str
13 changes: 0 additions & 13 deletions generates.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,13 @@ def generate(self, system: ClimateSeaLevelSystem) -> None:
system.add_sea_level_date(sea_level[1])
print(f'{station} is added.')

def generate_one(self, system: ClimateSeaLevelSystem, station: str) -> None:
"""Mutate system by generating one station.
"""
location = self._processed_sea_level_data[station][0]
sea_level = self.process_single_sea_level(station)
min_height = min(sea_level[0][data] for data in sea_level[0])
max_height = max(sea_level[0][data] for data in sea_level[0])
new_station = Station(station, location, sea_level[0], min_height, max_height)
system.add_station(new_station)
system.add_sea_level_date(sea_level[1])
print(f'{station} is added')

def process_single_sea_level(self, station: str) -> Tuple[Dict[datetime.date, float], list]:
"""This function will extract sea-level data from the internet.
This function will extract the corresponding sea-level data of the
input station name from the internet."""
csv_web = self._processed_sea_level_data[station][1]

# csv_file = urllib.request.urlopen(csv_web)
with contextlib.closing(urllib.request.urlopen(csv_web)) as csv_file:
lst_line = [line.decode('utf-8') for line in csv_file.readlines()]
read = csv.reader(lst_line)
Expand Down
3 changes: 0 additions & 3 deletions linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def get_compare(station: Station, system: ClimateSeaLevelSystem) -> list:
temperatures = system.get_temp()

base_month_sea = min(sea_levels.keys())
# base_month_temperature = system.find_min_temp()
base_month_temperature = min(temperatures.keys())

new_lst_temp = []
Expand Down Expand Up @@ -93,8 +92,6 @@ def extract_data(station: str, system: ClimateSeaLevelSystem) -> list:
"""Extract and process data from the input station and return a tuple containing the processed data to be used
when drawing the linear regression.
"""
# generate_tempera()
# generate_sea(station)
points_list = get_compare(system.get_station()[station], system)
graphing_data = []
for points in points_list:
Expand Down
20 changes: 0 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@
# pio.renderers.default = "browser"


# def generate_tempera() -> None:
# """Generating temperatures based on the measurement collected."""
# generate_temp.generate(system)
#
#
# def generate_sea() -> None:
# """Generating all stations with its collected sea level data."""
# generate_station.generate(system)


# def see_detail(station: str) -> None:
# """Invoke the go_plot function in the linear_regression module and pass in the station name for it."""
# go_plot(station, system)


def graph_data_set_up() -> tuple:
"""Set up all the datq for drawing the animation graph.
Expand Down Expand Up @@ -69,15 +54,12 @@ def see_regression() -> None:
print(f'The input station name {station} is invalid, please try again.')
station = input('Please type in the station name that you want to see detailed report of. '
'Hover over it to see name.')
# see_detail(station)
go_plot(station, system)


def main() -> None:
"""The main function that integrates everything in this project and show the animation graph. It also calls
see_regression function to show the linear regression."""
# generate_tempera()
# generate_sea()
GenerateTemperature().generate(system)
GenerateStationAndSeaLevel().generate(system)
draw_figure(graph_data_set_up())
Expand All @@ -88,8 +70,6 @@ def main() -> None:
if __name__ == '__main__':
# Created instances for the next two functions.
system = ClimateSeaLevelSystem()
# generate_temp = GenerateTemperature()
# generate_station = GenerateStationAndSeaLevel()

# Run the main function.
main()
Binary file added project_report/project_report.pdf
Binary file not shown.
115 changes: 115 additions & 0 deletions project_report/project_report.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
\documentclass[fontsize=11pt]{article}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.75in]{geometry}
\usepackage{graphicx}

\title{CSC110 Project Proposal: From Sea Level Raising to Global Warming: Analysing the Relationship Between Sea Level and Climate Change}
\author{Jiankun Wei, Ruiting Chen, Yiteng Sun, Weiheng Wang}
\date{Friday, November 6, 2020}

\begin{document}
\maketitle

\section*{Problem Description and Research Question}

Since the industrial revolution, humans have altered the world greatly from polluting the environment to destroying the habitat. We uninhibitedly release greenhouse gases into the air causing global warming, leaving heavy metals around mines to wipe out local plants, deforest Amazon for farming, and gazing. ("Deforestation in Brazilian Amazon surges to 12-year high") As a result, the species extinction rate of the world has soared from one species per decade to six thousand species per year, which has increased sixty thousand-fold! Yet in the past, humans have taken this for granted. We indeed alter the environment and many species go extinct, but it does not affect us. In fact, our metropolis mushroomed all around the world; airplanes flying high above the sky carrying people to explore previously unreachable places; factories had been built across the globe sending manufactured goods to everybody to improve our life. Even the moon, which our ancestors can only fancy about, has been reached. It seems all fine. But does it?\\
Gradually and unnoticeable by the proud humans, the Earth is altering and a great danger appears on the horizon -- the Raising of the sea level. ("This is what climate change look like") There are two main reasons for raising the sea level, all of them are due to the increasing amount of greenhouse gases in the atmosphere. As there are more and more greenhouse gases released into the air, it begins trapping sunlight which increases the temperature of the Earth. This in turn melts the ice on the north and south pole. The melted water flows into the sea, which raises the sea level. (“Why Are Glaciers and Sea Ice Melting?”) Also, as temperature rises, water tends to expand, directly leading to increased sea levels. Finally, as the sea level increases, more and more ice on the poles will be submerged underwater, and begin to melt itself. This is crucial because as the underlying ice melt, the iceberg fell into the sea which will eventually disappear resulting in a self-enhancing loop. ("NASA Sea Level Change Portal: Thermal Expansion.")\\
The rising sea level directly affects human society. First, a devastating tsunami will visit the coastline more frequently causing thousands of lives and money. The deconstruction of shelters will also turn people into refugees. What is more, seawater will taint the coastal farms and add salt into the soil which reduces the crop yield. Last but not the least, many cities located near the sea are directly threatened by the rising sea level. Following the current trend, big metropolis like London, San Diego, New York, and countries like the Netherlands will soon be submerged underwater. (Lewis, Sophie)\\

Given these important threatens, it is emergent to be aware and understand climate change and the rising sea level, and to treat them seriously.\\

Our research question is "How does sea-level change around the world due to climate change?”

\newpage
\section*{Dataset Description}
We gathered sea level data from the University of Hawaii Sea Level center website(UHSLC Legacy Data Portal), and temperature data from datahub. ("Global Temperature Time Series") The data downloaded from this website includes a collection of daily sea level recording (unit: mm) from different sea level stations across the world during the time span indicated in the data stored in .dat format. An example of sea level data from one station(Peter \& Paul Rocks Brazil) is shown in the image attached with this file.

Each data set contains a header(first row of data) and the body of the sea level data(the rest of the rows).\\

Header structure(from left to right):
\begin{itemize}
\item
station index: 3 digits station number followed by one letter from A to Z
\item
name and region of the station
\item
start and end year of data collection
\item
latitude and longitude of the station
\item
decimation method, Coded as
1 : filtered,
2 : simple average of all hourly values for a day,
3 : other
\item
reference offset: constant offset to be added to each data value for data to be relative to tide staff zero or primary datum in same units as data
\item
reference code: R = data referenced to datum,
X = data not referenced to datum
\item
unit of measurement
\end{itemize}

Body structure(from left to right):
\begin{itemize}
\item
station index: 3 digits station number followed by one letter from A to Z
\item
name and region of the station
\item
year of data collection
\item
julian day: day count from 1 Jan for 1st data point of each record followed by letter J for clarity
\item
12 daily sea level values(missing data indicated by(9999))
\end{itemize}


\section*{Computational Plan}

In order to let the data set be convenient for a computer to use, our group will write functions to read .html format file and .json format file to let python conveniently use this file to do complicated operations and then get assess to the data we need. ("Extracting Data from HTML with BeautifulSoup") Then we will create three dataclasses named “SeaLevel”, "Temperature" and "Station" to recored and store the data we need. In the next step, based on our entities, we would create a new class named "ClimateSeaLevelSystem", which is similar to the system we learnt in the lecture, to store all the data mapping to their key element(like station name matches its corresponding Station). After this step, we could create an abstract class named "EntityGenerator" to generate the Temperature data and Station with its corresponding sea level data and store them in our system "ClimateSeaLevelSystem". Then because the data type in our new data set is the continuous variables in the quantitative data type (Chopra \& Alaudeen(2019) page 1), thus we decide to use linear regression, and the scatter plots on map to present data by using plotly.\\
First, we want to present the relationship between the year (x-axis) and average daily sea-level value measured by one station (y-axis). We will first plot all the points out and then draw linear regression based on these points in the graph. What is more, we will also design a function to use linear regression to predict future changes in sea levels at different stations. \\
Then, we also design to show the relationship between the year (x-axis) and temperature measured by one station (y-axis). The methods is the same to the steps we take in creating the linear regression of sea level. To find the relation between sea level change and climate change, we will combine two lines in one chart. \\
Finally, we decided to use plotly to draw a world map with scatter plots about how the sea-level changes at all our stations from around 1880 to 2020, using the sea level data, station data from our data set. every single point on the map represents the actual location of each station. In the world map, we decide to use different color of plots to represent whether the sea level of the station is higher or lower than the base height(we also can say the sea level is rising or falling). For stations which reported rising sea level, we will use red to illustrate the intensity of how much sea level raised. For stations that reported falling sea level, we will use blue to illustrate the intensity of how much sea-level falls. Then as time moves forward, the colour will change, given the change in the rising and falling sea level as a vivid animation.\\
The plotly has the ability to draw animation which makes it relevant because by using plotly to draw animation, we can have a direct visualization of the data. ("Intro to Animations") As we depict the rising and falling of the sea level as time moves forward, the animation conveys in a vivid way the data which is just what we want to study. \\
Using plotly to draw animation is also appropriate because it reflects how sea level has changed in the recorded time period. This will give us valuable intuition on the data and also the importance of climate change. For example, when you see that as time passes, more and more areas become red and the colour gets darker and darker towards red, you will immediately realize the significance of climate change on our world and how less time we have. Thus, by viewing the animation, one will realize that the problem of climate change is something that we must treat seriously.


\section*{References}
\begin{enumerate}
\item
Nunez, Christina. “Sea Level Rise, Explained.” Sea Level Rise, Facts and Information, 27 Feb. 2019, www.nationalgeographic.com/environment/global-warming/sea-level-rise/.
\item
UHSLC Legacy Data Portal, uhslc.soest.hawaii.edu/data/?fd.
\item
Chopra, R., England, A., \& Alaudeen, M. N. (2019). Data science with Python: Combine Python with machine learning principles to discover hidden patterns in raw data. Birmingham: Packt Publishing.
\item
“Why Are Glaciers and Sea Ice Melting?” WWF, World Wildlife Fund, www.worldwildlife.org/pages/why-are-glaciers-and-sea-ice-melting.
\item
“NASA Sea Level Change Portal: Thermal Expansion.” NASA, NASA, 26 Mar. 2020.\\ sealevel.nasa.gov/understanding-sea-level/global-sea-level/thermal-expansion.
\item
Lewis, Sophie. “Rising Sea Levels on Track to Destroy the Homes of 300 Million People by 2050.” CBS News, CBS Interactive, 30 Oct. 2019, www.cbsnews.com/news/rising-sea-levels-on-track-to-destroy-homes-of-300-million-people-by-2050/.
\item
Shasta Darlington. "Deforestation in Brazilian Amazon surges to 12-year high". CNN World, CNN. 1 Dec, 2020.\\ https://edition.cnn.com/2020/12/01/americas/deforestation-brazil-amazon-bolsonaro-intl/index.html
\item
"This is what climate change looks like". CNN World, CNN. 11 Dec, 2020.\\
https://edition.cnn.com/2020/12/11/world/gallery/climate-change-effects-penguins-2020-spc/index.html
\item
Gaurav Singhal. "Extracting Data from HTML with BeautifulSoup". Pluralsight.\\ https://www.pluralsight.com/guides/extracting-data-html-beautifulsoup
\item
"Intro to animations in Python". Graphing Libraries, Plotly. https://plotly.com/python/animations/
\item
"Global Temperature Time Series". Datahub, Datahub. https://datahub.io/core/global-temp\#python
\item
Hover Text and Formatting. (n.d.). Python | Plotly. https://plotly.com/python/hover-text-and-formatting/
\item
Multiple Axes. (n.d.). Python | Plotly. https://plotly.com/python/multiple-axes/
\end{enumerate}

% NOTE: LaTeX does have a built-in way of generating references automatically,
% but it's a bit tricky to use so we STRONGLY recommend writing your references
% manually, using a standard academic format like APA or MLA.
% (E.g., https://owl.purdue.edu/owl/research_and_citation/apa_style/apa_formatting_and_style_guide/general_format.html)

\end{document}
Loading

0 comments on commit b67fb0e

Please sign in to comment.