Skip to content

Commit

Permalink
adding numbers to order the code
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaumer committed Aug 19, 2023
1 parent 2b27107 commit 7e58682
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 0 deletions.
312 changes: 312 additions & 0 deletions Borough_Potential/01_exploreClimateChange.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "7c187a10",
"metadata": {
"id": "7c187a10"
},
"outputs": [],
"source": [
"import ee\n",
"import google"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bd4fc922",
"metadata": {
"id": "bd4fc922"
},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cd2789f",
"metadata": {
"id": "0cd2789f"
},
"outputs": [],
"source": [
"ee.Authenticate()\n",
"ee.Initialize()"
]
},
{
"cell_type": "markdown",
"id": "4276104f",
"metadata": {
"id": "4276104f"
},
"source": [
"Seems like climate scientists love their 30 year averages. Go ahead and compare 1980-2010 with 2010-present ?\n",
"What about 2000-2010 and 2010-2020?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ab7a03b",
"metadata": {
"id": "4ab7a03b"
},
"outputs": [],
"source": [
"daily = ee.ImageCollection(\"ECMWF/ERA5_LAND/DAILY_AGGR\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "adda23c9",
"metadata": {
"id": "adda23c9"
},
"outputs": [],
"source": [
"daily1980_2010 = daily.filterDate('1980-01-01', '2009-12-31').select('temperature_2m').mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e42c2b47",
"metadata": {
"id": "e42c2b47"
},
"outputs": [],
"source": [
"daily2010_now = daily.filterDate('2010-01-01', '2023-12-31').select('temperature_2m').mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4646c48",
"metadata": {
"id": "f4646c48"
},
"outputs": [],
"source": [
"counties = ee.FeatureCollection(\"TIGER/2018/Counties\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c204758e",
"metadata": {
"id": "c204758e"
},
"outputs": [],
"source": [
"ak = counties.filter(ee.Filter.eq('STATEFP', '02'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2342d633",
"metadata": {
"id": "2342d633"
},
"outputs": [],
"source": [
"ak.size().getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c189b31",
"metadata": {
"id": "9c189b31"
},
"outputs": [],
"source": [
"prewarming = daily1980_2010.reduceRegions(collection=ak, reducer=ee.Reducer.mean(), scale=11132)\n",
"prewarming = prewarming.select(['NAMELSAD', 'mean'])\n",
"prewarming"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f0ad67f",
"metadata": {
"id": "8f0ad67f"
},
"outputs": [],
"source": [
"postwarming = daily2010_now.reduceRegions(collection=ak, reducer=ee.Reducer.mean(), scale=11132)\n",
"postwarming = postwarming.select(['NAMELSAD', 'mean'])\n",
"postwarming"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "614b8242",
"metadata": {
"id": "614b8242"
},
"outputs": [],
"source": [
"pre_boroughs = []\n",
"pre_temperature = []\n",
"preL = prewarming.toList(30)\n",
"\n",
"for i in range(prewarming.size().getInfo()):\n",
" pre_temperature.append(ee.Feature(preL.get(i)).get('mean').getInfo())\n",
" pre_boroughs.append(ee.Feature(preL.get(i)).get('NAMELSAD').getInfo())\n",
"\n",
"pre_temperature, pre_boroughs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04eeef2a",
"metadata": {
"id": "04eeef2a"
},
"outputs": [],
"source": [
"post_boroughs = []\n",
"post_temperature = []\n",
"postL = postwarming.toList(30)\n",
"\n",
"for i in range(postwarming.size().getInfo()):\n",
" post_temperature.append(ee.Feature(postL.get(i)).get('mean').getInfo())\n",
" post_boroughs.append(ee.Feature(postL.get(i)).get('NAMELSAD').getInfo())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eab88dc8",
"metadata": {
"id": "eab88dc8"
},
"outputs": [],
"source": [
"pre_boroughs == post_boroughs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28d7610a",
"metadata": {
"id": "28d7610a"
},
"outputs": [],
"source": [
"pre_temperature_f = [(temp - 273.15) * 1.8 + 32 for temp in pre_temperature]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bba9ab51",
"metadata": {
"id": "bba9ab51"
},
"outputs": [],
"source": [
"post_temperature_f = [(temp - 273.15) * 1.8 + 32 for temp in post_temperature]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d974623",
"metadata": {
"id": "5d974623"
},
"outputs": [],
"source": [
"difference = [post - pre for post, pre in zip(post_temperature_f, pre_temperature_f)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2e7f68a",
"metadata": {
"id": "d2e7f68a"
},
"outputs": [],
"source": [
"difference_greater2 = [temp > 2 for temp in difference]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "075e55e0",
"metadata": {
"id": "075e55e0"
},
"outputs": [],
"source": [
"print([b for a, b in zip(difference_greater2, pre_boroughs) if a])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aeae7c8e",
"metadata": {
"id": "aeae7c8e"
},
"outputs": [],
"source": [
"difference"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a60906b",
"metadata": {
"id": "9a60906b"
},
"outputs": [],
"source": [
"sum(difference) / len(difference)"
]
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File renamed without changes.

0 comments on commit 7e58682

Please sign in to comment.