1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
.. module:: usgs.scripts
.. cli:
USGS CLI
========
This library comes with a command line interface to expose many common requests, such as authenticating, searching, downloading, and obtaining metadata.
Here's an example of what can be done using the cli and GitHub Gists.
.. code-block:: bash
usgs search --node EE EO1_HYP_PUB --start-date 20150401 --end-date 20150501 --geojson | gist -f hyperion-20150401-20150501.geojson
.. .. raw:: html
<div style="margin-top:10px; margin-bottom:20px">
<iframe class='ghmap' width="640" height="400" src="https://render.githubusercontent.com/view/geojson/?url=https%3A%2F%2Fgist.githubusercontent.com%2Fkapadia%2F6e722427cecd9ac79971%2Fraw%2Fhyperion-20150401-20150501.geojson#aa859151-d85a-414d-865c-9704fae891a1" frameborder="0"></iframe>
</div>
Login
-----
.. code-block:: bash
usgs login [USGS username] [USGS password]
Logout
------
.. code-block:: bash
usgs logout [USGS username] [USGS password]
Search
------
.. code-block:: bash
usgs search [dataset] --start-date [start date] --end-date [end date] --longitude [lng] --latitude [lat] --node [node]
Suppose you're interested in declassified satellite imagery. The datasets ``CORONA2`` or ``DECLASSII`` can be queried. If you have a GeoJSON file with an AOI, you can pipe the file to ``usgs search``.
.. code-block:: bash
cat chile.geojson | usgs search --node EE DECLASSII --start-date 19700101 --end-date 19800101 --geojson | gist -f declassii-chile-1970s.geojson
.. .. raw:: html
<div style="margin-top:10px; margin-bottom:20px">
<iframe class='ghmap' width="640" height="400" src="https://render.githubusercontent.com/view/geojson/?url=https%3A%2F%2Fgist.githubusercontent.com%2Fkapadia%2Ffd15d4082da2ec47dbc5%2Fraw%2Fdeclassii-chile-1970s.geojson#08b6ad6d-046d-4fac-9ada-553356358235" frameborder="0"></iframe>
</div>
<script>
window. {
var mainEl = document.querySelector('div[role="main"]');
var mapElems = document.querySelectorAll('.ghmap');
for (var i = 0; i < mapElems.length; i++) {
mapElems[i].width = mainEl.clientWidth;
}
}
window.onresize();
</script>
Metadata
--------
.. code-block:: bash
usgs metadata [dataset] [entity/scene id 1] [entity/scene id 2] ... [entity/scene id n]
Suppose you want metadata from a couple scenes taken by Hyperion.
.. code-block:: bash
$ usgs metadata --node EE EO1_HYP_PUB EO1H1820422014302110K2_SG1_01 EO1H1830422015093110KF_TR2_01 | jq ""
{
"errorCode": null,
"executionTime": 1.676698923111,
"data": [
{
"metadataUrl": "https://earthexplorer.usgs.gov/metadata/xml/1854/EO1H1820422014302110K2_SG1_01/",
"upperLeftCoordinate": {
"latitude": 26.253489,
"longitude": 21.53022
},
"fgdcMetadataUrl": "https://earthexplorer.usgs.gov/fgdc/1854/EO1H1820422014302110K2_SG1_01/save_xml",
"displayId": "EO1H1820422014302110K2_SG1_01",
"acquisitionDate": "2014-10-29",
"browseUrl": "https://earthexplorer.usgs.gov/browse/eo-1/hyp/182/42/2014/EO11820422014302110K2_SG1_01.jpeg",
"dataAccessUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1820422014302110K2_SG1_01&node=INVSVC",
"orderUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1820422014302110K2_SG1_01&node=INVSVC",
"upperRightCoordinate": {
"latitude": 26.240475,
"longitude": 21.602509
},
"summary": "Entity ID: EO1H1820422014302110K2_SG1_01, Acquisition Date: 29-OCT-14, Target Path: 182, Target Row: 42",
"downloadUrl": "https://earthexplorer.usgs.gov/download/external/options/EO1_HYP_PUB/EO1H1820422014302110K2_SG1_01/INVSVC/",
"lowerLeftCoordinate": {
"latitude": 24.365584,
"longitude": 21.074194
},
"modifiedDate": "2017-03-22",
"startTime": "2014-10-29",
"sceneBounds": "21.074194,24.352528,21.602509,26.253489",
"ordered": false,
"entityId": "EO1H1820422014302110K2_SG1_01",
"endTime": "2014-10-29",
"lowerRightCoordinate": {
"latitude": 24.352528,
"longitude": 21.145425
},
"bulkOrdered": false
},
{
"metadataUrl": "https://earthexplorer.usgs.gov/metadata/xml/1854/EO1H1830422015093110KF_TR2_01/",
"upperLeftCoordinate": {
"latitude": 25.663285,
"longitude": 20.41565
},
"fgdcMetadataUrl": "https://earthexplorer.usgs.gov/fgdc/1854/EO1H1830422015093110KF_TR2_01/save_xml",
"displayId": "EO1H1830422015093110KF_TR2_01",
"acquisitionDate": "2015-04-03",
"browseUrl": "https://earthexplorer.usgs.gov/browse/eo-1/hyp/183/42/2015/EO11830422015093110KF_TR2_01.jpeg",
"dataAccessUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1830422015093110KF_TR2_01&node=INVSVC",
"orderUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1830422015093110KF_TR2_01&node=INVSVC",
"upperRightCoordinate": {
"latitude": 25.650833,
"longitude": 20.489455
},
"summary": "Entity ID: EO1H1830422015093110KF_TR2_01, Acquisition Date: 03-APR-15, Target Path: 183, Target Row: 42",
"downloadUrl": "https://earthexplorer.usgs.gov/download/external/options/EO1_HYP_PUB/EO1H1830422015093110KF_TR2_01/INVSVC/",
"lowerLeftCoordinate": {
"latitude": 24.800065,
"longitude": 20.220225
},
"modifiedDate": "2017-03-22",
"startTime": "2015-04-03",
"sceneBounds": "20.220225,24.787699,20.489455,25.663285",
"ordered": false,
"entityId": "EO1H1830422015093110KF_TR2_01",
"endTime": "2015-04-03",
"lowerRightCoordinate": {
"latitude": 24.787699,
"longitude": 20.293527
},
"bulkOrdered": false
}
],
"api_version": "1.2.1",
"error": ""
}
Unfortunately, this is not all the metadata available for each scene. More metadata is found behind the ``metadataUrl``. Using the ``extended`` flag will send a second request to USGS, and aggregrate the results in the returned JSON.
.. code-block:: bash
$ usgs metadata --node EE EO1_HYP_PUB EO1H1820422014302110K2_SG1_01 EO1H1830422015093110KF_TR2_01 --extended | jq ""
{
"errorCode": null,
"executionTime": 1.5633571147919,
"data": [
{
"metadataUrl": "https://earthexplorer.usgs.gov/metadata/xml/1854/EO1H1820422014302110K2_SG1_01/",
"upperLeftCoordinate": {
"latitude": 26.253489,
"longitude": 21.53022
},
"fgdcMetadataUrl": "https://earthexplorer.usgs.gov/fgdc/1854/EO1H1820422014302110K2_SG1_01/save_xml",
"displayId": "EO1H1820422014302110K2_SG1_01",
"acquisitionDate": "2014-10-29",
"browseUrl": "https://earthexplorer.usgs.gov/browse/eo-1/hyp/182/42/2014/EO11820422014302110K2_SG1_01.jpeg",
"dataAccessUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1820422014302110K2_SG1_01&node=INVSVC",
"orderUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1820422014302110K2_SG1_01&node=INVSVC",
"upperRightCoordinate": {
"latitude": 26.240475,
"longitude": 21.602509
},
"summary": "Entity ID: EO1H1820422014302110K2_SG1_01, Acquisition Date: 29-OCT-14, Target Path: 182, Target Row: 42",
"downloadUrl": "https://earthexplorer.usgs.gov/download/external/options/EO1_HYP_PUB/EO1H1820422014302110K2_SG1_01/INVSVC/",
"lowerLeftCoordinate": {
"latitude": 24.365584,
"longitude": 21.074194
},
"extended": {
"NE Corner Long": "21&deg;35'20.41"E",
"NW Corner Long": "21&deg;30'58.05"E",
"Entity ID": "EO1H1820422014302110K2_SG1_01",
"Sun Elevation": "38.506879",
"NW Corner Lat dec": "26.178639",
"Station": "SG1",
"Center Latitude dec": "25.233517",
"Target Path": "182",
"SE Corner Long": "21&deg;08'06.46"E",
"Look Angle": "2.2046",
"SW Corner Long dec": "21.063363",
"Scene Start Time": "2014:302:07:58:59.273",
"Cloud Cover": "10% to 19% Cloud Cover",
"NW Corner Lat": "26&deg;10'43.10"N",
"SW Corner Lat dec": "24.302885",
"Orbit Row": "42",
"NE Corner Lat": "26&deg;09'50.63"N",
"Target Row": "42",
"Date Entered": "2014/10/29",
"NW Corner Long dec": "21.516126",
"Processing Level": "L1T Product Available",
"Center Longtude dec": "21.325905",
"NE Corner Lat dec": "26.164064",
"SE Corner Long dec": "21.135127",
"Center Latitude": "25&deg;14'00.66"N",
"SW Corner Long": "21&deg;03'48.11"E",
"NE Corner Long dec": "21.589002",
"SE Corner Lat dec": "24.288481",
"Acquisition Date": "2014/10/29",
"Scene Stop Time": "2014:302:07:59:31.273",
"SE Corner Lat": "24&deg;17'18.53"N",
"Satellite Inclination": "97.96",
"Orbit Path": "182",
"Center Longitude": "21&deg;19'33.26"E",
"SW Corner Lat": "24&deg;18'10.39"N",
"Sun Azimuth": "134.735736"
},
"modifiedDate": "2017-03-22",
"startTime": "2014-10-29",
"sceneBounds": "21.074194,24.352528,21.602509,26.253489",
"ordered": false,
"entityId": "EO1H1820422014302110K2_SG1_01",
"endTime": "2014-10-29",
"lowerRightCoordinate": {
"latitude": 24.352528,
"longitude": 21.145425
},
"bulkOrdered": false
},
{
"metadataUrl": "https://earthexplorer.usgs.gov/metadata/xml/1854/EO1H1830422015093110KF_TR2_01/",
"upperLeftCoordinate": {
"latitude": 25.663285,
"longitude": 20.41565
},
"fgdcMetadataUrl": "https://earthexplorer.usgs.gov/fgdc/1854/EO1H1830422015093110KF_TR2_01/save_xml",
"displayId": "EO1H1830422015093110KF_TR2_01",
"acquisitionDate": "2015-04-03",
"browseUrl": "https://earthexplorer.usgs.gov/browse/eo-1/hyp/183/42/2015/EO11830422015093110KF_TR2_01.jpeg",
"dataAccessUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1830422015093110KF_TR2_01&node=INVSVC",
"orderUrl": "https://earthexplorer.usgs.gov/order/process?dataset_name=EO1_HYP_PUB&ordered=EO1H1830422015093110KF_TR2_01&node=INVSVC",
"upperRightCoordinate": {
"latitude": 25.650833,
"longitude": 20.489455
},
"summary": "Entity ID: EO1H1830422015093110KF_TR2_01, Acquisition Date: 03-APR-15, Target Path: 183, Target Row: 42",
"downloadUrl": "https://earthexplorer.usgs.gov/download/external/options/EO1_HYP_PUB/EO1H1830422015093110KF_TR2_01/INVSVC/",
"lowerLeftCoordinate": {
"latitude": 24.800065,
"longitude": 20.220225
},
"extended": {
"NE Corner Long": "20&deg;28'20.11"E",
"NW Corner Long": "20&deg;23'52.21"E",
"Entity ID": "EO1H1830422015093110KF_TR2_01",
"Sun Elevation": "42.984461",
"NW Corner Lat dec": "25.587842",
"Station": "TR2",
"Center Latitude dec": "25.15576",
"Target Path": "183",
"SE Corner Long": "20&deg;16'43.78"E",
"Look Angle": "-10.588",
"SW Corner Long dec": "20.20492",
"Scene Start Time": "2015:093:07:44:06.278",
"Cloud Cover": "0 to 9% Cloud Cover",
"NW Corner Lat": "25&deg;35'16.23"N",
"SW Corner Lat dec": "24.737627",
"Orbit Row": "43",
"NE Corner Lat": "25&deg;34'25.92"N",
"Target Row": "42",
"Date Entered": "2015/04/03",
"NW Corner Long dec": "20.397836",
"Processing Level": "L1T Product Available",
"Center Longtude dec": "20.33846",
"NE Corner Lat dec": "25.573867",
"SE Corner Long dec": "20.278828",
"Center Latitude": "25&deg;09'20.74"N",
"SW Corner Long": "20&deg;12'17.71"E",
"NE Corner Long dec": "20.472254",
"SE Corner Lat dec": "24.723703",
"Acquisition Date": "2015/04/03",
"Scene Stop Time": "2015:093:07:44:21.278",
"SE Corner Lat": "24&deg;43'25.33"N",
"Satellite Inclination": "97.98",
"Orbit Path": "182",
"Center Longitude": "20&deg;20'18.46"E",
"SW Corner Lat": "24&deg;44'15.46"N",
"Sun Azimuth": "107.463027"
},
"modifiedDate": "2017-03-22",
"startTime": "2015-04-03",
"sceneBounds": "20.220225,24.787699,20.489455,25.663285",
"ordered": false,
"entityId": "EO1H1830422015093110KF_TR2_01",
"endTime": "2015-04-03",
"lowerRightCoordinate": {
"latitude": 24.787699,
"longitude": 20.293527
},
"bulkOrdered": false
}
],
"api_version": "1.2.1",
"error": ""
}
Download Options
----------------
.. code-block:: bash
usgs download-options [dataset] [entity/scene id] --node [node]
Download URL
------------
.. code-block:: bash
usgs download-url [dataset] [entity/scene id] --node [node] --product [product]
|