Created
June 1, 2023 19:56
-
-
Save jdbcode/92b803ea6b3f40aeee2c2cf748556622 to your computer and use it in GitHub Desktop.
annual_modis_cloud_fraction.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyPvgOuG36HwyuHBTmnjFMRd", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/jdbcode/92b803ea6b3f40aeee2c2cf748556622/annual_modis_cloud_fraction.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "f9OPbuCGergr" | |
}, | |
"outputs": [], | |
"source": [ | |
"!pip install -q geemap" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import ee\n", | |
"import geemap" | |
], | |
"metadata": { | |
"id": "VBFEiHVne1tm" | |
}, | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"land = ee.Image('MERIT/DEM/v1_0_3').select(0).mask()\n", | |
"\n", | |
"modis = (ee.ImageCollection(\"MODIS/061/MOD09GA\")\n", | |
" .filterDate('2020-01-01', '2021-01-01'))\n", | |
"\n", | |
"def getClouds(img):\n", | |
" cloud = img.select('state_1km').bitwiseAnd(int('1', 2)).rename('cloud')\n", | |
" mask = cloud.mask().rename('mask')\n", | |
" return img.select().addBands([cloud, mask])\n", | |
"\n", | |
"\n", | |
"sum = modis.map(getClouds).sum().updateMask(land)\n", | |
"cloud_fraction = sum.select('cloud').divide(sum.select('mask'))\n", | |
"\n", | |
"proj = ee.Projection(\n", | |
" 'PROJCS[\"World_Robinson\",' +\n", | |
" 'GEOGCS[\"GCS_WGS_1984\",' +\n", | |
" 'DATUM[\"WGS_1984\",' +\n", | |
" 'SPHEROID[\"WGS_1984\",6378137,298.257223563]],' +\n", | |
" 'PRIMEM[\"Greenwich\",0],' +\n", | |
" 'UNIT[\"Degree\",0.017453292519943295]],' +\n", | |
" 'PROJECTION[\"Robinson\"],' +\n", | |
" 'UNIT[\"Meter\",1]]'\n", | |
")\n", | |
"\n", | |
"cloud_fraction_rob = cloud_fraction.changeProj(proj, 'EPSG:3857')\n", | |
"\n", | |
"m = geemap.Map(**{'height': '900px'})\n", | |
"m.addLayer(ee.Image(60), {'min': 0, 'max': 255})\n", | |
"m.addLayer(\n", | |
" cloud_fraction_rob, \n", | |
" {'min': 0, 'max': 0.9, 'palette': ['040613', '292851', '3f4b96',\n", | |
" '427bb7', '61a8c7', '9cd4da', 'eafdfd']},\n", | |
" 'cloudFraction [0,1]')" | |
], | |
"metadata": { | |
"id": "6W2oPexHfDGF" | |
}, | |
"execution_count": 12, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment