├── docs ├── msscvm_demo_01.png ├── make_readme.md ├── guide.md └── jsdoc.md ├── CHANGELOG.md ├── LICENSE.md ├── README.md └── msslib.js /docs/msscvm_demo_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gee-community/msslib/main/docs/msscvm_demo_01.png -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #### 0.1.2 2 | 3 | - Added tasseled cap yellowness index as an output band of the `addTc` function. 4 | 5 | #### 0.1.1 6 | 7 | - Fixed issue with MSScvm cloud shadow identification. Topographic correction of 8 | NIR band was being set to integer, but needs to be float. The result was that 9 | the dark pixel layer was identifying the entire image as dark, so any pixel 10 | intersecting the cloud projection layer was considered cloud shadow. 11 | 12 | #### 0.1.0 13 | 14 | Initial release 15 | -------------------------------------------------------------------------------- /docs/make_readme.md: -------------------------------------------------------------------------------- 1 | # Node.js jsdoc-to-markdown setup for project 2 | 3 | 1. Make sure Node.js is [installed](https://nodejs.org/en/download/). 4 | 5 | 2. Open Node.js command prompt. 6 | 7 | 3. cd to project directory. 8 | 9 | 4. Install jsdoc-to-markdown. 10 | 11 | ``` 12 | npm install --save-dev jsdoc-to-markdown 13 | ``` 14 | 15 | # Generate README.md from guide.md and module JSDoc markup. 16 | 17 | 1. Copy and paste the .js code w/ JSDoc markup to a module.js file. 18 | 19 | 2. Open Node.js command prompt. 20 | 21 | 3. cd to project directory. 22 | 23 | 4. Execute the jsdoc2md command and pipe result to a file. 24 | 25 | ``` 26 | npx jsdoc2md msslib.js > jsdoc.md 27 | ``` 28 | 29 | 5. Find/replace ## > ### and adjust level for Constants and Functions. 30 | 31 | ``` 32 | powershell -Command "(Get-Content jsdoc.md) -replace '##', '###' | Out-File -encoding ASCII jsdoc.md" 33 | 34 | powershell -Command "(Get-Content jsdoc.md) -replace '### Constants', '#### Constants' -replace '### Functions', '#### Functions' | Out-File -encoding ASCII jsdoc.md" 35 | 36 | powershell -Command "(Get-Content jsdoc.md) -replace [RegEx]::Escape('???'), [RegEx]::Escape('>') | Out-File -encoding ASCII jsdoc.md" 37 | ``` 38 | 39 | 6. Concatenate the guide and the jsdoc. 40 | 41 | ``` 42 | powershell -Command "Get-Content guide.md, jsdoc.md | Set-Content README.md" 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/guide.md: -------------------------------------------------------------------------------- 1 | # msslib 2 | 3 | The aim of `msslib` is to make it easy to work with Landsat MSS data in Earth 4 | Engine. It assembles image collections across the five satellites that carried 5 | the MSS sensor, filters images for quality, calculates TOA reflectance, and 6 | calculates the MSScvm cloud mask. 7 | 8 | ## Guide 9 | 10 | ### Module import 11 | 12 | Include the following line at the top of every script to import the library. 13 | 14 | ```js 15 | var msslib = require('users/jstnbraaten/modules:msslib/msslib.js'); 16 | ``` 17 | 18 | ### Example workflow 19 | 20 | This example demonstrates how to assemble an MSS image collection, view 21 | thumbnails to assess quality, reassemble collection to remove bad images, 22 | transform the images to TOA reflectance, add an NDVI band, and apply QA and 23 | cloud/shadow masks. 24 | 25 | Import the `msslib` module. 26 | 27 | ```js 28 | var msslib = require('users/jstnbraaten/modules:msslib/msslib.js'); 29 | ``` 30 | 31 | Get an MSS image collection filtered by region and day of year, as well as 32 | default settings for cloud and RMSE. 33 | 34 | ```js 35 | var mssDnCol = msslib.getCol({ 36 | aoi: ee.Geometry.Point([-122.239, 44.018]), 37 | doyRange: [170, 240] 38 | }); 39 | ``` 40 | 41 | View image thumbnails to get a sense for quality. 42 | 43 | ```js 44 | msslib.viewThumbnails(mssDnCol); 45 | ``` 46 | 47 | Retrieve an image collection again, but this time exclude bad images identified 48 | previously. 49 | 50 | ```js 51 | var mssDnCol = msslib.getCol({ 52 | aoi: ee.Geometry.Point([-122.239, 44.018]), 53 | doyRange: [170, 240], 54 | excludeIds: ['LM10480291974234GDS03', 'LM20490291975185GDS03'] 55 | }); 56 | ``` 57 | 58 | Convert the collection to top of atmosphere reflectance. 59 | 60 | ```js 61 | var mssToaCol = mssDnCol.map(msslib.calcToa); 62 | ``` 63 | 64 | Add the NDVI transformation as a band to all images in the collection. 65 | 66 | ```js 67 | mssToaCol = mssToaCol.map(msslib.addNdvi); 68 | ``` 69 | 70 | Apply the MSS clear-view-mask 71 | ([MSScvm](https://jdbcode.github.io/MSScvm/index.html)) to all images in the 72 | collection to remove clouds and cloud shadows. 73 | 74 | ```js 75 | mssToaCol = mssToaCol.map(msslib.applyMsscvm); 76 | ``` 77 | 78 | Apply QA band to all images in the collection. 79 | 80 | ```js 81 | mssToaCol = mssToaCol.map(msslib.applyQaMask); 82 | ``` 83 | 84 | ## Components 85 | 86 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /docs/jsdoc.md: -------------------------------------------------------------------------------- 1 | #### Constants 2 | 3 |
4 |
visDn : Object
5 |

A dictionary of false color visualization parameters for MSS DN images.

6 |
7 |
visRad : Object
8 |

A dictionary of false color visualization parameters for MSS radiance images.

9 |
10 |
visToa : Object
11 |

A dictionary of false color visualization parameters for MSS TOA reflectance 12 | images.

13 |
14 |
visNdvi : Object
15 |

A dictionary of visualization parameters for MSS NDVI images.

16 |
17 |
18 | 19 | #### Functions 20 | 21 |
22 |
getWrs1GranuleGeom(granuleId) > ee.Dictionary
23 |

Get the geometry for a given WRS-1 granule. Returns a dictionary with three 24 | elements: 'granule' a ee.Feature, granule 'centroid' a ee.Geometry, and 25 | granule 'bounds' ee.Geometry with a 40 km buffer. Note that it will only 26 | return results for granules that intersect land on the descending path.

27 |
28 |
getCol(params) > ee.ImageCollection
29 |

Assembles a Landsat MSS image collection from USGS Collection 1 T1 and T2 30 | images acquired by satellites 1-5. Removes L1G images and images without a 31 | complete set of reflectance bands. Additional default and optional filtering 32 | criteria are applied, including by bounds, geometric error, cloud cover, 33 | year, and day of year. All image bands are named consistently: 34 | ['green', 'red', 'red_edge', 'nir', 'BQA']. Adds 'wrs' property to all images 35 | designating them as 'WRS-1' or 'WRS-2'.

36 |
37 |
viewThumbnails(col, params)
38 |

Prints image collection thumbnails to the console with accompanying image 39 | IDs for use in quickly evaluating a collection. The image IDs can be recorded 40 | and used as entries in the params.excludeIds list of the msslib.getCol() 41 | function to exclude the given image(s).

42 |
43 |
calcRad(img) > ee.Image
44 |

Converts DN values to radiance.

45 |
46 |
calcToa(img) > ee.Image
47 |

Converts DN values to TOA reflectance.

48 |
49 |
addNdvi(img) > ee.Image
50 |

Adds NDVI transformation as a band ('ndvi') to the input image.

51 |
52 |
addQaMask(img) > ee.Image
53 |

Adds the 'BQA' quality band as mask band ('BQA_mask') indicating good (1) and 54 | bad (0) pixels. Learn more about the 'BQA' band.

55 |
56 |
applyQaMask(img) > ee.Image
57 |

Applies the 'BQA' quality band to an image as a mask. It masks out cloud 58 | pixels and those exhibiting radiometric saturation, as well pixels associated 59 | with missing data. Cloud identification is limited to mostly thick cumulus 60 | clouds; note that snow and very bright surface features are often mislabeled 61 | as cloud. Radiometric saturation in MSS images usually manifests as entire 62 | or partial image pixel rows being highly biased toward high values in a 63 | single band, which when visualized, can appear as tinted red, green, or 64 | blue. Learn more about the 'BQA' band.

65 |
66 |
addMsscvm(img) > ee.Image
67 |

Adds the MSScvm band ('msscvm') to the input image. Value 0 designates pixels 68 | as clear, 1 as clouds, and 2 as shadows. Learn about MSScvm.

69 |
70 |
applyMsscvm(img) > ee.Image
71 |

Applies the MSScvm mask to the input image, i.e., pixels identified as cloud 72 | or cloud shadow are masked out. Learn about MSScvm.

73 |
74 |
75 | 76 | 77 | 78 | ### visDn : Object 79 | A dictionary of false color visualization parameters for MSS DN images. 80 | 81 | **Kind**: global constant 82 | **Example** 83 | ```js 84 | // Get an MSS image. 85 | var mssDnImg = msslib.getCol({ 86 | aoi: ee.Geometry.Point([-122.239, 44.018]), 87 | yearRange: [1987, 1987], 88 | doyRange: [170, 240], 89 | wrs: '2' 90 | }).first(); 91 | 92 | // Use with Map.addLayer(). 93 | Map.centerObject(mssDnImg, 8); 94 | Map.addLayer(mssDnImg, msslib.visDn, 'From Map.addLayer()'); 95 | 96 | // Use with ee.Image.visualize(). 97 | var visImg = mssDnImg.visualize(msslib.visDn); 98 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 99 | ``` 100 | 101 | 102 | ### visRad : Object 103 | A dictionary of false color visualization parameters for MSS radiance images. 104 | 105 | **Kind**: global constant 106 | **Example** 107 | ```js 108 | // Get an MSS image. 109 | var mssDnImg = msslib.getCol({ 110 | aoi: ee.Geometry.Point([-122.239, 44.018]), 111 | yearRange: [1987, 1987], 112 | doyRange: [170, 240], 113 | wrs: '2' 114 | }).first(); 115 | 116 | // Convert DN to radiance. 117 | var mssRadImg = msslib.calcRad(mssDnImg); 118 | 119 | // Use with Map.addLayer(). 120 | Map.centerObject(mssRadImg, 8); 121 | Map.addLayer(mssRadImg, msslib.visRad, 'From Map.addLayer()'); 122 | 123 | // Use with ee.Image.visualize(). 124 | var visImg = mssRadImg.visualize(msslib.visRad); 125 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 126 | ``` 127 | 128 | 129 | ### visToa : Object 130 | A dictionary of false color visualization parameters for MSS TOA reflectance 131 | images. 132 | 133 | **Kind**: global constant 134 | **Example** 135 | ```js 136 | // Get an MSS image. 137 | var mssDnImg = msslib.getCol({ 138 | aoi: ee.Geometry.Point([-122.239, 44.018]), 139 | yearRange: [1987, 1987], 140 | doyRange: [170, 240], 141 | wrs: '2' 142 | }).first(); 143 | 144 | // Convert DN to TOA. 145 | var mssToaImg = msslib.calcToa(mssDnImg); 146 | 147 | // Use with Map.addLayer(). 148 | Map.centerObject(mssToaImg, 8); 149 | Map.addLayer(mssToaImg, msslib.visToa, 'From Map.addLayer()'); 150 | 151 | // Use with ee.Image.visualize(). 152 | var visImg = mssToaImg.visualize(msslib.visToa); 153 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 154 | ``` 155 | 156 | 157 | ### visNdvi : Object 158 | A dictionary of visualization parameters for MSS NDVI images. 159 | 160 | **Kind**: global constant 161 | **Example** 162 | ```js 163 | // Get an MSS image. 164 | var mssDnImg = msslib.getCol({ 165 | aoi: ee.Geometry.Point([-122.239, 44.018]), 166 | yearRange: [1987, 1987], 167 | doyRange: [170, 240], 168 | wrs: '2' 169 | }).first(); 170 | 171 | // Convert DN to TOA and add NDVI band. 172 | var mssNdviImg = msslib.addNdvi(msslib.calcToa(mssDnImg)); 173 | 174 | // Use with Map.addLayer(). 175 | Map.centerObject(mssNdviImg, 8); 176 | Map.addLayer(mssNdviImg, msslib.visNdvi, 'From Map.addLayer()'); 177 | 178 | // Use with ee.Image.visualize(). 179 | var visImg = mssNdviImg.visualize(msslib.visNdvi); 180 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 181 | ``` 182 | 183 | 184 | ### getWrs1GranuleGeom(granuleId) > ee.Dictionary 185 | Get the geometry for a given WRS-1 granule. Returns a dictionary with three 186 | elements: 'granule' a `ee.Feature`, granule 'centroid' a `ee.Geometry`, and 187 | granule 'bounds' `ee.Geometry` with a 40 km buffer. Note that it will only 188 | return results for granules that intersect land on the descending path. 189 | 190 | **Kind**: global function 191 | 192 | | Param | Type | Description | 193 | | --- | --- | --- | 194 | | granuleId | string | The PPPRRR granule ID. | 195 | 196 | **Example** 197 | ```js 198 | // Get granule geometry for WRS-1 path/row granule 049030. 199 | var granuleGeom = msslib.getWrs1GranuleGeom('049030'); 200 | 201 | // Print the results. 202 | print(granuleGeom); 203 | 204 | // Display the results. 205 | var granule = ee.Feature(granuleGeom.get('granule')); 206 | var centroid = ee.Geometry(granuleGeom.get('centroid')); 207 | var bounds = ee.Geometry(granuleGeom.get('bounds')); 208 | Map.centerObject(centroid, 8); 209 | Map.addLayer(bounds, {color: 'blue'}, 'Bounds'); 210 | Map.addLayer(granule, {color: 'black'}, 'Granule'); 211 | Map.addLayer(centroid, {color: 'red'}, 'Centroid'); 212 | ``` 213 | 214 | 215 | ### getCol(params) > ee.ImageCollection 216 | Assembles a Landsat MSS image collection from USGS Collection 1 T1 and T2 217 | images acquired by satellites 1-5. Removes L1G images and images without a 218 | complete set of reflectance bands. Additional default and optional filtering 219 | criteria are applied, including by bounds, geometric error, cloud cover, 220 | year, and day of year. All image bands are named consistently: 221 | ['green', 'red', 'red_edge', 'nir', 'BQA']. Adds 'wrs' property to all images 222 | designating them as 'WRS-1' or 'WRS-2'. 223 | 224 | **Kind**: global function 225 | **Returns**: ee.ImageCollection - An MSS image collection. 226 | 227 | | Param | Type | Default | Description | 228 | | --- | --- | --- | --- | 229 | | params | Object | | An object that provides filtering parameters. | 230 | | [params.aoi] | ee.Geometry | | The geometry to filter images by intersection; those intersecting the geometry are included in the collection. | 231 | | [params.maxRmseVerify] | number | 0.5 | The maximum geometric RMSE of a given image allowed in the collection, provided in units of pixels (60 m), conditioned on the 'GEOMETRIC_RMSE_VERIFY' image property. | 232 | | [params.maxCloudCover] | number | 50 | The maximum cloud cover of a given image allowed in the collection, provided as a percent, conditioned on the 'CLOUD_COVER' image property. | 233 | | [params.wrs] | string | "1&2" | An indicator for what World Reference System types to allow in the collection. MSS images from Landsat satellites 1-3 use WRS-1, while 4-5 use WRS-2. Options include: '1' (WRS-1 only), '2' (WRS-2 only), and '1&2' (both WRS-1 and WRS-2). | 234 | | [params.yearRange] | Array | [1972, 2000] | An array with two integers that define the range of years to include in the collection. The first defines the start year (inclusive) and the second defines the end year (inclusive). Ex: [1972, 1990]. | 235 | | [params.doyRange] | Array | [1, 365] | An array with two integers that define the range of days to include in the collection. The first defines the start day of year (inclusive) and the second defines the end day of year (inclusive). Note that the start day can be less than the end day, which indicates that the day range crosses the new year. Ex: [180, 240] (dates for northern hemisphere summer images), [330, 90] (dates for southern hemisphere summer images). | 236 | | [params.excludeIds] | Array | | A list of image IDs to filter out of the image collection, given as the value of the image's 'LANDSAT_SCENE_ID' property. | 237 | 238 | **Example** 239 | ```js 240 | // Filter by geometry intersection, cloud cover, and geometric RMSE. 241 | var mssDnCol = msslib.getCol({ 242 | aoi: ee.Geometry.Point([-122.239, 44.018]), 243 | maxCloudCover: 25, 244 | maxRmseVerify: 0.25 245 | }); 246 | 247 | // Filter by geometry intersection, year range, and day of year. 248 | var mssDnCol = msslib.getCol({ 249 | aoi: ee.Geometry.Point([-122.239, 44.018]), 250 | yearRange: [1975, 1980], 251 | doyRange: [170, 240] 252 | }); 253 | 254 | // Filter by geometry intersection and exclude two images by ID. 255 | var mssDnCol = msslib.getCol({ 256 | aoi: ee.Geometry.Point([-122.239, 44.018]), 257 | excludeIds: ['LM10490291972246AAA04', 'LM10480291973113AAA02'] 258 | }); 259 | ``` 260 | 261 | 262 | ### viewThumbnails(col, params) 263 | Prints image collection thumbnails to the console with accompanying image 264 | IDs for use in quickly evaluating a collection. The image IDs can be recorded 265 | and used as entries in the `params.excludeIds` list of the `msslib.getCol()` 266 | function to exclude the given image(s). 267 | 268 | **Kind**: global function 269 | 270 | | Param | Type | Default | Description | 271 | | --- | --- | --- | --- | 272 | | col | ee.ImageCollection | | MSS DN image collection originating from the `msslib.getCol()` function. | 273 | | params | Object | | An object that provides visualization parameters. | 274 | | [params.unit] | string | "toa" | An indicator for what units to use in the display image. Use: 'dn' (raw digital number), 'rad' (radiance), or 'toa' (TOA reflectance). The selected unit will be calculated on-the-fly. | 275 | | [params.display] | string | "nir\\|red\\|green" | An indicator for how to display the image thumbnail. Use 'nir\|red\|green' (RGB) or 'ndvi' (grayscale). Default visualization parameters for color stretch are applied. | 276 | | [params.visParams] | Object | | A custom visualization parameter dictionary as described [here](https://developers.google.com/earth-engine/image_visualization#mapVisParamTable). If set, overrides the `params.display` option and default. | 277 | 278 | **Example** 279 | ```js 280 | // Get an MSS image collection. 281 | var mssDnCol = msslib.getCol({ 282 | aoi: ee.Geometry.Point([-122.239, 44.018]), 283 | doyRange: [170, 240] 284 | }); 285 | 286 | // View DN image thumbnails in the console. 287 | viewThumbnails(mssDnCol, {unit: 'dn'}); 288 | ``` 289 | 290 | 291 | ### calcRad(img) > ee.Image 292 | Converts DN values to radiance. 293 | 294 | **Kind**: global function 295 | 296 | | Param | Type | Description | 297 | | --- | --- | --- | 298 | | img | ee.Image | MSS DN image originating from the `msslib.getCol()` function. | 299 | 300 | **Example** 301 | ```js 302 | // Get an MSS image collection. 303 | var mssDnCol = msslib.getCol({ 304 | aoi: ee.Geometry.Point([-122.239, 44.018]), 305 | doyRange: [170, 240] 306 | }); 307 | 308 | // Convert DN to radiance for a single image. 309 | var mssRadImg = msslib.calcRad(mssDnCol.first()); 310 | 311 | // Convert DN to radiance for all images in a collection. 312 | var mssRadCol = mssDnCol.map(msslib.calcRad); 313 | ``` 314 | 315 | 316 | ### calcToa(img) > ee.Image 317 | Converts DN values to TOA reflectance. 318 | 319 | **Kind**: global function 320 | 321 | | Param | Type | Description | 322 | | --- | --- | --- | 323 | | img | ee.Image | MSS DN image originating from the `msslib.getCol()` function. | 324 | 325 | **Example** 326 | ```js 327 | // Get an MSS image collection. 328 | var mssDnCol = msslib.getCol({ 329 | aoi: ee.Geometry.Point([-122.239, 44.018]), 330 | doyRange: [170, 240] 331 | }); 332 | 333 | // Convert DN to TOA for a single image. 334 | var mssToaImg = msslib.calcToa(mssDnCol.first()); 335 | 336 | // Convert DN to TOA for all images in a collection. 337 | var mssToaCol = mssDnCol.map(msslib.calcToa); 338 | ``` 339 | 340 | 341 | ### addNdvi(img) > ee.Image 342 | Adds NDVI transformation as a band ('ndvi') to the input image. 343 | 344 | **Kind**: global function 345 | 346 | | Param | Type | Description | 347 | | --- | --- | --- | 348 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. It is recommended that the image be in units of radiance or TOA reflectance (see `msslib.calcRad()` and `msslib.calcToa()`). | 349 | 350 | **Example** 351 | ```js 352 | // Get an MSS image collection. 353 | var mssDnCol = msslib.getCol({ 354 | aoi: ee.Geometry.Point([-122.239, 44.018]), 355 | doyRange: [170, 240] 356 | }); 357 | 358 | // Convert DN to TOA for all images in a collection. 359 | var mssToaCol = mssDnCol.map(msslib.calcToa); 360 | 361 | // Add NDVI band to each image in a collection. 362 | var mssToaColNdvi = mssToaCol.map(msslib.addNdvi); 363 | ``` 364 | 365 | 366 | ### addQaMask(img) > ee.Image 367 | Adds the 'BQA' quality band as mask band ('BQA_mask') indicating good (1) and 368 | bad (0) pixels. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 369 | 370 | **Kind**: global function 371 | 372 | | Param | Type | Description | 373 | | --- | --- | --- | 374 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. | 375 | 376 | **Example** 377 | ```js 378 | // Get an MSS image collection. 379 | var mssDnCol = msslib.getCol({ 380 | aoi: ee.Geometry.Point([-122.239, 44.018]), 381 | doyRange: [170, 240] 382 | }); 383 | 384 | // Select a single image. 385 | var mssDnImg = mssDnCol.filter( 386 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 387 | 388 | // Add BQA mask band to the single image. 389 | var mssDnImgQaMask = msslib.addQaMask(mssDnImg); 390 | 391 | // Display the results. 392 | Map.centerObject(mssDnImgQaMask, 9); 393 | Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image'); 394 | Map.addLayer(mssDnImgQaMask, { 395 | bands: ['BQA_mask'], 396 | min: 0, 397 | max: 1, 398 | palette: ['grey', 'green'] 399 | }, 'BQA mask'); 400 | 401 | // Add BQA mask band to all images in collection. 402 | var mssDnColQaMask = mssDnCol.map(msslib.addQaMask); 403 | print(mssDnColQaMask.limit(5)); 404 | ``` 405 | 406 | 407 | ### applyQaMask(img) > ee.Image 408 | Applies the 'BQA' quality band to an image as a mask. It masks out cloud 409 | pixels and those exhibiting radiometric saturation, as well pixels associated 410 | with missing data. Cloud identification is limited to mostly thick cumulus 411 | clouds; note that snow and very bright surface features are often mislabeled 412 | as cloud. Radiometric saturation in MSS images usually manifests as entire 413 | or partial image pixel rows being highly biased toward high values in a 414 | single band, which when visualized, can appear as tinted red, green, or 415 | blue. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 416 | 417 | **Kind**: global function 418 | 419 | | Param | Type | Description | 420 | | --- | --- | --- | 421 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. | 422 | 423 | **Example** 424 | ```js 425 | // Get an MSS image collection. 426 | var mssDnCol = msslib.getCol({ 427 | aoi: ee.Geometry.Point([-122.239, 44.018]), 428 | doyRange: [170, 240] 429 | }); 430 | 431 | // Select a single image. 432 | var mssDnImg = mssDnCol.filter( 433 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 434 | 435 | // Apply BQA mask to the single image. 436 | var mssDnImgQaMask = msslib.applyQaMask(mssDnImg); 437 | 438 | // Display the results. 439 | Map.centerObject(mssDnImgQaMask, 9); 440 | Map.setOptions('SATELLITE'); 441 | Map.addLayer(mssDnImg, msslib.visDn, 'DN image'); 442 | Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image masked'); 443 | 444 | // Apply BQA mask to all images in collection. 445 | var mssDnColQaMask = mssDnCol.map(msslib.applyQaMask); 446 | print(mssDnColQaMask.limit(5)); 447 | ``` 448 | 449 | 450 | ### addMsscvm(img) > ee.Image 451 | Adds the MSScvm band ('msscvm') to the input image. Value 0 designates pixels 452 | as clear, 1 as clouds, and 2 as shadows. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 453 | 454 | **Kind**: global function 455 | 456 | | Param | Type | Description | 457 | | --- | --- | --- | 458 | | img | ee.Image | MSS TOA image originating from `msslib.getCol()` and `msslib.calcToa()`. | 459 | 460 | **Example** 461 | ```js 462 | // Get an MSS image collection. 463 | var mssDnCol = msslib.getCol({ 464 | aoi: ee.Geometry.Point([-122.239, 44.018]), 465 | doyRange: [170, 240], 466 | yearRange: [1983, 1986], 467 | wrs: '2' 468 | }); 469 | 470 | // Convert DN to TOA. 471 | var mssToaCol = mssDnCol.map(msslib.calcToa); 472 | 473 | // Select a single image. 474 | var mssToaImg = mssToaCol.filter( 475 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 476 | 477 | // Add MSScvm band to the single image. 478 | var mssToaImgMsscvm = msslib.addMsscvm(mssToaImg); 479 | 480 | // Display the results. 481 | Map.centerObject(mssToaImgMsscvm, 9); 482 | Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image'); 483 | Map.addLayer(mssToaImgMsscvm, { 484 | bands: ['msscvm'], 485 | min: 0, 486 | max: 2, 487 | palette: ['27ae60', 'FFFFFF', '000000'] 488 | }, 'MSScmv'); 489 | 490 | // Add MSScvm band to all images in collection. 491 | var mssToaColMsscvm = mssToaCol.map(msslib.addMsscvm); 492 | print(mssToaColMsscvm.limit(5)); 493 | ``` 494 | 495 | 496 | ### applyMsscvm(img) > ee.Image 497 | Applies the MSScvm mask to the input image, i.e., pixels identified as cloud 498 | or cloud shadow are masked out. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 499 | 500 | **Kind**: global function 501 | 502 | | Param | Type | Description | 503 | | --- | --- | --- | 504 | | img | ee.Image | MSS TOA image originating from `msslib.getCol()` and `msslib.calcToa()`. | 505 | 506 | **Example** 507 | ```js 508 | // Get an MSS image collection. 509 | var mssDnCol = msslib.getCol({ 510 | aoi: ee.Geometry.Point([-122.239, 44.018]), 511 | doyRange: [170, 240], 512 | yearRange: [1983, 1986], 513 | wrs: '2' 514 | }); 515 | 516 | // Convert DN to TOA. 517 | var mssToaCol = mssDnCol.map(msslib.calcToa); 518 | 519 | // Select a single image. 520 | var mssToaImg = mssToaCol.filter( 521 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 522 | 523 | // Apply MSScvm to the single image. 524 | var mssToaImgMsscvm = msslib.applyMsscvm(mssToaImg); 525 | 526 | // Display the results. 527 | Map.centerObject(mssToaImgMsscvm, 9); 528 | Map.setOptions('SATELLITE'); 529 | Map.addLayer(mssToaImg, msslib.visToa, 'TOA image'); 530 | Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image masked'); 531 | 532 | // Apply MSScvm to all images in collection. 533 | var mssToaColMsscvm = mssToaCol.map(msslib.applyMsscvm); 534 | print(mssToaColMsscvm.limit(5)); 535 | ``` 536 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # msslib 2 | 3 | The aim of `msslib` is to make it easy to work with Landsat MSS data in Earth 4 | Engine. It assembles image collections across the five satellites that carried 5 | the MSS sensor, filters images for quality, calculates TOA reflectance, and 6 | calculates the [MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf) 7 | cloud mask. 8 | 9 | ![](/docs/msscvm_demo_01.png) 10 | 11 | ## Guide 12 | 13 | ### Module import 14 | 15 | Include the following line at the top of every script to import the library. 16 | 17 | ```js 18 | var msslib = require('users/jstnbraaten/modules:msslib/msslib.js'); 19 | ``` 20 | 21 | ### Example workflow 22 | 23 | This example demonstrates how to assemble an MSS image collection, view 24 | thumbnails to assess quality, reassemble collection to remove bad images, 25 | transform the images to TOA reflectance, add an NDVI band, and apply QA and 26 | cloud/shadow masks. 27 | 28 | Import the `msslib` module. 29 | 30 | ```js 31 | var msslib = require('users/jstnbraaten/modules:msslib/msslib.js'); 32 | ``` 33 | 34 | Get an MSS image collection filtered by region and day of year, as well as 35 | default settings for cloud and RMSE. 36 | 37 | ```js 38 | var mssDnCol = msslib.getCol({ 39 | aoi: ee.Geometry.Point([-122.239, 44.018]), 40 | doyRange: [170, 240] 41 | }); 42 | ``` 43 | 44 | View image thumbnails to get a sense for quality. 45 | 46 | ```js 47 | msslib.viewThumbnails(mssDnCol); 48 | ``` 49 | 50 | Retrieve an image collection again, but this time exclude bad images identified 51 | previously. 52 | 53 | ```js 54 | var mssDnCol = msslib.getCol({ 55 | aoi: ee.Geometry.Point([-122.239, 44.018]), 56 | doyRange: [170, 240], 57 | excludeIds: ['LM10480291974234GDS03', 'LM20490291975185GDS03'] 58 | }); 59 | ``` 60 | 61 | Convert the collection to top of atmosphere reflectance. 62 | 63 | ```js 64 | var mssToaCol = mssDnCol.map(msslib.calcToa); 65 | ``` 66 | 67 | Add the NDVI transformation as a band to all images in the collection. 68 | 69 | ```js 70 | mssToaCol = mssToaCol.map(msslib.addNdvi); 71 | ``` 72 | 73 | Apply the MSS clear-view-mask 74 | ([MSScvm](https://jdbcode.github.io/MSScvm/index.html)) to all images in the 75 | collection to remove clouds and cloud shadows. 76 | 77 | ```js 78 | mssToaCol = mssToaCol.map(msslib.applyMsscvm); 79 | ``` 80 | 81 | Apply QA band to all images in the collection. 82 | 83 | ```js 84 | mssToaCol = mssToaCol.map(msslib.applyQaMask); 85 | ``` 86 | 87 | ## Components 88 | 89 | #### Constants 90 | 91 |
92 |
visDn : Object
93 |

A dictionary of false color visualization parameters for MSS DN images.

94 |
95 |
visRad : Object
96 |

A dictionary of false color visualization parameters for MSS radiance images.

97 |
98 |
visToa : Object
99 |

A dictionary of false color visualization parameters for MSS TOA reflectance 100 | images.

101 |
102 |
visNdvi : Object
103 |

A dictionary of visualization parameters for MSS NDVI images.

104 |
105 |
106 | 107 | #### Functions 108 | 109 |
110 |
getWrs1GranuleGeom(granuleId) > ee.Dictionary
111 |

Get the geometry for a given WRS-1 granule. Returns a dictionary with three 112 | elements: 'granule' a ee.Feature, granule 'centroid' a ee.Geometry, and 113 | granule 'bounds' ee.Geometry with a 40 km buffer. Note that it will only 114 | return results for granules that intersect land on the descending path.

115 |
116 |
getCol(params) > ee.ImageCollection
117 |

Assembles a Landsat MSS image collection from USGS Collection 1 T1 and T2 118 | images acquired by satellites 1-5. Removes L1G images and images without a 119 | complete set of reflectance bands. Additional default and optional filtering 120 | criteria are applied, including by bounds, geometric error, cloud cover, 121 | year, and day of year. All image bands are named consistently: 122 | ['green', 'red', 'red_edge', 'nir', 'BQA']. Adds 'wrs' property to all images 123 | designating them as 'WRS-1' or 'WRS-2'.

124 |
125 |
viewThumbnails(col, params)
126 |

Prints image collection thumbnails to the console with accompanying image 127 | IDs for use in quickly evaluating a collection. The image IDs can be recorded 128 | and used as entries in the params.excludeIds list of the msslib.getCol() 129 | function to exclude the given image(s).

130 |
131 |
calcRad(img) > ee.Image
132 |

Converts DN values to radiance.

133 |
134 |
calcToa(img) > ee.Image
135 |

Converts DN values to TOA reflectance.

136 |
137 |
addNdvi(img) > ee.Image
138 |

Adds NDVI transformation as a band ('ndvi') to the input image.

139 |
140 |
addTc(img) > ee.Image
141 |

Adds Tasseled Cap indices brightness ('tcb'), greenness ('tcg'), yellowness 142 | ('tcy'), and angle ('tca') to the input image. See Kauth and Thomas, 1976

143 |
144 |
addQaMask(img) > ee.Image
145 |

Adds the 'BQA' quality band as mask band ('BQA_mask') indicating good (1) and 146 | bad (0) pixels. Learn more about the 'BQA' band.

147 |
148 |
applyQaMask(img) > ee.Image
149 |

Applies the 'BQA' quality band to an image as a mask. It masks out cloud 150 | pixels and those exhibiting radiometric saturation, as well pixels associated 151 | with missing data. Cloud identification is limited to mostly thick cumulus 152 | clouds; note that snow and very bright surface features are often mislabeled 153 | as cloud. Radiometric saturation in MSS images usually manifests as entire 154 | or partial image pixel rows being highly biased toward high values in a 155 | single band, which when visualized, can appear as tinted red, green, or 156 | blue. Learn more about the 'BQA' band.

157 |
158 |
addMsscvm(img) > ee.Image
159 |

Adds the MSScvm band ('msscvm') to the input image. Value 0 designates pixels 160 | as clear, 1 as clouds, and 2 as shadows. Learn about MSScvm.

161 |
162 |
applyMsscvm(img) > ee.Image
163 |

Applies the MSScvm mask to the input image, i.e., pixels identified as cloud 164 | or cloud shadow are masked out. Learn about MSScvm.

165 |
166 |
167 | 168 | 169 | 170 | ### visDn : Object 171 | A dictionary of false color visualization parameters for MSS DN images. 172 | 173 | **Kind**: global constant 174 | **Example** 175 | ```js 176 | // Get an MSS image. 177 | var mssDnImg = msslib.getCol({ 178 | aoi: ee.Geometry.Point([-122.239, 44.018]), 179 | yearRange: [1987, 1987], 180 | doyRange: [170, 240], 181 | wrs: '2' 182 | }).first(); 183 | 184 | // Use with Map.addLayer(). 185 | Map.centerObject(mssDnImg, 8); 186 | Map.addLayer(mssDnImg, msslib.visDn, 'From Map.addLayer()'); 187 | 188 | // Use with ee.Image.visualize(). 189 | var visImg = mssDnImg.visualize(msslib.visDn); 190 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 191 | ``` 192 | 193 | 194 | ### visRad : Object 195 | A dictionary of false color visualization parameters for MSS radiance images. 196 | 197 | **Kind**: global constant 198 | **Example** 199 | ```js 200 | // Get an MSS image. 201 | var mssDnImg = msslib.getCol({ 202 | aoi: ee.Geometry.Point([-122.239, 44.018]), 203 | yearRange: [1987, 1987], 204 | doyRange: [170, 240], 205 | wrs: '2' 206 | }).first(); 207 | 208 | // Convert DN to radiance. 209 | var mssRadImg = msslib.calcRad(mssDnImg); 210 | 211 | // Use with Map.addLayer(). 212 | Map.centerObject(mssRadImg, 8); 213 | Map.addLayer(mssRadImg, msslib.visRad, 'From Map.addLayer()'); 214 | 215 | // Use with ee.Image.visualize(). 216 | var visImg = mssRadImg.visualize(msslib.visRad); 217 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 218 | ``` 219 | 220 | 221 | ### visToa : Object 222 | A dictionary of false color visualization parameters for MSS TOA reflectance 223 | images. 224 | 225 | **Kind**: global constant 226 | **Example** 227 | ```js 228 | // Get an MSS image. 229 | var mssDnImg = msslib.getCol({ 230 | aoi: ee.Geometry.Point([-122.239, 44.018]), 231 | yearRange: [1987, 1987], 232 | doyRange: [170, 240], 233 | wrs: '2' 234 | }).first(); 235 | 236 | // Convert DN to TOA. 237 | var mssToaImg = msslib.calcToa(mssDnImg); 238 | 239 | // Use with Map.addLayer(). 240 | Map.centerObject(mssToaImg, 8); 241 | Map.addLayer(mssToaImg, msslib.visToa, 'From Map.addLayer()'); 242 | 243 | // Use with ee.Image.visualize(). 244 | var visImg = mssToaImg.visualize(msslib.visToa); 245 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 246 | ``` 247 | 248 | 249 | ### visNdvi : Object 250 | A dictionary of visualization parameters for MSS NDVI images. 251 | 252 | **Kind**: global constant 253 | **Example** 254 | ```js 255 | // Get an MSS image. 256 | var mssDnImg = msslib.getCol({ 257 | aoi: ee.Geometry.Point([-122.239, 44.018]), 258 | yearRange: [1987, 1987], 259 | doyRange: [170, 240], 260 | wrs: '2' 261 | }).first(); 262 | 263 | // Convert DN to TOA and add NDVI band. 264 | var mssNdviImg = msslib.addNdvi(msslib.calcToa(mssDnImg)); 265 | 266 | // Use with Map.addLayer(). 267 | Map.centerObject(mssNdviImg, 8); 268 | Map.addLayer(mssNdviImg, msslib.visNdvi, 'From Map.addLayer()'); 269 | 270 | // Use with ee.Image.visualize(). 271 | var visImg = mssNdviImg.visualize(msslib.visNdvi); 272 | Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 273 | ``` 274 | 275 | 276 | ### getWrs1GranuleGeom(granuleId) > ee.Dictionary 277 | Get the geometry for a given WRS-1 granule. Returns a dictionary with three 278 | elements: 'granule' a `ee.Feature`, granule 'centroid' a `ee.Geometry`, and 279 | granule 'bounds' `ee.Geometry` with a 40 km buffer. Note that it will only 280 | return results for granules that intersect land on the descending path. 281 | 282 | **Kind**: global function 283 | 284 | | Param | Type | Description | 285 | | --- | --- | --- | 286 | | granuleId | string | The PPPRRR granule ID. | 287 | 288 | **Example** 289 | ```js 290 | // Get granule geometry for WRS-1 path/row granule 049030. 291 | var granuleGeom = msslib.getWrs1GranuleGeom('049030'); 292 | 293 | // Print the results. 294 | print(granuleGeom); 295 | 296 | // Display the results. 297 | var granule = ee.Feature(granuleGeom.get('granule')); 298 | var centroid = ee.Geometry(granuleGeom.get('centroid')); 299 | var bounds = ee.Geometry(granuleGeom.get('bounds')); 300 | Map.centerObject(centroid, 8); 301 | Map.addLayer(bounds, {color: 'blue'}, 'Bounds'); 302 | Map.addLayer(granule, {color: 'black'}, 'Granule'); 303 | Map.addLayer(centroid, {color: 'red'}, 'Centroid'); 304 | ``` 305 | 306 | 307 | ### getCol(params) > ee.ImageCollection 308 | Assembles a Landsat MSS image collection from USGS Collection 1 T1 and T2 309 | images acquired by satellites 1-5. Removes L1G images and images without a 310 | complete set of reflectance bands. Additional default and optional filtering 311 | criteria are applied, including by bounds, geometric error, cloud cover, 312 | year, and day of year. All image bands are named consistently: 313 | ['green', 'red', 'red_edge', 'nir', 'BQA']. Adds 'wrs' property to all images 314 | designating them as 'WRS-1' or 'WRS-2'. 315 | 316 | **Kind**: global function 317 | **Returns**: ee.ImageCollection - An MSS image collection. 318 | 319 | | Param | Type | Default | Description | 320 | | --- | --- | --- | --- | 321 | | params | Object | | An object that provides filtering parameters. | 322 | | [params.aoi] | ee.Geometry | | The geometry to filter images by intersection; those intersecting the geometry are included in the collection. | 323 | | [params.maxRmseVerify] | number | 0.5 | The maximum geometric RMSE of a given image allowed in the collection, provided in units of pixels (60 m), conditioned on the 'GEOMETRIC_RMSE_VERIFY' image property. | 324 | | [params.maxCloudCover] | number | 50 | The maximum cloud cover of a given image allowed in the collection, provided as a percent, conditioned on the 'CLOUD_COVER' image property. | 325 | | [params.wrs] | string | "1&2" | An indicator for what World Reference System types to allow in the collection. MSS images from Landsat satellites 1-3 use WRS-1, while 4-5 use WRS-2. Options include: '1' (WRS-1 only), '2' (WRS-2 only), and '1&2' (both WRS-1 and WRS-2). | 326 | | [params.yearRange] | Array | [1972, 2000] | An array with two integers that define the range of years to include in the collection. The first defines the start year (inclusive) and the second defines the end year (inclusive). Ex: [1972, 1990]. | 327 | | [params.doyRange] | Array | [1, 365] | An array with two integers that define the range of days to include in the collection. The first defines the start day of year (inclusive) and the second defines the end day of year (inclusive). Note that the start day can be less than the end day, which indicates that the day range crosses the new year. Ex: [180, 240] (dates for northern hemisphere summer images), [330, 90] (dates for southern hemisphere summer images). | 328 | | [params.excludeIds] | Array | | A list of image IDs to filter out of the image collection, given as the value of the image's 'LANDSAT_SCENE_ID' property. | 329 | 330 | **Example** 331 | ```js 332 | // Filter by geometry intersection, cloud cover, and geometric RMSE. 333 | var mssDnCol = msslib.getCol({ 334 | aoi: ee.Geometry.Point([-122.239, 44.018]), 335 | maxCloudCover: 25, 336 | maxRmseVerify: 0.25 337 | }); 338 | 339 | // Filter by geometry intersection, year range, and day of year. 340 | var mssDnCol = msslib.getCol({ 341 | aoi: ee.Geometry.Point([-122.239, 44.018]), 342 | yearRange: [1975, 1980], 343 | doyRange: [170, 240] 344 | }); 345 | 346 | // Filter by geometry intersection and exclude two images by ID. 347 | var mssDnCol = msslib.getCol({ 348 | aoi: ee.Geometry.Point([-122.239, 44.018]), 349 | excludeIds: ['LM10490291972246AAA04', 'LM10480291973113AAA02'] 350 | }); 351 | ``` 352 | 353 | 354 | ### viewThumbnails(col, params) 355 | Prints image collection thumbnails to the console with accompanying image 356 | IDs for use in quickly evaluating a collection. The image IDs can be recorded 357 | and used as entries in the `params.excludeIds` list of the `msslib.getCol()` 358 | function to exclude the given image(s). 359 | 360 | **Kind**: global function 361 | 362 | | Param | Type | Default | Description | 363 | | --- | --- | --- | --- | 364 | | col | ee.ImageCollection | | MSS DN image collection originating from the `msslib.getCol()` function. | 365 | | params | Object | | An object that provides visualization parameters. | 366 | | [params.unit] | string | "toa" | An indicator for what units to use in the display image. Use: 'dn' (raw digital number), 'rad' (radiance), or 'toa' (TOA reflectance). The selected unit will be calculated on-the-fly. | 367 | | [params.display] | string | "nir\\|red\\|green" | An indicator for how to display the image thumbnail. Use 'nir\|red\|green' (RGB) or 'ndvi' (grayscale). Default visualization parameters for color stretch are applied. | 368 | | [params.visParams] | Object | | A custom visualization parameter dictionary as described [here](https://developers.google.com/earth-engine/image_visualization#mapVisParamTable). If set, overrides the `params.display` option and default. | 369 | 370 | **Example** 371 | ```js 372 | // Get an MSS image collection. 373 | var mssDnCol = msslib.getCol({ 374 | aoi: ee.Geometry.Point([-122.239, 44.018]), 375 | doyRange: [170, 240] 376 | }); 377 | 378 | // View DN image thumbnails in the console. 379 | viewThumbnails(mssDnCol, {unit: 'dn'}); 380 | ``` 381 | 382 | 383 | ### calcRad(img) > ee.Image 384 | Converts DN values to radiance. 385 | 386 | **Kind**: global function 387 | 388 | | Param | Type | Description | 389 | | --- | --- | --- | 390 | | img | ee.Image | MSS DN image originating from the `msslib.getCol()` function. | 391 | 392 | **Example** 393 | ```js 394 | // Get an MSS image collection. 395 | var mssDnCol = msslib.getCol({ 396 | aoi: ee.Geometry.Point([-122.239, 44.018]), 397 | doyRange: [170, 240] 398 | }); 399 | 400 | // Convert DN to radiance for a single image. 401 | var mssRadImg = msslib.calcRad(mssDnCol.first()); 402 | 403 | // Convert DN to radiance for all images in a collection. 404 | var mssRadCol = mssDnCol.map(msslib.calcRad); 405 | ``` 406 | 407 | 408 | ### calcToa(img) > ee.Image 409 | Converts DN values to TOA reflectance. 410 | 411 | **Kind**: global function 412 | 413 | | Param | Type | Description | 414 | | --- | --- | --- | 415 | | img | ee.Image | MSS DN image originating from the `msslib.getCol()` function. | 416 | 417 | **Example** 418 | ```js 419 | // Get an MSS image collection. 420 | var mssDnCol = msslib.getCol({ 421 | aoi: ee.Geometry.Point([-122.239, 44.018]), 422 | doyRange: [170, 240] 423 | }); 424 | 425 | // Convert DN to TOA for a single image. 426 | var mssToaImg = msslib.calcToa(mssDnCol.first()); 427 | 428 | // Convert DN to TOA for all images in a collection. 429 | var mssToaCol = mssDnCol.map(msslib.calcToa); 430 | ``` 431 | 432 | 433 | ### addNdvi(img) > ee.Image 434 | Adds NDVI transformation as a band ('ndvi') to the input image. 435 | 436 | **Kind**: global function 437 | 438 | | Param | Type | Description | 439 | | --- | --- | --- | 440 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. It is recommended that the image be in units of radiance or TOA reflectance (see `msslib.calcRad()` and `msslib.calcToa()`). | 441 | 442 | **Example** 443 | ```js 444 | // Get an MSS image collection. 445 | var mssDnCol = msslib.getCol({ 446 | aoi: ee.Geometry.Point([-122.239, 44.018]), 447 | doyRange: [170, 240] 448 | }); 449 | 450 | // Convert DN to TOA for all images in a collection. 451 | var mssToaCol = mssDnCol.map(msslib.calcToa); 452 | 453 | // Add NDVI band to each image in a collection. 454 | var mssToaColNdvi = mssToaCol.map(msslib.addNdvi); 455 | ``` 456 | 457 | 458 | ### addTc(img) > ee.Image 459 | Adds Tasseled Cap indices brightness ('tcb'), greenness ('tcg'), yellowness 460 | ('tcy'), and angle ('tca') to the input image. See [Kauth and Thomas, 1976](https://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1160&context=lars_symp) 461 | 462 | **Kind**: global function 463 | 464 | | Param | Type | Description | 465 | | --- | --- | --- | 466 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. It is recommended that the image be in units of radiance or TOA reflectance (see `msslib.calcRad()` and `msslib.calcToa()`). | 467 | 468 | **Example** 469 | ```js 470 | // Get an MSS image collection. 471 | var mssDnCol = msslib.getCol({ 472 | aoi: ee.Geometry.Point([-122.239, 44.018]), 473 | doyRange: [170, 240] 474 | }); 475 | 476 | // Convert DN to TOA for all images in a collection. 477 | var mssToaCol = mssDnCol.map(msslib.calcToa); 478 | 479 | // Add Tasseled Cap bands to each image in a collection. 480 | var mssToaColTc = mssToaCol.map(msslib.addTc); 481 | ``` 482 | 483 | 484 | ### addQaMask(img) > ee.Image 485 | Adds the 'BQA' quality band as mask band ('BQA_mask') indicating good (1) and 486 | bad (0) pixels. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 487 | 488 | **Kind**: global function 489 | 490 | | Param | Type | Description | 491 | | --- | --- | --- | 492 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. | 493 | 494 | **Example** 495 | ```js 496 | // Get an MSS image collection. 497 | var mssDnCol = msslib.getCol({ 498 | aoi: ee.Geometry.Point([-122.239, 44.018]), 499 | doyRange: [170, 240] 500 | }); 501 | 502 | // Select a single image. 503 | var mssDnImg = mssDnCol.filter( 504 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 505 | 506 | // Add BQA mask band to the single image. 507 | var mssDnImgQaMask = msslib.addQaMask(mssDnImg); 508 | 509 | // Display the results. 510 | Map.centerObject(mssDnImgQaMask, 9); 511 | Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image'); 512 | Map.addLayer(mssDnImgQaMask, { 513 | bands: ['BQA_mask'], 514 | min: 0, 515 | max: 1, 516 | palette: ['grey', 'green'] 517 | }, 'BQA mask'); 518 | 519 | // Add BQA mask band to all images in collection. 520 | var mssDnColQaMask = mssDnCol.map(msslib.addQaMask); 521 | print(mssDnColQaMask.limit(5)); 522 | ``` 523 | 524 | 525 | ### applyQaMask(img) > ee.Image 526 | Applies the 'BQA' quality band to an image as a mask. It masks out cloud 527 | pixels and those exhibiting radiometric saturation, as well pixels associated 528 | with missing data. Cloud identification is limited to mostly thick cumulus 529 | clouds; note that snow and very bright surface features are often mislabeled 530 | as cloud. Radiometric saturation in MSS images usually manifests as entire 531 | or partial image pixel rows being highly biased toward high values in a 532 | single band, which when visualized, can appear as tinted red, green, or 533 | blue. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 534 | 535 | **Kind**: global function 536 | 537 | | Param | Type | Description | 538 | | --- | --- | --- | 539 | | img | ee.Image | MSS image originating from the `msslib.getCol()` function. | 540 | 541 | **Example** 542 | ```js 543 | // Get an MSS image collection. 544 | var mssDnCol = msslib.getCol({ 545 | aoi: ee.Geometry.Point([-122.239, 44.018]), 546 | doyRange: [170, 240] 547 | }); 548 | 549 | // Select a single image. 550 | var mssDnImg = mssDnCol.filter( 551 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 552 | 553 | // Apply BQA mask to the single image. 554 | var mssDnImgQaMask = msslib.applyQaMask(mssDnImg); 555 | 556 | // Display the results. 557 | Map.centerObject(mssDnImgQaMask, 9); 558 | Map.setOptions('SATELLITE'); 559 | Map.addLayer(mssDnImg, msslib.visDn, 'DN image'); 560 | Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image masked'); 561 | 562 | // Apply BQA mask to all images in collection. 563 | var mssDnColQaMask = mssDnCol.map(msslib.applyQaMask); 564 | print(mssDnColQaMask.limit(5)); 565 | ``` 566 | 567 | 568 | ### addMsscvm(img) > ee.Image 569 | Adds the MSScvm band ('msscvm') to the input image. Value 0 designates pixels 570 | as clear, 1 as clouds, and 2 as shadows. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 571 | 572 | **Kind**: global function 573 | 574 | | Param | Type | Description | 575 | | --- | --- | --- | 576 | | img | ee.Image | MSS TOA image originating from `msslib.getCol()` and `msslib.calcToa()`. | 577 | 578 | **Example** 579 | ```js 580 | // Get an MSS image collection. 581 | var mssDnCol = msslib.getCol({ 582 | aoi: ee.Geometry.Point([-122.239, 44.018]), 583 | doyRange: [170, 240], 584 | yearRange: [1983, 1986], 585 | wrs: '2' 586 | }); 587 | 588 | // Convert DN to TOA. 589 | var mssToaCol = mssDnCol.map(msslib.calcToa); 590 | 591 | // Select a single image. 592 | var mssToaImg = mssToaCol.filter( 593 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 594 | 595 | // Add MSScvm band to the single image. 596 | var mssToaImgMsscvm = msslib.addMsscvm(mssToaImg); 597 | 598 | // Display the results. 599 | Map.centerObject(mssToaImgMsscvm, 9); 600 | Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image'); 601 | Map.addLayer(mssToaImgMsscvm, { 602 | bands: ['msscvm'], 603 | min: 0, 604 | max: 2, 605 | palette: ['27ae60', 'FFFFFF', '000000'] 606 | }, 'MSScmv'); 607 | 608 | // Add MSScvm band to all images in collection. 609 | var mssToaColMsscvm = mssToaCol.map(msslib.addMsscvm); 610 | print(mssToaColMsscvm.limit(5)); 611 | ``` 612 | 613 | 614 | ### applyMsscvm(img) > ee.Image 615 | Applies the MSScvm mask to the input image, i.e., pixels identified as cloud 616 | or cloud shadow are masked out. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 617 | 618 | **Kind**: global function 619 | 620 | | Param | Type | Description | 621 | | --- | --- | --- | 622 | | img | ee.Image | MSS TOA image originating from `msslib.getCol()` and `msslib.calcToa()`. | 623 | 624 | **Example** 625 | ```js 626 | // Get an MSS image collection. 627 | var mssDnCol = msslib.getCol({ 628 | aoi: ee.Geometry.Point([-122.239, 44.018]), 629 | doyRange: [170, 240], 630 | yearRange: [1983, 1986], 631 | wrs: '2' 632 | }); 633 | 634 | // Convert DN to TOA. 635 | var mssToaCol = mssDnCol.map(msslib.calcToa); 636 | 637 | // Select a single image. 638 | var mssToaImg = mssToaCol.filter( 639 | ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 640 | 641 | // Apply MSScvm to the single image. 642 | var mssToaImgMsscvm = msslib.applyMsscvm(mssToaImg); 643 | 644 | // Display the results. 645 | Map.centerObject(mssToaImgMsscvm, 9); 646 | Map.setOptions('SATELLITE'); 647 | Map.addLayer(mssToaImg, msslib.visToa, 'TOA image'); 648 | Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image masked'); 649 | 650 | // Apply MSScvm to all images in collection. 651 | var mssToaColMsscvm = mssToaCol.map(msslib.applyMsscvm); 652 | print(mssToaColMsscvm.limit(5)); 653 | ``` 654 | -------------------------------------------------------------------------------- /msslib.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2020 Justin Braaten 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // ############################################################################# 19 | // ### VERSION ### 20 | // ############################################################################# 21 | 22 | exports.version = '0.1.2'; 23 | 24 | // ############################################################################# 25 | // ### CONSTANTS ### 26 | // ############################################################################# 27 | 28 | /** 29 | * A dictionary of false color visualization parameters for MSS DN images. 30 | * 31 | * @constant {Object} 32 | * @example 33 | * // Get an MSS image. 34 | * var mssDnImg = msslib.getCol({ 35 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 36 | * yearRange: [1987, 1987], 37 | * doyRange: [170, 240], 38 | * wrs: '2' 39 | * }).first(); 40 | * 41 | * // Use with Map.addLayer(). 42 | * Map.centerObject(mssDnImg, 8); 43 | * Map.addLayer(mssDnImg, msslib.visDn, 'From Map.addLayer()'); 44 | * 45 | * // Use with ee.Image.visualize(). 46 | * var visImg = mssDnImg.visualize(msslib.visDn); 47 | * Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 48 | */ 49 | var visDn = { 50 | bands: ['nir', 'red', 'green'], 51 | min: [47, 20, 27], 52 | max: [142, 92, 71], 53 | gamma: [1.2, 1.2, 1.2] 54 | }; 55 | exports.visDn = visDn; 56 | 57 | /** 58 | * A dictionary of false color visualization parameters for MSS radiance images. 59 | * 60 | * @constant {Object} 61 | * @example 62 | * // Get an MSS image. 63 | * var mssDnImg = msslib.getCol({ 64 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 65 | * yearRange: [1987, 1987], 66 | * doyRange: [170, 240], 67 | * wrs: '2' 68 | * }).first(); 69 | * 70 | * // Convert DN to radiance. 71 | * var mssRadImg = msslib.calcRad(mssDnImg); 72 | * 73 | * // Use with Map.addLayer(). 74 | * Map.centerObject(mssRadImg, 8); 75 | * Map.addLayer(mssRadImg, msslib.visRad, 'From Map.addLayer()'); 76 | * 77 | * // Use with ee.Image.visualize(). 78 | * var visImg = mssRadImg.visualize(msslib.visRad); 79 | * Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 80 | */ 81 | var visRad = { 82 | bands: ['nir', 'red', 'green'], 83 | min: [23, 15, 25], 84 | max: [67, 62, 64], 85 | gamma: [1.2, 1.2, 1.2] 86 | }; 87 | exports.visRad = visRad; 88 | 89 | /** 90 | * A dictionary of false color visualization parameters for MSS TOA reflectance 91 | * images. 92 | * 93 | * @constant {Object} 94 | * @example 95 | * // Get an MSS image. 96 | * var mssDnImg = msslib.getCol({ 97 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 98 | * yearRange: [1987, 1987], 99 | * doyRange: [170, 240], 100 | * wrs: '2' 101 | * }).first(); 102 | * 103 | * // Convert DN to TOA. 104 | * var mssToaImg = msslib.calcToa(mssDnImg); 105 | * 106 | * // Use with Map.addLayer(). 107 | * Map.centerObject(mssToaImg, 8); 108 | * Map.addLayer(mssToaImg, msslib.visToa, 'From Map.addLayer()'); 109 | * 110 | * // Use with ee.Image.visualize(). 111 | * var visImg = mssToaImg.visualize(msslib.visToa); 112 | * Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 113 | */ 114 | var visToa = { 115 | bands: ['nir', 'red', 'green'], 116 | min: [0.0896, 0.0322, 0.0464], 117 | max: [0.2627, 0.1335, 0.1177], 118 | gamma: [1.2, 1.2, 1.2] 119 | }; 120 | exports.visToa = visToa; 121 | 122 | /** 123 | * A dictionary of visualization parameters for MSS NDVI images. 124 | * 125 | * @constant {Object} 126 | * @example 127 | * // Get an MSS image. 128 | * var mssDnImg = msslib.getCol({ 129 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 130 | * yearRange: [1987, 1987], 131 | * doyRange: [170, 240], 132 | * wrs: '2' 133 | * }).first(); 134 | * 135 | * // Convert DN to TOA and add NDVI band. 136 | * var mssNdviImg = msslib.addNdvi(msslib.calcToa(mssDnImg)); 137 | * 138 | * // Use with Map.addLayer(). 139 | * Map.centerObject(mssNdviImg, 8); 140 | * Map.addLayer(mssNdviImg, msslib.visNdvi, 'From Map.addLayer()'); 141 | * 142 | * // Use with ee.Image.visualize(). 143 | * var visImg = mssNdviImg.visualize(msslib.visNdvi); 144 | * Map.addLayer(visImg, null, 'From ee.Image.visualize()'); 145 | */ 146 | var visNdvi = { 147 | bands: ['ndvi'], min: 0.1, max: 0.8 148 | }; 149 | exports.visNdvi = visNdvi; 150 | 151 | /** 152 | * An example MSS 5 image. 153 | * 154 | * @constant {ee.Image} 155 | * @ignore 156 | */ 157 | var exMss5 = ee.Image('LANDSAT/LM05/C01/T2/LM05_045029_19840728'); 158 | exports.exMss5 = exMss5; 159 | 160 | // ############################################################################# 161 | // ### FETCH COLLECTIONS ### 162 | // ############################################################################# 163 | 164 | /** 165 | * Generates the PPPRRR path/row granuale ID. 166 | * 167 | * @param {ee.Image} img A Landsat MSS image. 168 | * @returns {ee.String} A Landsat PPPRRR path/row granuale ID. 169 | * @ignore 170 | */ 171 | function getPr(img) { 172 | var path = ee.String('000').cat( 173 | ee.String(ee.Number(img.get('WRS_PATH')).toShort())).slice(-3); 174 | var row = ee.String('000').cat( 175 | ee.String(ee.Number(img.get('WRS_ROW')).toShort())).slice(-3); 176 | return ee.String(path.cat(row)); 177 | } 178 | 179 | // TODO: describe the returned dictionary better, it may not be clear what the 180 | // keys and values are. Also, why not add the 40 km buffer as needed later, 181 | // seems strange to include it here. 182 | 183 | /** 184 | * Get the geometry for a given WRS-1 granule. Returns a dictionary with three 185 | * elements: 'granule' a `ee.Feature`, granule 'centroid' a `ee.Geometry`, and 186 | * granule 'bounds' `ee.Geometry` with a 40 km buffer. Note that it will only 187 | * return results for granules that intersect land on the descending path. 188 | * 189 | * @param {string} granuleId The PPPRRR granule ID. 190 | * @returns {ee.Dictionary} 191 | * @example 192 | * // Get granule geometry for WRS-1 path/row granule 049030. 193 | * var granuleGeom = msslib.getWrs1GranuleGeom('049030'); 194 | * 195 | * // Print the results. 196 | * print(granuleGeom); 197 | * 198 | * // Display the results. 199 | * var granule = ee.Feature(granuleGeom.get('granule')); 200 | * var centroid = ee.Geometry(granuleGeom.get('centroid')); 201 | * var bounds = ee.Geometry(granuleGeom.get('bounds')); 202 | * Map.centerObject(centroid, 8); 203 | * Map.addLayer(bounds, {color: 'blue'}, 'Bounds'); 204 | * Map.addLayer(granule, {color: 'black'}, 'Granule'); 205 | * Map.addLayer(centroid, {color: 'red'}, 'Centroid'); 206 | */ 207 | function getWrs1GranuleGeom(granuleId) { 208 | var granule = ee.Feature( 209 | ee.FeatureCollection('users/jstnbraaten/wrs/wrs1_descending_land') 210 | .filter(ee.Filter.eq('PR', granuleId)).first()); 211 | var centroid = granule.centroid(300).geometry(300); 212 | var bounds = granule.geometry(300).buffer(40000); 213 | return ee.Dictionary({ 214 | granule: granule, 215 | centroid: centroid, 216 | bounds: bounds 217 | }); 218 | } 219 | exports.getWrs1GranuleGeom = getWrs1GranuleGeom; 220 | 221 | /** 222 | * Excludes an image from a collection by image ID. Used as the `algorithm` 223 | * input to the `ee.List.iterate()` function in the `msslib.filterById()` 224 | * function. 225 | * 226 | * @param {string} id The image ID to filter out of the image collection, given 227 | * as the value of the image's 'LANDSAT_SCENE_ID' property. 228 | * @param {ee.ImageCollection} col The image collection to filter. 229 | * @returns {ee.ImageCollection} The filtered image collection. 230 | * @ignore 231 | */ 232 | function _filterById(id, col) { 233 | return ee.ImageCollection(col).filter( 234 | ee.Filter.neq('LANDSAT_SCENE_ID', ee.String(id))); 235 | } 236 | 237 | /** 238 | * Excludes a list of images from a collection by image ID. It is used in the 239 | * `msslib.filterCol()` function. 240 | * 241 | * @param {ee.ImageCollection} col The image collection to filter. 242 | * @param {Array} imgList A list of image IDs to filter out of the image 243 | * collection, given as the value of the image's 'system:index' property. 244 | * @returns {ee.ImageCollection} The filtered image collection. 245 | * @ignore 246 | */ 247 | function filterById(col, imgList) { 248 | return ee.ImageCollection(ee.List(imgList).iterate(_filterById, col)); 249 | } 250 | 251 | /** 252 | * Filters an MSS image collection by bounds, date, and quality properties. 253 | * By default, it excludes images that do not have all four reflectance bands 254 | * present and/or are only processed to level L1G. It is intended to handle 255 | * only one MSS collection at a time i.e. no merged collections. Used by the 256 | * `msslib.getCol()` function. 257 | * 258 | * @param {ee.ImageCollection} col The image collection to filter. 259 | * @param {Object} params See `getCol`. 260 | * @param {string} wrs An indicator for whether the image collection contains 261 | * WRS-1 ('wrs1') or WRS-2 ('wrs2') images. 262 | * @returns {ee.ImageCollection} The filtered image collection. 263 | * @ignore 264 | */ 265 | function filterCol(col, params, wrs) { 266 | // Adjust band present property names depending on WRS (1 or 2). 267 | var bandsPresent = { 268 | wrs1: [ 269 | 'PRESENT_BAND_4', 'PRESENT_BAND_5', 'PRESENT_BAND_6', 'PRESENT_BAND_7' 270 | ], 271 | wrs2: [ 272 | 'PRESENT_BAND_1', 'PRESENT_BAND_2', 'PRESENT_BAND_3', 'PRESENT_BAND_4' 273 | ], 274 | }; 275 | 276 | if (params.aoi) { 277 | col = col.filterBounds(params.aoi); 278 | } 279 | 280 | col = col.filter(ee.Filter.neq('DATA_TYPE', 'L1G')) 281 | .filter(ee.Filter.eq(bandsPresent[wrs][0], 'Y')) 282 | .filter(ee.Filter.eq(bandsPresent[wrs][1], 'Y')) 283 | .filter(ee.Filter.eq(bandsPresent[wrs][2], 'Y')) 284 | .filter(ee.Filter.eq(bandsPresent[wrs][3], 'Y')) 285 | .filter(ee.Filter.lte('GEOMETRIC_RMSE_VERIFY', params.maxRmseVerify)) 286 | .filter(ee.Filter.lte('CLOUD_COVER', params.maxCloudCover)); 287 | 288 | if (params.yearRange) { 289 | col = col.filter(ee.Filter.calendarRange( 290 | params.yearRange[0], params.yearRange[1], 'year')); 291 | } 292 | if (params.doyRange) { 293 | col = col.filter(ee.Filter.calendarRange( 294 | params.doyRange[0], params.doyRange[1], 'day_of_year')); 295 | } 296 | if (params.excludeIds) { 297 | col = filterById(col, params.excludeIds); 298 | } 299 | 300 | return col; 301 | } 302 | 303 | /** 304 | * Assembles a Landsat MSS image collection from USGS Collection 1 T1 and T2 305 | * images acquired by satellites 1-5. Removes L1G images and images without a 306 | * complete set of reflectance bands. Additional default and optional filtering 307 | * criteria are applied, including by bounds, geometric error, cloud cover, 308 | * year, and day of year. All image bands are named consistently: 309 | * ['green', 'red', 'red_edge', 'nir', 'BQA']. Adds 'wrs' property to all images 310 | * designating them as 'WRS-1' or 'WRS-2'. 311 | * 312 | * @param {Object} params An object that provides filtering parameters. 313 | * @param {ee.Geometry} [params.aoi=null] The geometry to filter images by 314 | * intersection; those intersecting the geometry are included in the 315 | * collection. 316 | * @param {number} [params.maxRmseVerify=0.5] The maximum geometric RMSE of a 317 | * given image allowed in the collection, provided in units of pixels 318 | * (60 m), conditioned on the 'GEOMETRIC_RMSE_VERIFY' image property. 319 | * @param {number} [params.maxCloudCover=50] The maximum cloud cover of a given 320 | * image allowed in the collection, provided as a percent, conditioned on 321 | * the 'CLOUD_COVER' image property. 322 | * @param {string} [params.wrs=1&2] An indicator for what World Reference 323 | * System types to allow in the collection. MSS images from Landsat 324 | * satellites 1-3 use WRS-1, while 4-5 use WRS-2. Options include: '1' 325 | * (WRS-1 only), '2' (WRS-2 only), and '1&2' (both WRS-1 and WRS-2). 326 | * @param {Array} [params.yearRange=[1972, 2000]] An array with two integers that define 327 | * the range of years to include in the collection. The first defines the 328 | * start year (inclusive) and the second defines the end year (inclusive). 329 | * Ex: [1972, 1990]. 330 | * @param {Array} [params.doyRange=[1, 365]] An array with two integers that define 331 | * the range of days to include in the collection. The first defines the 332 | * start day of year (inclusive) and the second defines the end day of year 333 | * (inclusive). Note that the start day can be less than the end day, which 334 | * indicates that the day range crosses the new year. Ex: [180, 240] 335 | * (dates for northern hemisphere summer images), [330, 90] (dates for 336 | * southern hemisphere summer images). 337 | * @param {Array} [params.excludeIds=null] A list of image IDs to filter out of 338 | * the image collection, given as the value of the image's 339 | * 'LANDSAT_SCENE_ID' property. 340 | * @returns {ee.ImageCollection} An MSS image collection. 341 | * @example 342 | * // Filter by geometry intersection, cloud cover, and geometric RMSE. 343 | * var mssDnCol = msslib.getCol({ 344 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 345 | * maxCloudCover: 25, 346 | * maxRmseVerify: 0.25 347 | * }); 348 | * 349 | * // Filter by geometry intersection, year range, and day of year. 350 | * var mssDnCol = msslib.getCol({ 351 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 352 | * yearRange: [1975, 1980], 353 | * doyRange: [170, 240] 354 | * }); 355 | * 356 | * // Filter by geometry intersection and exclude two images by ID. 357 | * var mssDnCol = msslib.getCol({ 358 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 359 | * excludeIds: ['LM10490291972246AAA04', 'LM10480291973113AAA02'] 360 | * }); 361 | */ 362 | function getCol(params) { 363 | // Define default filter parameters. 364 | var _params = { 365 | 'aoi': null, 366 | 'maxRmseVerify': 0.5, 367 | 'maxCloudCover': 50, 368 | 'wrs': '1&2', 369 | 'yearRange': [1972, 2000], 370 | 'doyRange': [1, 365], 371 | 'excludeIds': null 372 | }; 373 | 374 | // Replace default params with provided params. 375 | if (params) { 376 | for (var param in params) { 377 | _params[param] = params[param] || _params[param]; 378 | } 379 | } 380 | 381 | // Initialize WRS-1 and WRS-2 collections. 382 | var wrs1Col = ee.ImageCollection([]); 383 | var wrs2Col = ee.ImageCollection([]); 384 | 385 | // Gather MSS WRS-1 images, filter as requested, designate as 'WRS-1'. 386 | if (_params.wrs.indexOf('1') !== -1) { 387 | var mss1T1 = filterCol( 388 | ee.ImageCollection('LANDSAT/LM01/C01/T1'), _params, 'wrs1'); 389 | var mss1T2 = filterCol( 390 | ee.ImageCollection('LANDSAT/LM01/C01/T2'), _params, 'wrs1'); 391 | var mss2T1 = filterCol( 392 | ee.ImageCollection('LANDSAT/LM02/C01/T1'), _params, 'wrs1'); 393 | var mss2T2 = filterCol( 394 | ee.ImageCollection('LANDSAT/LM02/C01/T2'), _params, 'wrs1'); 395 | var mss3T1 = filterCol( 396 | ee.ImageCollection('LANDSAT/LM03/C01/T1'), _params, 'wrs1'); 397 | var mss3T2 = filterCol( 398 | ee.ImageCollection('LANDSAT/LM03/C01/T2'), _params, 'wrs1'); 399 | wrs1Col = 400 | mss1T1.merge(mss1T2) 401 | .merge(mss2T1) 402 | .merge(mss2T2) 403 | .merge(mss3T1) 404 | .merge(mss3T2) 405 | .map(function(img) { 406 | return img.rename(['green', 'red', 'red_edge', 'nir', 'BQA']) 407 | .set('wrs', 'WRS-1'); 408 | }); 409 | } 410 | 411 | // Gather MSS WRS-2 images, filter as requested, designate as 'WRS-2'. 412 | if (_params.wrs.indexOf('2') !== -1) { 413 | var mss4T1 = filterCol( 414 | ee.ImageCollection('LANDSAT/LM04/C01/T1'), _params, 'wrs2'); 415 | var mss4T2 = filterCol( 416 | ee.ImageCollection('LANDSAT/LM04/C01/T2'), _params, 'wrs2'); 417 | var mss5T1 = filterCol( 418 | ee.ImageCollection('LANDSAT/LM05/C01/T1'), _params, 'wrs2'); 419 | var mss5T2 = filterCol( 420 | ee.ImageCollection('LANDSAT/LM05/C01/T2'), _params, 'wrs2'); 421 | wrs2Col = 422 | mss4T1.merge(mss4T2).merge(mss5T1).merge(mss5T2).map(function(img) { 423 | return img.rename(['green', 'red', 'red_edge', 'nir', 'BQA']) 424 | .set('wrs', 'WRS-2'); 425 | }); 426 | } 427 | 428 | // Return time-sorted, merged, WRS-1 and WRS-2 collection with filter params 429 | // attached. 430 | return wrs1Col 431 | .merge(wrs2Col) 432 | .map(function(img) { 433 | var date = img.date(); 434 | return img.set({ 435 | start_doy: _params.doyRange[0], 436 | end_doy: _params.doyRange[1], 437 | year: date.get('year'), 438 | doy: date.getRelative('day', 'year'), 439 | pr: getPr(img) 440 | // composite_year: // TODO 441 | }); 442 | }) 443 | .sort('system:time_start'); 444 | } 445 | exports.getCol = getCol; 446 | 447 | 448 | // ############################################################################# 449 | // ### IMAGE ASSESSMENT ### 450 | // ############################################################################# 451 | 452 | // TODO: add example(s) that shows how to use `display` and `visParams`. 453 | 454 | /** 455 | * Prints image collection thumbnails to the console with accompanying image 456 | * IDs for use in quickly evaluating a collection. The image IDs can be recorded 457 | * and used as entries in the `params.excludeIds` list of the `msslib.getCol()` 458 | * function to exclude the given image(s). 459 | * 460 | * @param {ee.ImageCollection} col MSS DN image collection originating from the 461 | * `msslib.getCol()` function. 462 | * @param {Object} params An object that provides visualization parameters. 463 | * @param {string} [params.unit=toa] An indicator for what units to use in the 464 | * display image. Use: 'dn' (raw digital number), 'rad' (radiance), or 465 | * 'toa' (TOA reflectance). The selected unit will be calculated on-the-fly. 466 | * @param {string} [params.display=nir\|red\|green] An indicator for how to 467 | * display the image thumbnail. Use 'nir\|red\|green' (RGB) or 'ndvi' 468 | * (grayscale). Default visualization parameters for color stretch are 469 | * applied. 470 | * @param {Object} [params.visParams=null] A custom visualization parameter 471 | * dictionary as described [here](https://developers.google.com/earth-engine/image_visualization#mapVisParamTable). 472 | * If set, overrides the `params.display` option and default. 473 | * @example 474 | * // Get an MSS image collection. 475 | * var mssDnCol = msslib.getCol({ 476 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 477 | * doyRange: [170, 240] 478 | * }); 479 | * 480 | * // View DN image thumbnails in the console. 481 | * viewThumbnails(mssDnCol, {unit: 'dn'}); 482 | */ 483 | function viewThumbnails(col, params) { 484 | print('Please wait patiently, images may not load immediately'); 485 | 486 | var _params = { 487 | unit: 'toa', 488 | display: 'nir|red|green', 489 | visParams: null 490 | }; 491 | 492 | if (params) { 493 | for (var param in params) { 494 | _params[param] = params[param] || _params[param]; 495 | } 496 | } 497 | 498 | var settings = { 499 | unit: { 500 | dn: function(img) {return img}, 501 | rad: calcRad, 502 | toa: calcToa 503 | }, 504 | display: { 505 | 'nir|red|green': { 506 | dn: visDn, 507 | rad: visRad, 508 | toa: visToa 509 | }, 510 | 'ndvi': { 511 | dn: visNdvi, 512 | rad: visNdvi, 513 | toa: visNdvi 514 | } 515 | } 516 | }; 517 | 518 | var imgList = col.sort('system:time_start').toList(col.size()); 519 | 520 | imgList.evaluate(function(imgList) { 521 | for (var i = 0; i < imgList.length; i++) { 522 | var id = imgList[i].id; 523 | var img = ee.Image(id).rename(['green', 'red', 'red_edge', 'nir', 'BQA']); 524 | img = settings.unit[_params.unit](img); 525 | if(_params.display == 'ndvi') { 526 | img = addNdvi(img); 527 | } 528 | var visParams = settings.display[_params.display][_params.unit]; 529 | if(_params.visParams) { 530 | visParams = _params.visParams; 531 | } 532 | var imgVis = img.visualize(visParams); 533 | print(img.get('LANDSAT_SCENE_ID')); 534 | print(ui.Thumbnail(imgVis, { 535 | dimensions: 512, 536 | crs: 'EPSG:3857', 537 | })); 538 | } 539 | }); 540 | } 541 | exports.viewThumbnails = viewThumbnails; 542 | 543 | // ############################################################################# 544 | // ### IMAGE MANIPULATION ### 545 | // ############################################################################# 546 | 547 | /** 548 | * Converts DN values to either radiance or TOA reflectance. 549 | * 550 | * @param {ee.Image} img MSS DN image originating from the `msslib.getCol()` 551 | * function. 552 | * @param {string} unit Indicator for whether to convert DN to units of radiance 553 | * ('radiance') or TOA reflectance ('reflectance'). 554 | * @return {ee.Image} 555 | * @ignore 556 | */ 557 | function scaleDn(img, unit) { 558 | var mult = 'REFLECTANCE_MULT_BAND', add = 'REFLECTANCE_ADD_BAND'; 559 | if (unit == 'radiance') { 560 | mult = 'RADIANCE_MULT_BAND'; 561 | add = 'RADIANCE_ADD_BAND'; 562 | } 563 | 564 | var gainBands = ee.List(img.propertyNames()) 565 | .filter(ee.Filter.stringContains('item', mult)) 566 | .sort(); 567 | var biasBands = ee.List(img.propertyNames()) 568 | .filter(ee.Filter.stringContains('item', add)) 569 | .sort(); 570 | 571 | var gainImg = ee.Image.cat( 572 | ee.Image.constant(img.get(gainBands.getString(0))), 573 | ee.Image.constant(img.get(gainBands.getString(1))), 574 | ee.Image.constant(img.get(gainBands.getString(2))), 575 | ee.Image.constant(img.get(gainBands.getString(3)))).toFloat(); 576 | 577 | var biasImg = ee.Image.cat( 578 | ee.Image.constant(img.get(biasBands.getString(0))), 579 | ee.Image.constant(img.get(biasBands.getString(1))), 580 | ee.Image.constant(img.get(biasBands.getString(2))), 581 | ee.Image.constant(img.get(biasBands.getString(3)))).toFloat(); 582 | 583 | var dnImg = img.select([0, 1, 2, 3]); 584 | 585 | return ee.Image( 586 | dnImg.multiply(gainImg) 587 | .add(biasImg) 588 | .toFloat() 589 | .addBands(img.select('BQA')) 590 | .copyProperties(img, img.propertyNames())); 591 | } 592 | 593 | /** 594 | * Converts DN values to radiance. 595 | * 596 | * @param {ee.Image} img MSS DN image originating from the `msslib.getCol()` 597 | * function. 598 | * @return {ee.Image} 599 | * @example 600 | * // Get an MSS image collection. 601 | * var mssDnCol = msslib.getCol({ 602 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 603 | * doyRange: [170, 240] 604 | * }); 605 | * 606 | * // Convert DN to radiance for a single image. 607 | * var mssRadImg = msslib.calcRad(mssDnCol.first()); 608 | * 609 | * // Convert DN to radiance for all images in a collection. 610 | * var mssRadCol = mssDnCol.map(msslib.calcRad); 611 | */ 612 | function calcRad(img) { 613 | return scaleDn(img, 'radiance'); 614 | } 615 | exports.calcRad = calcRad; 616 | 617 | /** 618 | * Converts DN values to TOA reflectance. 619 | * 620 | * @param {ee.Image} img MSS DN image originating from the `msslib.getCol()` 621 | * function. 622 | * @return {ee.Image} 623 | * @example 624 | * // Get an MSS image collection. 625 | * var mssDnCol = msslib.getCol({ 626 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 627 | * doyRange: [170, 240] 628 | * }); 629 | * 630 | * // Convert DN to TOA for a single image. 631 | * var mssToaImg = msslib.calcToa(mssDnCol.first()); 632 | * 633 | * // Convert DN to TOA for all images in a collection. 634 | * var mssToaCol = mssDnCol.map(msslib.calcToa); 635 | */ 636 | function calcToa(img) { 637 | return scaleDn(img, 'reflectance'); 638 | } 639 | exports.calcToa = calcToa; 640 | 641 | // TODO: add example of applying to a single image. 642 | 643 | /** 644 | * Adds NDVI transformation as a band ('ndvi') to the input image. 645 | * 646 | * @param {ee.Image} img MSS image originating from the `msslib.getCol()` 647 | * function. It is recommended that the image be in units of radiance or 648 | * TOA reflectance (see `msslib.calcRad()` and `msslib.calcToa()`). 649 | * @return {ee.Image} 650 | * @example 651 | * // Get an MSS image collection. 652 | * var mssDnCol = msslib.getCol({ 653 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 654 | * doyRange: [170, 240] 655 | * }); 656 | * 657 | * // Convert DN to TOA for all images in a collection. 658 | * var mssToaCol = mssDnCol.map(msslib.calcToa); 659 | * 660 | * // Add NDVI band to each image in a collection. 661 | * var mssToaColNdvi = mssToaCol.map(msslib.addNdvi); 662 | */ 663 | function addNdvi(img) { 664 | var ndvi = img.normalizedDifference(['nir', 'red']).rename('ndvi'); 665 | return ee.Image(img.addBands(ndvi).copyProperties(img, img.propertyNames())); 666 | } 667 | exports.addNdvi = addNdvi; 668 | 669 | // TODO: Need to ensure use of the proper units - paper seems to suggest DN 670 | // and also the use of an offset - see section IV, eq 1. Should it be 671 | // capitalized? 672 | 673 | /** 674 | * Adds Tasseled Cap indices brightness ('tcb'), greenness ('tcg'), yellowness 675 | * ('tcy'), and angle ('tca') to the input image. See [Kauth and Thomas, 1976](https://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1160&context=lars_symp) 676 | * 677 | * @param {ee.Image} img MSS image originating from the `msslib.getCol()` 678 | * function. It is recommended that the image be in units of radiance or 679 | * TOA reflectance (see `msslib.calcRad()` and `msslib.calcToa()`). 680 | * @return {ee.Image} 681 | * @example 682 | * // Get an MSS image collection. 683 | * var mssDnCol = msslib.getCol({ 684 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 685 | * doyRange: [170, 240] 686 | * }); 687 | * 688 | * // Convert DN to TOA for all images in a collection. 689 | * var mssToaCol = mssDnCol.map(msslib.calcToa); 690 | * 691 | * // Add Tasseled Cap band to each image in a collection. 692 | * var mssToaColTc = mssToaCol.map(msslib.addTc); 693 | * @ignore 694 | */ 695 | function addTc(img) { 696 | var bands = img.select([0, 1, 2, 3]); 697 | var tcbCoeffs = ee.Image.constant([0.433, 0.632, 0.586, 0.264]); 698 | var tcgCoeffs = ee.Image.constant([-0.290, -0.562, 0.600, 0.491]); 699 | var tcyCoeffs = ee.Image.constant([-0.829, 0.522, -0.039, 0.194]); 700 | var tcb = bands.multiply(tcbCoeffs).reduce(ee.Reducer.sum()).toFloat(); 701 | var tcg = bands.multiply(tcgCoeffs).reduce(ee.Reducer.sum()).toFloat(); 702 | var tcy = bands.multiply(tcyCoeffs).reduce(ee.Reducer.sum()).toFloat(); 703 | var tca = (tcg.divide(tcb)).atan().multiply(180 / Math.PI).toFloat(); 704 | var tc = ee.Image.cat(tcb, tcg, tcy, tca).rename('tcb', 'tcg', 'tcy', 'tca'); 705 | return ee.Image(img.addBands(tc).copyProperties(img, img.propertyNames())); 706 | } 707 | exports.addTc = addTc; 708 | 709 | 710 | 711 | 712 | // ############################################################################# 713 | // ### BQA MASK ### 714 | // ############################################################################# 715 | 716 | /** 717 | * Get the 'BQA' quality band as a Boolean layer indicating good (1) and bad (0) 718 | * pixels. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 719 | * 720 | * @param {ee.Image} img MSS image originating from the `msslib.getCol()` 721 | * function. 722 | * @return {ee.Image} 723 | * @ignore 724 | */ 725 | function getQaMask(img) { 726 | return img.select('BQA').eq(32).rename('BQA_mask'); 727 | } 728 | 729 | /** 730 | * Adds the 'BQA' quality band as mask band ('BQA_mask') indicating good (1) and 731 | * bad (0) pixels. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 732 | * 733 | * @param {ee.Image} img MSS image originating from the `msslib.getCol()` 734 | * function. 735 | * @return {ee.Image} 736 | * @example 737 | * // Get an MSS image collection. 738 | * var mssDnCol = msslib.getCol({ 739 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 740 | * doyRange: [170, 240] 741 | * }); 742 | * 743 | * // Select a single image. 744 | * var mssDnImg = mssDnCol.filter( 745 | * ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 746 | * 747 | * // Add BQA mask band to the single image. 748 | * var mssDnImgQaMask = msslib.addQaMask(mssDnImg); 749 | * 750 | * // Display the results. 751 | * Map.centerObject(mssDnImgQaMask, 9); 752 | * Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image'); 753 | * Map.addLayer(mssDnImgQaMask, { 754 | * bands: ['BQA_mask'], 755 | * min: 0, 756 | * max: 1, 757 | * palette: ['grey', 'green'] 758 | * }, 'BQA mask'); 759 | * 760 | * // Add BQA mask band to all images in collection. 761 | * var mssDnColQaMask = mssDnCol.map(msslib.addQaMask); 762 | * print(mssDnColQaMask.limit(5)); 763 | */ 764 | function addQaMask(img) { 765 | return img.addBands(getQaMask(img)); 766 | } 767 | exports.addQaMask = addQaMask; 768 | 769 | /** 770 | * Applies the 'BQA' quality band to an image as a mask. It masks out cloud 771 | * pixels and those exhibiting radiometric saturation, as well pixels associated 772 | * with missing data. Cloud identification is limited to mostly thick cumulus 773 | * clouds; note that snow and very bright surface features are often mislabeled 774 | * as cloud. Radiometric saturation in MSS images usually manifests as entire 775 | * or partial image pixel rows being highly biased toward high values in a 776 | * single band, which when visualized, can appear as tinted red, green, or 777 | * blue. [Learn more about the 'BQA' band](https://www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band). 778 | * 779 | * @param {ee.Image} img MSS image originating from the `msslib.getCol()` 780 | * function. 781 | * @return {ee.Image} 782 | * @example 783 | * // Get an MSS image collection. 784 | * var mssDnCol = msslib.getCol({ 785 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 786 | * doyRange: [170, 240] 787 | * }); 788 | * 789 | * // Select a single image. 790 | * var mssDnImg = mssDnCol.filter( 791 | * ee.Filter.eq('LANDSAT_SCENE_ID', 'LM30490291982193AAA03')).first(); 792 | * 793 | * // Apply BQA mask to the single image. 794 | * var mssDnImgQaMask = msslib.applyQaMask(mssDnImg); 795 | * 796 | * // Display the results. 797 | * Map.centerObject(mssDnImgQaMask, 9); 798 | * Map.setOptions('SATELLITE'); 799 | * Map.addLayer(mssDnImg, msslib.visDn, 'DN image'); 800 | * Map.addLayer(mssDnImgQaMask, msslib.visDn, 'DN image masked'); 801 | * 802 | * // Apply BQA mask to all images in collection. 803 | * var mssDnColQaMask = mssDnCol.map(msslib.applyQaMask); 804 | * print(mssDnColQaMask.limit(5)); 805 | */ 806 | function applyQaMask(img) { 807 | return img.updateMask(getQaMask(img)); 808 | } 809 | exports.applyQaMask = applyQaMask; 810 | 811 | 812 | 813 | 814 | // ############################################################################# 815 | // ### MSSCVM ### 816 | // ############################################################################# 817 | 818 | /** 819 | * Returns MSScvm cloud layer. 820 | * 821 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 822 | * and `msslib.calcToa()`. 823 | * @return {ee.Image} 824 | * @ignore 825 | */ 826 | function cloudLayer(img) { 827 | // Identify cloud pixels. 828 | var cloudPixels = img.normalizedDifference(['green', 'red']) 829 | .gt(0) 830 | .multiply(img.select('green').gt(0.175)) // 1750 831 | .add(img.select('green').gt(0.39)) // 3900 832 | .gt(0); 833 | 834 | // Nine-pixel minimum connected component sieve. 835 | cloudPixels = cloudPixels.selfMask() 836 | .connectedPixelCount(10, true) 837 | .reproject(img.projection()) 838 | .gte(0) 839 | .unmask(0) 840 | .rename('cloudtest'); 841 | 842 | // Define kernel for buffer. 843 | var kernel = ee.Kernel.circle({radius: 2, units: 'pixels', normalize: true}); 844 | 845 | // Two pixel buffer, eight neighbor rule. 846 | return cloudPixels.focal_max({radius: 2, kernel: kernel}) 847 | .reproject(img.projection()) 848 | .rename('clouds'); 849 | } 850 | 851 | /** 852 | * Returns MSScvm water layer. 853 | * 854 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 855 | * and `msslib.calcToa()`. 856 | * @return {ee.Image} 857 | * @ignore 858 | */ 859 | function waterLayer(img) { 860 | // Threshold on NDVI. 861 | var mssWater = img.normalizedDifference(['nir', 'red']).lt(-0.085); 862 | 863 | // Get max extent of water 1985-2018. 864 | var waterExtent = 865 | ee.Image('JRC/GSW1_1/GlobalSurfaceWater').select('max_extent'); 866 | 867 | // Get intersection of MSS water and max extent. 868 | return mssWater.multiply(waterExtent) 869 | .reproject(img.projection()) 870 | .rename('water'); 871 | } 872 | 873 | /** 874 | * Assembles a global DEM from several sources, returned in the projection of 875 | * the input image. 876 | * 877 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 878 | * and `msslib.calcToa()`. 879 | * @return {ee.Image} 880 | * @ignore 881 | */ 882 | function getDem(img) { 883 | var aw3d30 = 884 | ee.Image('JAXA/ALOS/AW3D30/V2_2').select('AVE_DSM').rename('elev'); 885 | var GMTED2010 = ee.Image('USGS/GMTED2010').rename('elev'); 886 | return ee.ImageCollection([GMTED2010, aw3d30]) 887 | .mosaic() 888 | .reproject(img.projection()); 889 | } 890 | exports.getDem = getDem; 891 | 892 | /** 893 | * Converts degrees to radians. 894 | * 895 | * @param {ee.Image} img An image with pixel values in units of degrees. 896 | * @return {ee.Image} 897 | * @ignore 898 | */ 899 | function radians(img) { 900 | return img.toFloat().multiply(Math.PI).divide(180); 901 | } 902 | 903 | /** 904 | * Returns terrain illumination image. 905 | * 906 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 907 | * and `msslib.calcToa()`. 908 | * @param {ee.Image} slope A terrain slope image in units of degrees. 909 | * @param {ee.Image} aspect A terrain aspect image in units of degrees. 910 | * @return {ee.Image} 911 | * @ignore 912 | */ 913 | function getIll(img, slope, aspect) { 914 | // Get sun info. 915 | var azimuth = img.get('SUN_AZIMUTH'); 916 | var zenith = ee.Number(90).subtract(img.getNumber('SUN_ELEVATION')); 917 | 918 | // Convert slope and aspect degrees to radians. 919 | var slopeRad = radians(slope); 920 | var aspectRad = radians(aspect); 921 | 922 | // Calculate illumination. 923 | var azimuthImg = radians(ee.Image.constant(azimuth)); 924 | var zenithImg = radians(ee.Image.constant(zenith)); 925 | var left = zenithImg.cos().multiply(slopeRad.cos()); 926 | var right = zenithImg.sin() 927 | .multiply(slopeRad.sin()) 928 | .multiply(azimuthImg.subtract(aspectRad).cos()); 929 | return left.add(right); 930 | } 931 | 932 | /** 933 | * Returns MSS NIR TOA reflectance band corrected for topography via 934 | * Minnaert correction. 935 | * 936 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 937 | * and `msslib.calcToa()`. 938 | * @param {ee.Image} dem A digital elevation model. 939 | * @return {ee.Image} 940 | * @ignore 941 | */ 942 | function topoCorrB4(img, dem) { 943 | // Get terrain layers. 944 | var terrain = ee.Algorithms.Terrain(dem); 945 | var slope = terrain.select(['slope']); 946 | var aspect = terrain.select(['aspect']); 947 | 948 | // Get k image. 949 | // define polynomial coefficients to calc Minnaert value as function of slope 950 | // Ge, H., Lu, D., He, S., Xu, A., Zhou, G., & Du, H. (2008). Pixel-based 951 | // Minnaert correction method for reducing topographic effects on a Landsat 7 952 | // ETM+ image. Photogrammetric Engineering & Remote Sensing, 74(11), 953 | // 1343-1350. | 954 | // https://orst.library.ingentaconnect.com/content/asprs/pers/2008/00000074/00000011/art00003?crawler=true&mimetype=application/pdf 955 | var kImg = slope.resample('bilinear') 956 | .where( 957 | slope.gt(50), 958 | 50) // Set max slope at 50 degrees - paper does not sample 959 | // past - authors recommend no extrapolation. 960 | .polynomial([ 961 | 1.0021313684, -0.1308793751, 0.0106861276, -0.0004051135, 962 | 0.0000071825, -4.88e-8 963 | ]); 964 | 965 | // Get illumination. 966 | var ill = getIll(img, slope, aspect); 967 | 968 | // Correct NIR reflectance for topography. 969 | var cosTheta = radians(ee.Image.constant(ee.Number(90).subtract( 970 | ee.Number(img.get('SUN_ELEVATION'))))) 971 | .cos(); 972 | var correction = (cosTheta.divide(ill)).pow(kImg); 973 | return img.select('nir').multiply(correction); 974 | } 975 | exports.topoCorrB4 = topoCorrB4; 976 | 977 | /** 978 | * Returns MSScvm shadow layer. 979 | * 980 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 981 | * and `msslib.calcToa()`. 982 | * @param {ee.Image} dem A digital elevation model. 983 | * @param {ee.Image} clouds The result of `msslib.cloudLayer()`. 984 | * @return {ee.Image} 985 | * @ignore 986 | */ 987 | function shadowLayer(img, dem, clouds) { 988 | // Correct B4 reflectance for topography. 989 | var b4c = topoCorrB4(img, dem); 990 | 991 | // Threshold B4 - target dark pixels. 992 | var shadows = b4c.lt(0.11); // Make this true for all pixels to use full cloud projection. 993 | 994 | // Project clouds as potential shadow. 995 | var shadow_azimuth = 996 | ee.Number(90).subtract(ee.Number(img.get('SUN_AZIMUTH'))); 997 | var cloudProj = clouds.directionalDistanceTransform(shadow_azimuth, 50) 998 | .reproject({crs: img.projection(), scale: 60}) 999 | .select('distance') 1000 | .gt(0) 1001 | .unmask(0); 1002 | 1003 | // Get water layer. 1004 | var water = waterLayer(img); 1005 | 1006 | // Exclude water pixels from intersection of cloud projection and dark pixels. 1007 | return shadows.multiply(water.not()) 1008 | .multiply(cloudProj) 1009 | .focal_max(2) 1010 | .reproject(img.projection()); 1011 | } 1012 | 1013 | /** 1014 | * Adds the MSScvm band ('msscvm') to the input image. Value 0 designates pixels 1015 | * as clear, 1 as clouds, and 2 as shadows. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 1016 | * 1017 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 1018 | * and `msslib.calcToa()`. 1019 | * @return {ee.Image} 1020 | * @example 1021 | * // Get an MSS image collection. 1022 | * var mssDnCol = msslib.getCol({ 1023 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 1024 | * doyRange: [170, 240], 1025 | * yearRange: [1983, 1986], 1026 | * wrs: '2' 1027 | * }); 1028 | * 1029 | * // Convert DN to TOA. 1030 | * var mssToaCol = mssDnCol.map(msslib.calcToa); 1031 | * 1032 | * // Select a single image. 1033 | * var mssToaImg = mssToaCol.filter( 1034 | * ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 1035 | * 1036 | * // Add MSScvm band to the single image. 1037 | * var mssToaImgMsscvm = msslib.addMsscvm(mssToaImg); 1038 | * 1039 | * // Display the results. 1040 | * Map.centerObject(mssToaImgMsscvm, 9); 1041 | * Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image'); 1042 | * Map.addLayer(mssToaImgMsscvm, { 1043 | * bands: ['msscvm'], 1044 | * min: 0, 1045 | * max: 2, 1046 | * palette: ['27ae60', 'FFFFFF', '000000'] 1047 | * }, 'MSScmv'); 1048 | * 1049 | * // Add MSScvm band to all images in collection. 1050 | * var mssToaColMsscvm = mssToaCol.map(msslib.addMsscvm); 1051 | * print(mssToaColMsscvm.limit(5)); 1052 | */ 1053 | function addMsscvm(img) { 1054 | var dem = getDem(img); 1055 | var water = waterLayer(img); 1056 | var b4c = topoCorrB4(img, dem); 1057 | var clouds = cloudLayer(img).selfMask(); 1058 | var shadows = shadowLayer(img, dem, clouds).selfMask().add(1); 1059 | return img.addBands(shadows.blend(clouds).unmask(0).rename('msscvm')); 1060 | } 1061 | exports.addMsscvm = addMsscvm; 1062 | 1063 | /** 1064 | * Applies the MSScvm mask to the input image, i.e., pixels identified as cloud 1065 | * or cloud shadow are masked out. [Learn about MSScvm](https://jdbcode.github.io/MSScvm/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf). 1066 | * 1067 | * @param {ee.Image} img MSS TOA image originating from `msslib.getCol()` 1068 | * and `msslib.calcToa()`. 1069 | * @return {ee.Image} 1070 | * @example 1071 | * // Get an MSS image collection. 1072 | * var mssDnCol = msslib.getCol({ 1073 | * aoi: ee.Geometry.Point([-122.239, 44.018]), 1074 | * doyRange: [170, 240], 1075 | * yearRange: [1983, 1986], 1076 | * wrs: '2' 1077 | * }); 1078 | * 1079 | * // Convert DN to TOA. 1080 | * var mssToaCol = mssDnCol.map(msslib.calcToa); 1081 | * 1082 | * // Select a single image. 1083 | * var mssToaImg = mssToaCol.filter( 1084 | * ee.Filter.eq('LANDSAT_SCENE_ID', 'LM50450301986215AAA03')).first(); 1085 | * 1086 | * // Apply MSScvm to the single image. 1087 | * var mssToaImgMsscvm = msslib.applyMsscvm(mssToaImg); 1088 | * 1089 | * // Display the results. 1090 | * Map.centerObject(mssToaImgMsscvm, 9); 1091 | * Map.setOptions('SATELLITE'); 1092 | * Map.addLayer(mssToaImg, msslib.visToa, 'TOA image'); 1093 | * Map.addLayer(mssToaImgMsscvm, msslib.visToa, 'TOA image masked'); 1094 | * 1095 | * // Apply MSScvm to all images in collection. 1096 | * var mssToaColMsscvm = mssToaCol.map(msslib.applyMsscvm); 1097 | * print(mssToaColMsscvm.limit(5)); 1098 | */ 1099 | function applyMsscvm(img) { 1100 | var dem = getDem(img); 1101 | var water = waterLayer(img); 1102 | var b4c = topoCorrB4(img, dem); 1103 | var clouds = cloudLayer(img); 1104 | var shadows = shadowLayer(img, dem, clouds); 1105 | var mask = clouds.add(shadows).eq(0); 1106 | return img.updateMask(mask); 1107 | } 1108 | exports.applyMsscvm = applyMsscvm; 1109 | --------------------------------------------------------------------------------