Skip to content

Instantly share code, notes, and snippets.

@ageller
ageller / .block
Last active August 12, 2019 16:30
Interactive Searchable Bar Chart
license: mit
height: 505
@ageller
ageller / getSentinalS2SRImage_block1.py
Last active November 19, 2021 20:22
getSentinalS2SRImage block 1
# define the area of interest, using the Earth Engines geometry object
coords = [
[lon - sze/2., lat - sze/2.],
[lon + sze/2., lat - sze/2.],
[lon + sze/2., lat + sze/2.],
[lon - sze/2., lat + sze/2.],
[lon - sze/2., lat - sze/2.]
]
aoi = ee.Geometry.Polygon(coords)
@ageller
ageller / getSentinalS2SRImage_block_2.py
Last active November 19, 2021 20:22
getSentinalS2SRImage block 2
# define the bands that I want to use. B4 is red, B3 is green, B2 is blue
# https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR#bands
bands = ['B4', 'B3', 'B2']
# export geotiff images, these go to Drive and then are downloaded locally
for selection in bands:
task = ee.batch.Export.image.toDrive(image=db.select(selection),
description=selection,
scale=30,
region=aoi,
@ageller
ageller / getSentinalS2SRImage_block_3.py
Created November 19, 2021 20:21
getSentinalS2SRImage block 3
# open the images
B2 = rasterio.open('B2.tif')
B3 = rasterio.open('B3.tif')
B4 = rasterio.open('B4.tif')
#get the scaling
image = np.array([B2.read(1), B3.read(1), B4.read(1)]).transpose(1,2,0)
p2, p98 = np.percentile(image, (2,98))
# use the B2 image as a starting point so that I keep the same parameters
@ageller
ageller / getSentinalS2SRImage_conda_install.sh
Last active December 17, 2021 15:18
getSentinalS2SRImage conda install
conda create --name geo_forge
conda activate geo_forge
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
conda install python=3.9 jupyter numpy matplotlib earthengine-api rasterio
@ageller
ageller / downloadChicagoMap_block_1.py
Last active November 19, 2021 20:53
downloadChicagoMap block 1
import ee
import rasterio
from rasterio.plot import show as showRasterio
# my script
from EarthEngineToGeoTIFF import getSentinalS2SRImage
import matplotlib.pyplot as plt
# Trigger the authentication flow.
@ageller
ageller / downloadChicagoMap_block_2.py
Last active November 19, 2021 20:53
downloadChicagoMap block 2
# Chicago central latitude, longitude and approximate size
lat = 41.8781
lon = -87.6298
sze = 0.65
_ = getSentinalS2SRImage(lon, lat, sze, 'ChicagoGeoTIFF.tif')
@ageller
ageller / downloadChicagoMap_block_3.py
Created November 19, 2021 20:28
downloadChicagoMap block 3
f,ax = plt.subplots(figsize=(15,15))
chicago = rasterio.open('ChicagoGeoTIFF.tif')
showRasterio(chicago.read(), ax = ax, transform=chicago.transform)
chicago.close()
@ageller
ageller / ChicagoPotholes_install.sh
Last active December 20, 2021 22:15
install geopandas and pandas
conda activate geo_forge
conda install geopandas pandas
@ageller
ageller / ChicagoPotholes_1.py
Last active December 20, 2021 22:14
read in the geospatial data
import rasterio
import pandas as pd
import geopandas as gpd
df = pd.read_csv('311_Service_Requests_-_Pot_Holes_Reported_-_Historical.csv')
gdf = gpd.read_file('Boundaries_ZIP_Codes/geo_export_94cfa385-03be-4b00-b827-c9e4fdd73a8f.shp')
chicago = rasterio.open('ChicagoGeoTIFF.tif')