Created
February 18, 2020 20:52
-
-
Save jdbcode/f4d56d72f7fc5beeaa3859999b1f5c3d to your computer and use it in GitHub Desktop.
q_350771_68792.ipynb
@Mohammadreza20 If you are looking to just visualize the NO2 data with Iran state overlay in Python with matplotlib, you can do it all in server-side Earth Engine - you just transfer final visualization to Python client for plotting (regarding non-EE libraries for overlay, I'm not sure):
import ee ee.Initialize() import requests from io import BytesIO from PIL import Image import matplotlib.pyplot as plt # Get Iran admin boundry feature collection. admin_poly = (ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1") .filter(ee.Filter.eq('ADM0_NAME' , 'Iran (Islamic Republic of)'))); # Get S5P NO2 collection. col = (ee.ImageCollection("COPERNICUS/S5P/NRTI/L3_NO2") .filterBounds(admin_poly.geometry()) .filterDate('2020-09-01', '2021-01-01') .select('tropospheric_NO2_column_number_density')); # Calculate S5P NO2 collection mean. mean2020 = col.mean(); # Reproject the data. band = mean2020.reproject(**{'crs': col.first().projection().crs(), 'scale': 4000}) # Convert NO2 data to RGB visualization. vis_img = band.visualize(**{ 'min': 0, 'max': 0.000096, 'palette': ['00007F', '002AFF', '00D4FF', '7FFF7F', 'FFD400', 'FF2A00', '7F0000'] }); # Convert Iran admin boundry feature collection to a raster w/ state outlines. admin_raster = (ee.Image().byte().paint(**{ 'featureCollection': admin_poly, 'color': '000000', 'width': 2 })) # Overlay the Iran raster state outlines on the NO2 visualization. vis_img = vis_img.blend(admin_raster).clipToCollection(admin_poly) # Get final visualization thumbnail URL. url = vis_img.getThumbURL({'dimensions': 1024, 'region': admin_poly.geometry()}) # Get image content from the URL. response = requests.get(url) img = Image.open(BytesIO(response.content)) # Plot the image with matplotlib. plt.imshow(img) plt.show()
Hi dear @jdbcode
I do not know how to thank you, I have always done my job with your help and great tips, whether on GateHub or other sites, you answer everyone's questions very well and honestly,
I wrote more than a hundred lines of code to reach the result you wrote :)))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Mohammadreza20 If you are looking to just visualize the NO2 data with Iran state overlay in Python with matplotlib, you can do it all in server-side Earth Engine - you just transfer final visualization to Python client for plotting (regarding non-EE libraries for overlay, I'm not sure):