Last active
March 5, 2021 19:45
-
-
Save giswqs/e85b0371bc3cd15ff6ccd5adfa9643d7 to your computer and use it in GitHub Desktop.
copy properties
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
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import os\nimport ee\nimport geemap\n\nout_dir = os.path.join(os.path.expanduser(\"~\"), 'Downloads')\nif not os.path.exists(out_dir):\n os.makedirs(out_dir)\nMap = geemap.Map()\nMap.basemap_demo()\nMap\n\n", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/plain": "Map(center=[40, -100], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=(T…", | |
"application/vnd.jupyter.widget-view+json": { | |
"version_major": 2, | |
"version_minor": 0, | |
"model_id": "92f501856d9a4290b08f9817f0217c2c" | |
} | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "start = ee.Date('2018-01-01')\nend = ee.Date('2020-12-31')\nLS_collection_initial = ee.ImageCollection(\"LANDSAT/LC08/C01/T1_SR\").filterDate(start, end).filter(ee.Filter.Or(\n ee.Filter.And(ee.Filter.eq('WRS_PATH', 39),\n ee.Filter.eq('WRS_ROW', 32)),\n ee.Filter.And(ee.Filter.eq('WRS_PATH', 39),\n ee.Filter.eq('WRS_ROW', 31)))).filter(ee.Filter.lt('CLOUD_COVER', 15)) \\\n.filter(ee.Filter.calendarRange(4, 10, 'month'))\n\nmetadata_col = ee.ImageCollection(\"LANDSAT/LC08/C01/T1_SR\").filterDate(start, end).filter(ee.Filter.Or(\n ee.Filter.And(ee.Filter.eq('WRS_PATH', 39),\n ee.Filter.eq('WRS_ROW', 32)))).filter(ee.Filter.lt('CLOUD_COVER', 15)) \\\n.filter(ee.Filter.calendarRange(4, 10, 'month'))\n", | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "LS_collection_initial.size().getInfo()", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 4, | |
"data": { | |
"text/plain": "40" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "metadata_col.size().getInfo()", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": "23" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "##METHOD FOR MOSAICING BY DATE, MAKES IMAGE ID THE DATE OF IMAGE ACQUISITION\ndef mosaicByDate(imcol):\n imlist = imcol.toList(imcol.size())\n \n def imdate(im):\n return ee.Image(im).date().format(\"YYYY-MM-dd\")\n \n unique_dates = imlist.map(imdate).distinct()\n \n def dater(d):\n d = ee.Date(d)\n im = imcol.filterDate(d, d.advance(1, \"day\")).mosaic()##.map(clp)\n return im.set(\"system:time_start\", d.millis(), \n \"system:id\", d.format(\"YYYY-MM-dd\"))\n \n mosaic_imlist = unique_dates.map(dater)\n \n return ee.ImageCollection(mosaic_imlist)\n\nLS_collection = mosaicByDate(LS_collection_initial)", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "LS_collection.size().getInfo()", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 7, | |
"data": { | |
"text/plain": "23" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "seq = ee.List.sequence(0, LS_collection.size().subtract(1))", | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def copyProps(index):\n source = ee.Image(metadata_col.toList(metadata_col.size()).get(index))\n dest = ee.Image(LS_collection.toList(LS_collection.size()).get(index))\n image = ee.Image(source.copyProperties(dest))\n return image", | |
"execution_count": 14, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "final_col = ee.ImageCollection(seq.map(copyProps))", | |
"execution_count": 17, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"scrolled": false | |
}, | |
"cell_type": "code", | |
"source": "final_col.first().getInfo()", | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 18, | |
"data": { | |
"text/plain": "{'type': 'Image',\n 'bands': [{'id': 'B1',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B2',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B3',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B4',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B5',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B6',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B7',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B10',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'B11',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': -32768,\n 'max': 32767},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'sr_aerosol',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': 0,\n 'max': 255},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'pixel_qa',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': 0,\n 'max': 65535},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]},\n {'id': 'radsat_qa',\n 'data_type': {'type': 'PixelType',\n 'precision': 'int',\n 'min': 0,\n 'max': 65535},\n 'dimensions': [7891, 8001],\n 'crs': 'EPSG:32612',\n 'crs_transform': [30, 0, 166785, 0, -30, 4587315]}],\n 'id': 'LANDSAT/LC08/C01/T1_SR/LC08_039032_20180427',\n 'version': 1525596081811784,\n 'properties': {'IMAGE_QUALITY_TIRS': 9,\n 'CLOUD_COVER': 11.94,\n 'EARTH_SUN_DISTANCE': 1.006585,\n 'LANDSAT_ID': 'LC08_L1TP_039032_20180427_20180502_01_T1',\n 'system:footprint': {'type': 'LinearRing',\n 'coordinates': [[-112.29603605920809, 40.65526804836501],\n [-112.27985420032194, 40.70303657654413],\n [-112.23074049277939, 40.84785989063591],\n [-112.18398194052321, 40.98536434006351],\n [-112.44254572409946, 41.03544357741646],\n [-113.755327735972, 41.279562294804904],\n [-114.19064244466176, 41.3567859296924],\n [-114.33929250482579, 41.38272714080113],\n [-114.34499503618554, 41.36451058754035],\n [-114.5856575433867, 40.5760471617874],\n [-114.82879255038681, 39.76204130266753],\n [-114.8569183675285, 39.66538968250982],\n [-114.77300862331865, 39.650423692477936],\n [-112.86300764076296, 39.291375867287876],\n [-112.75631370118056, 39.27027653088733],\n [-112.75371840049199, 39.278125562934164],\n [-112.72985030104113, 39.35112581955692],\n [-112.70385730490933, 39.43050506722972],\n [-112.64140707108159, 39.62060979566252],\n [-112.62084672163022, 39.683065348875466],\n [-112.29603605920809, 40.65526804836501]]},\n 'CLOUD_COVER_LAND': 11.94,\n 'GEOMETRIC_RMSE_MODEL': 5.537,\n 'SR_APP_VERSION': 'LaSRC_1.3.0',\n 'SATELLITE': 'LANDSAT_8',\n 'SOLAR_AZIMUTH_ANGLE': 141.484863,\n 'IMAGE_QUALITY_OLI': 9,\n 'WRS_PATH': 39,\n 'system:time_start': 1524852814840,\n 'SENSING_TIME': '2018-04-27T18:13:34.8375679Z',\n 'ESPA_VERSION': '2_23_0_1a',\n 'SOLAR_ZENITH_ANGLE': 31.398262,\n 'WRS_ROW': 32,\n 'GEOMETRIC_RMSE_MODEL_Y': 4.27,\n 'LEVEL1_PRODUCTION_DATE': 1525267585000,\n 'GEOMETRIC_RMSE_MODEL_X': 3.526,\n 'system:asset_size': 670402770,\n 'PIXEL_QA_VERSION': 'generate_pixel_qa_1.6.0',\n 'system:index': 'LC08_039032_20180427'}}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"hide_input": false, | |
"varInspector": { | |
"window_display": false, | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"library": "var_list.py", | |
"delete_cmd_prefix": "del ", | |
"delete_cmd_postfix": "", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"library": "var_list.r", | |
"delete_cmd_prefix": "rm(", | |
"delete_cmd_postfix": ") ", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
] | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.5", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "copy properties", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment