Created
September 7, 2017 19:24
-
-
Save rutgerhofste/b5e3ff7862e727a17d1bc77c941bef97 to your computer and use it in GitHub Desktop.
ee question
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Calculate average PCRGlobWB supply using EE\n", | |
"\n", | |
"* Purpose of script: This script will calculate baseline supply based on runoff for 1960-2014 at 5min resolution\n", | |
"* Author: Rutger Hofste\n", | |
"* Kernel used: python27\n", | |
"* Date created: 20170830" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import os\n", | |
"import ee\n", | |
"import folium\n", | |
"from folium_gee import *\n", | |
"import subprocess" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"ee.Initialize()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"EE_INPUT_PATH = \"projects/WRI-Aquaduct/PCRGlobWB20V07/\"\n", | |
"\n", | |
"# Unfortunately specifying the dimensions caused the script to crash (internal error on Google's side) Specify scale instead.\n", | |
"\n", | |
"DIMENSION5MIN = {}\n", | |
"DIMENSION5MIN[\"x\"] = 4320\n", | |
"DIMENSION5MIN[\"y\"] = 2160\n", | |
"\n", | |
"INPUT_FILE_NAME_ANNUAL = \"global_historical_runoff_year_myear_5min_1958_2014\"\n", | |
"INPUT_FILE_NAME_MONTH = \"global_historical_runoff_month_mmonth_5min_1958_2014\"\n", | |
"\n", | |
"EE_IC_NAME_ANNUAL = \"global_historical_reducedmeanrunoff_year_myear_5min_1960_2014\"\n", | |
"EE_IC_NAME_MONTH = \"global_historical_reducedmeanrunoff_month_mmonth_5min_1960_2014\"\n", | |
"\n", | |
"EE_I_NAME_ANNUAL = EE_IC_NAME_ANNUAL\n", | |
"EE_I_NAME_MONTH = EE_IC_NAME_MONTH\n", | |
"\n", | |
"YEAR_MIN = 1960\n", | |
"YEAR_MAX = 2014\n", | |
"\n", | |
"ANNUAL_UNITS = \"m/year\"\n", | |
"MONTHLY_UNITS = \"m/month\"\n", | |
"\n", | |
"ANNUAL_EXPORTDESCRIPTION = \"reducedmeanrunoff_year\" #final format reducedmeanrunoff_yearY1960Y2014\n", | |
"MONTHLY_EXPORTDESCRIPTION = \"reducedmeanrunoff_month\" #final format reducedmeanrunoff_monthY1960Y2014M01\n", | |
"VERSION = 15\n", | |
"\n", | |
"MAXPIXELS =1e10" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The Standardized format to store assets on Earth Engine is EE_INPUT_PATH / EE_IC_NAME / EE_I_NAME and every image should have the property expertdescription that would allow to export the data to a table header. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"dimensions = \"%sx%s\" %(DIMENSION5MIN[\"x\"],DIMENSION5MIN[\"y\"])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4320x2160\n" | |
] | |
} | |
], | |
"source": [ | |
"print(dimensions)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"projection = ee.Image(ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_ANNUAL)).first()).projection().getInfo()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"crs = ee.Image(ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_ANNUAL)).first()).projection().crs().getInfo()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"crsTransform = ee.Image(ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_ANNUAL)).first()).projection().transform().getInfo()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{u'crs': u'EPSG:4326', u'type': u'Projection', u'transform': [0.0833333309780367, 0.0, -179.99999491255934, 0.0, -0.0833333309780367, 90.00000254430942]}\n" | |
] | |
} | |
], | |
"source": [ | |
"print(projection)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"scale = ee.Image(ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_ANNUAL)).first()).projection().nominalScale().getInfo()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def geometryFromProj(projection,dimensions):\n", | |
" coords = {}\n", | |
" coords[\"xmin\"]=projection[\"transform\"][2]\n", | |
" coords[\"xmax\"]=projection[\"transform\"][2]+dimensions[\"x\"]*projection[\"transform\"][0]\n", | |
" coords[\"ymin\"]=projection[\"transform\"][5]+dimensions[\"y\"]*projection[\"transform\"][4]\n", | |
" coords[\"ymax\"]=projection[\"transform\"][5]\n", | |
" geometry = ee.Geometry.Polygon(coords=[[coords[\"xmin\"], coords[\"ymin\"]], \n", | |
" [coords[\"xmax\"], coords[\"ymin\"]],\n", | |
" [coords[\"xmax\"], coords[\"ymax\"]],\n", | |
" [coords[\"xmin\"], coords[\"ymax\"]]],\n", | |
" proj= ee.Projection('EPSG:4326'),geodesic=False )\n", | |
" return geometry\n", | |
"\n", | |
"def reduceMean(ic,yearMin,yearMax):\n", | |
" dateFilterMin = ee.Filter.gte(\"year\",yearMin)\n", | |
" dateFilterMax = ee.Filter.lte(\"year\",yearMax)\n", | |
" filteredIc = ee.ImageCollection(ic.filter(dateFilterMin).filter(dateFilterMax))\n", | |
" reducedImage = ee.Image(filteredIc.reduce(ee.Reducer.mean()))\n", | |
" return reducedImage\n", | |
"\n", | |
"def exportToAsset(image,description,assetId,dimensions,region,maxPixels):\n", | |
" print(dimensions)\n", | |
" task = ee.batch.Export.image.toAsset(\n", | |
" image = ee.Image(image),\n", | |
" description = description,\n", | |
" assetId = assetId,\n", | |
" dimensions = dimensions,\n", | |
" #scale = scale,\n", | |
" crs = crs,\n", | |
" crsTransform = crsTransform,\n", | |
" #region = geometry.bounds().getInfo()['coordinates'][0],\n", | |
" maxPixels = maxPixels\n", | |
" )\n", | |
" print(assetId)\n", | |
" task.start()\n", | |
" return 1\n", | |
"\n", | |
"def addValidProperties(image,d):\n", | |
" nestedNewDict = {}\n", | |
" #remove non string or real properties\n", | |
" for nestedKey, nestedValue in d.iteritems():\n", | |
" if isinstance(nestedValue,str) or isinstance(nestedValue,int):\n", | |
" newDict[nestedKey] = nestedValue\n", | |
" else:\n", | |
" pass\n", | |
" #print(\"removing property: \",nestedKey )\n", | |
" image = ee.Image(image).set(nestedNewDict)\n", | |
" return image\n", | |
"\n", | |
"def createImageCollections(d):\n", | |
" command = (\"earthengine create collection %s%s\") %(EE_INPUT_PATH,d[\"ic_name\"])\n", | |
" response = subprocess.check_output(command,shell=True)\n", | |
" print(response)\n", | |
" \n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"geometry = geometryFromProj(projection,DIMENSION5MIN)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"d = {}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"d[\"annual\"] = {\"ic\": ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_ANNUAL)),\n", | |
" \"ic_name\": EE_IC_NAME_ANNUAL+\"V%0.2d\" %(VERSION) ,\n", | |
" \"image_name\": EE_IC_NAME_ANNUAL+\"V%0.2d\" %(VERSION),\n", | |
" \"temporal_resolution\":\"year\",\n", | |
" \"rangeMin\":YEAR_MIN,\n", | |
" \"rangeMax\":YEAR_MAX,\n", | |
" \"units\":ANNUAL_UNITS,\n", | |
" \"exportdescription\": ANNUAL_EXPORTDESCRIPTION + \"Y%sY%s\" %(YEAR_MIN,YEAR_MAX),\n", | |
" \"creation\":\"RutgerHofste_20170901_Python27\",\n", | |
" \"nodata_value\":-9999,\n", | |
" \"reducer\":\"mean\",\n", | |
" \"time_start\": \"%04d-%0.2d-%0.2d\" %(YEAR_MAX,12,1),\n", | |
" \"version\":VERSION\n", | |
" }" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"d[\"monthly\"] = {\"ic\": ee.ImageCollection(os.path.join(EE_INPUT_PATH,INPUT_FILE_NAME_MONTH)),\n", | |
" \"ic_name\": EE_IC_NAME_MONTH +\"V%0.2d\" %(VERSION),\n", | |
" \"temporal_resolution\":\"month\",\n", | |
" \"rangeMin\":YEAR_MIN,\n", | |
" \"rangeMax\":YEAR_MAX,\n", | |
" \"units\":MONTHLY_UNITS,\n", | |
" \"creation\":\"RutgerHofste_20170901_Python27\",\n", | |
" \"nodata_value\":-9999,\n", | |
" \"reducer\":\"mean\", \n", | |
" \"version\":VERSION,\n", | |
" # add month , image_name and exportdexription\n", | |
" }" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Asset projects/WRI-Aquaduct/PCRGlobWB20V07/global_historical_reducedmeanrunoff_month_mmonth_5min_1960_2014V15 already exists\n", | |
"\n", | |
"Asset projects/WRI-Aquaduct/PCRGlobWB20V07/global_historical_reducedmeanrunoff_year_myear_5min_1960_2014V15 already exists\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"for key, value in d.iteritems():\n", | |
" createImageCollections(value)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4320x2160\n", | |
"projects/WRI-Aquaduct/PCRGlobWB20V07/global_historical_reducedmeanrunoff_month_mmonth_5min_1960_2014V15/global_historical_reducedmeanrunoff_month_mmonth_5min_1960_2014M01V15\n" | |
] | |
}, | |
{ | |
"ename": "EEException", | |
"evalue": "Malformed JSON: 'PARAM_MT[\"Affine\", \n PARAMETER[\"num_row\", 3], \n PARAMETER[\"num_col\", 3], \n PARAMETER[\"elt_0_0\", 0.0833333309780367], \n PARAMETER[\"elt_0_2\", -179.99999491255934], \n PARAMETER[\"elt_1_1\", -0.0833333309780367], \n PARAMETER[\"elt_1_2\", 90.00000254430942]]'.", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mEEException\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-17-844d9bff3744>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0mvalidImage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0maddValidProperties\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreducedImage\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0massetId\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mEE_INPUT_PATH\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mnewDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"ic_name\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"/\"\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mnewDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"image_name\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 20\u001b[0;31m \u001b[0mexportToAsset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidImage\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"exportdescription\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"V%s\"\u001b[0m \u001b[0;34m%\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnewDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"version\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0massetId\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdimensions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mgeometry\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mMAXPIXELS\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 21\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m<ipython-input-11-1e9ed77a567b>\u001b[0m in \u001b[0;36mexportToAsset\u001b[0;34m(image, description, assetId, dimensions, region, maxPixels)\u001b[0m\n\u001b[1;32m 33\u001b[0m )\n\u001b[1;32m 34\u001b[0m \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0massetId\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 35\u001b[0;31m \u001b[0mtask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 36\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/opt/anaconda3/envs/python27/lib/python2.7/site-packages/ee/batch.pyc\u001b[0m in \u001b[0;36mstart\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 71\u001b[0m raise ee_exception.EEException(\n\u001b[1;32m 72\u001b[0m 'Task config must be specified for tasks to be started.')\n\u001b[0;32m---> 73\u001b[0;31m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartProcessing\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 74\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mstatus\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/opt/anaconda3/envs/python27/lib/python2.7/site-packages/ee/data.pyc\u001b[0m in \u001b[0;36mstartProcessing\u001b[0;34m(taskId, params)\u001b[0m\n\u001b[1;32m 536\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 537\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'id'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtaskId\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 538\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0msend_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/processingrequest'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 539\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 540\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/opt/anaconda3/envs/python27/lib/python2.7/site-packages/ee/data.pyc\u001b[0m in \u001b[0;36msend_\u001b[0;34m(path, params, opt_method, opt_raw)\u001b[0m\n\u001b[1;32m 781\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mee_exception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEEException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Invalid JSON: %s'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mcontent\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 782\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'error'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mjson_content\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 783\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mee_exception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEEException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mjson_content\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'error'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'message'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 784\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'data'\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mcontent\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 785\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mee_exception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEEException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Malformed response: '\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcontent\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mEEException\u001b[0m: Malformed JSON: 'PARAM_MT[\"Affine\", \n PARAMETER[\"num_row\", 3], \n PARAMETER[\"num_col\", 3], \n PARAMETER[\"elt_0_0\", 0.0833333309780367], \n PARAMETER[\"elt_0_2\", -179.99999491255934], \n PARAMETER[\"elt_1_1\", -0.0833333309780367], \n PARAMETER[\"elt_1_2\", 90.00000254430942]]'." | |
] | |
} | |
], | |
"source": [ | |
"newDict = {}\n", | |
"for key, value in d.iteritems():\n", | |
" newDict[key] = value\n", | |
" reducedImage = reduceMean(value[\"ic\"],YEAR_MIN,YEAR_MAX)\n", | |
" if value[\"temporal_resolution\"] == \"year\":\n", | |
" reducedImage = reduceMean(value[\"ic\"],value[\"rangeMin\"],newDict[key][\"rangeMax\"])\n", | |
" validImage = addValidProperties(reducedImage,value)\n", | |
" assetId = EE_INPUT_PATH+newDict[key][\"ic_name\"]+\"/\"+newDict[key][\"image_name\"]\n", | |
" exportToAsset(validImage,newDict[key][\"exportdescription\"]+\"V%s\"%(newDict[key][\"version\"]),assetId,dimensions,geometry,MAXPIXELS)\n", | |
" \n", | |
" if value[\"temporal_resolution\"] == \"month\":\n", | |
" for month in range(1,2):\n", | |
" newDict[key][\"month\"] = month\n", | |
" newDict[key][\"image_name\"] = EE_IC_NAME_MONTH +\"M%0.2dV%0.2d\" %(month,VERSION)\n", | |
" newDict[key][\"exportdescription\"] = ANNUAL_EXPORTDESCRIPTION + \"Y%sY%sM%0.d\" %(YEAR_MIN,YEAR_MAX,month)\n", | |
" \n", | |
" reducedImage = reduceMean(value[\"ic\"],newDict[key][\"rangeMin\"],newDict[key][\"rangeMax\"])\n", | |
" validImage = addValidProperties(reducedImage,value)\n", | |
" assetId = EE_INPUT_PATH+newDict[key][\"ic_name\"]+\"/\"+newDict[key][\"image_name\"]\n", | |
" exportToAsset(validImage,value[\"exportdescription\"]+\"V%s\" %(newDict[key][\"version\"]),assetId,dimensions,geometry,MAXPIXELS) \n", | |
" pass\n", | |
" \n", | |
" \n", | |
" \n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 27", | |
"language": "python", | |
"name": "python27" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment