{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Plot NO2 emissions data from Earth Engine\n* Using code that was adapted from https://www.kaggle.com/gpoulain/eda-ef-with-n2o-time-series-earth-engine\n* For more information on how to establish your initial connection to the Earth Engine API, see the DS4G: EIE [tutorial notebook](https://www.kaggle.com/paultimothymooney/how-to-get-started-with-the-earth-engine-data).  \n* Plots will exist for 2 days after the most recent commit.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"*Step 1: Import Python Modules and Connect to the Earth Engine API*","execution_count":null},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport folium\nfrom folium import plugins\n\ndef initMap(lat, lon):\n    location = [lat, lon]\n    Map = folium.Map(location=location, zoom_start=7)\n    return Map\n\ndef add_ee_layer(self, ee_image_object, vis_params, name):\n  map_id_dict = ee.Image(ee_image_object).getMapId(vis_params)\n  folium.raster_layers.TileLayer(\n    tiles = map_id_dict['tile_fetcher'].url_format,\n    attr = \"Map Data © Google Earth Engine\",\n    name = name,\n    overlay = True,\n    control = True\n  ).add_to(self)\n    \nfolium.Map.add_ee_layer = add_ee_layer\n\n# Connect to Earth Engine\nimport ee\nfrom kaggle_secrets import UserSecretsClient\nfrom google.oauth2.credentials import Credentials\n\n# Trigger the authentication flow.\n#ee.Authenticate()\n\n# Retrieve your refresh token.\n#!cat ~/.config/earthengine/credentials\n\nuser_secret = \"earth_engine\" # Your user secret, defined in the add-on menu of the notebook editor\nrefresh_token = UserSecretsClient().get_secret(user_secret)\ncredentials = Credentials(\n        None,\n        refresh_token=refresh_token,\n        token_uri=ee.oauth.TOKEN_URI,\n        client_id=ee.oauth.CLIENT_ID,\n        client_secret=ee.oauth.CLIENT_SECRET,\n        scopes=ee.oauth.SCOPES)\n\n# Initialize GEE\nee.Initialize(credentials=credentials)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*Step 2: Plot NO2 emissions from the first two weeks of October 2019*","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"startdate = '2019-10-01'\nfinishdate = '2019-10-14'\nlatitude = 18.20\nlongitude = -66.66","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"#Sentinel-5P OFFL NO2: Offline Nitrogen Dioxide\nee_s5p_no2 = (ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_NO2')\n              .select('NO2_column_number_density')\n              .filterDate(startdate, finishdate)\n             )\nband_viz_s5p_no2 = {\n    'min': 0,\n    'max': 0.00015,\n    'palette': ['black', 'blue', 'purple', 'cyan', 'green', 'yellow', 'red']}\nMap = initMap(lat = latitude, lon = longitude)\nMap.add_ee_layer(ee_s5p_no2.mean(), band_viz_s5p_no2, 'S5P_NO2')\nMap.add_child(folium.LayerControl())\nMap","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*Step 3: View basemap with no emissions data overlayed*","execution_count":null},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":false,"trusted":true},"cell_type":"code","source":"Map = initMap(lat = latitude, lon = longitude)\nMap","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}