{ "cells": [ { "cell_type": "markdown", "id": "6731c70f", "metadata": { "id": "be14ef90" }, "source": [ "## Lab 11 ###" ] }, { "cell_type": "markdown", "id": "feb48844", "metadata": { "id": "feb48844" }, "source": [ "## Consider the following information\n", "\n", "#### 1. References for group calculations:\n", "\n", "https://pandas.pydata.org/pandas-docs/version/1.2/reference/api/pandas.core.groupby.GroupBy.mean.html\n", "\n", "https://pandas.pydata.org/pandas-docs/version/1.2/reference/api/pandas.core.groupby.GroupBy.min.html\n", "\n", "#### 2. main libraries to be imported:\n", "\n", "import pandas as pd\n", "import numpy as np\n", "file=\"https://github.com/masterfloss/sustainability/raw/refs/heads/main/lisboa.xlsx\"\n", "data = pd.read_excel(file)\n", "\n", "#### 3. distance between two points on the Earth's surface given their latitude and longitude in decimal degrees.\n", "\n", "The function you provided is known as the **Haversine formula**, which calculates the great-circle distance between two points on the Earth's surface given their latitude and longitude in decimal degrees. Here's a breakdown of the mathematical formulas extracted from the function:\n", "\n", "1. **Input Parameters:**\n", "\n", " - lat1: Latitude of the first point (in degrees).\n", " - lon1: Longitude of the first point (in degrees).\n", " - lat2: Latitude of the second point (in degrees).\n", " - lon2: Longitude of the second point (in degrees).\n", "\n", "\n", "2. **Earth's Radius:**\n", " - R = 6371 km (average radius of the Earth).\n", "\n", "3. **Differences in Latitude and Longitude:**\n", "\n", "\\begin{align}\n", " \\Delta \\text{lat} = \\text{lat2} - \\text{lat1}\\\\\n", " \\Delta \\text{lon} = \\text{lon2} - \\text{lon1}\n", "\\end{align}\n", "\n", "4. **Convert Degrees to Radians:**\n", "\\begin{align}\n", " \\ dlat = \\text{radians}(\\Delta \\text{lat}) \\\\\n", " \\ dlon = \\text{radians}(\\Delta \\text{lon})\n", "\\end{align}\n", "5. **Haversine Formula:**\n", "\\begin{align}\n", " a = \\sin^2\\left(\\frac{dlat}{2}\\right) + \\cos(\\text{radians}(\\text{lat1})) \\cdot \\cos(\\text{radians}(\\text{lat2})) \\cdot \\sin^2\\left(\\frac{dlon}{2}\\right)\n", "\\end{align}\n", " \n", "6. **Central Angle (c):**\n", "\\begin{align}\n", " c = 2 \\cdot \\text{atan2}\\left(\\sqrt{a}, \\sqrt{1 - a}\\right)\n", "\\end{align}\n", "\n", "7. **Distance (d):**\n", "\\begin{align}\n", " d = R \\cdot c\n", "\\end{align}\n", " where \\( d \\) is the great-circle distance between the two points.\n", "\n", "The overall Haversine formula to compute the distance between two points on the Earth's surface is:\n", "\\begin{align}\n", "d = 2R \\cdot \\text{atan2}\\left(\\sqrt{a}, \\sqrt{1 - a}\\right)\n", "\\end{align}\n", "where \\( a \\) is calculated as described above.\n", "\n", "\n" ] }, { "cell_type": "markdown", "id": "e4f1ef94", "metadata": { "id": "ae899059" }, "source": [ "## Answer to the following questions separatly:\n", "\n", "\n", "#### 1. Import necessary libraries and read import dataset\n", "\n", "#### 2. Separate points of interest (POIs) and Metro station data\n", "\n", "#### 3. Define a Haversine function (lat1, lon1, lat2, lon2) to calculate the distance between two coordinates\n", "\n", "#### 4. Combine the Metro and POI datasets into a new dataset\n", "\n", "#### 5. Create a new column for distances by applying the Haversine function. Use the pandas apply method: \n", "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html\n", "\n", "#### 6. Calculate the distance to the closest metro station for each POI\n", "\n", "#### 7. Calculate the average distance of each POI to all metro stations\n" ] }, { "cell_type": "code", "execution_count": null, "id": "8daf8be0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }