nst-guide / data

Create map waypoints and layers from open data sources
https://nst-guide.github.io/data/
GNU General Public License v3.0
6 stars 0 forks source link

Sentinel Imagery #35

Open kylebarron opened 4 years ago

kylebarron commented 4 years ago

Imagery is collected in the Military Grid Reference System. Here's a KML you can use to find imagery intersections with the trail.

The Sentinel AWS Readme lists how the file structure is set up. So for example, the UTM grid square that intersects Glacier Peak in WA, on July 22, 2019 is here:

> aws s3 ls s3://sentinel-s2-l2a/tiles/10/U/FU/2019/7/22/0/ --request-payer
                           PRE R10m/
                           PRE R20m/
                           PRE R60m/
                           PRE auxiliary/
                           PRE qi/
2019-07-22 21:15:40     553239 metadata.xml
2019-07-22 21:15:49       1035 productInfo.json
2019-07-22 21:15:40       1491 tileInfo.json

The tileInfo.json has helpful information, including a GeoJSON representation of the geometry of the square, (not in WGS84), cloudyPixelPercentage(!!), and the path to the image.

{
  "path" : "tiles/10/U/FU/2019/7/22/0",
  "timestamp" : "2019-07-22T19:11:13.752Z",
  "utmZone" : 10,
  "latitudeBand" : "U",
  "gridSquare" : "FU",
  "datastrip" : {
    "id" : "S2A_OPER_MSI_L2A_DS_SGS__20190722T231540_S20190722T190551_N02.13",
    "path" : "products/2019/7/22/S2A_MSIL2A_20190722T185921_N0213_R013_T10UFU_20190722T231540/datastrip/0"
  },
  "tileGeometry" : {
    "type" : "Polygon",
    "crs" : {
      "type" : "name",
      "properties" : {
        "name" : "urn:ogc:def:crs:EPSG:8.8.1:32610"
      }
    },
    "coordinates" : [ [ [ 600000.0, 5400000.0 ], [ 709800.0, 5400000.0 ], [ 709800.0, 5290200.0 ], [ 600000.0, 5290200.0 ], [ 600000.0, 5400000.0 ] ] ]
  },
  "tileDataGeometry" : {
    "type" : "Polygon",
    "crs" : {
      "type" : "name",
      "properties" : {
        "name" : "urn:ogc:def:crs:EPSG:8.8.1:32610"
      }
    },
    "coordinates" : [ [ [ 600001.0, 5399999.0 ], [ 709799.0, 5399999.0 ], [ 709799.0, 5290201.0 ], [ 600001.0, 5290201.0 ], [ 600001.0, 5399999.0 ] ] ]
  },
  "tileOrigin" : {
    "type" : "Point",
    "crs" : {
      "type" : "name",
      "properties" : {
        "name" : "urn:ogc:def:crs:EPSG:8.8.1:32610"
      }
    },
    "coordinates" : [ 600000.0, 5400000.0 ]
  },
  "dataCoveragePercentage" : 100.0,
  "cloudyPixelPercentage" : 0.0,
  "productName" : "S2A_MSIL2A_20190722T185921_N0213_R013_T10UFU_20190722T231540",
  "productPath" : "products/2019/7/22/S2A_MSIL2A_20190722T185921_N0213_R013_T10UFU_20190722T231540"
}

If you look into a given folder for (utm square / year / month / day / snapshot number / resolution), you'll see this:

> aws s3 ls s3://sentinel-s2-l2a/tiles/10/U/EU/2019/7/22/0/R60m/ --request-payer
2019-07-22 21:07:22     512645 AOT.jp2
2019-07-22 21:07:22    2840382 B01.jp2
2019-07-22 21:07:22    3182126 B02.jp2
2019-07-22 21:07:22    3344222 B03.jp2
2019-07-22 21:07:22    3297405 B04.jp2
2019-07-22 21:07:22    3529444 B05.jp2
2019-07-22 21:07:22    3755698 B06.jp2
2019-07-22 21:07:22    3736390 B07.jp2
2019-07-22 21:07:22    3341917 B08.jp2
2019-07-22 21:07:22    3750817 B09.jp2
2019-07-22 21:07:22    3707894 B11.jp2
2019-07-22 21:07:22    3553773 B12.jp2
2019-07-22 21:07:22    3727852 B8A.jp2
2019-07-22 21:07:22     317802 SCL.jp2
2019-07-22 21:07:22    3711655 TCI.jp2
2019-07-22 21:07:22    3152856 WVP.jp2

Each of the B*.jp2 files are a different band. Wikipedia explains which band is which. However, easiest for my purposes is TCI.jp2, which stands for True Color Image I think. For the 10m resolution, each file is around 129MB.

If you download a few images and run gdal2tiles.py --srcnodata="0,0,0" *.jp2 tiles, you can get an image like this:

image

--srcnodata="0,0,0" means that all fully black areas will become transparent, as seen above. The path of the satellites means that it won't always be simple to find continuous bands to display.

Note that Lambda isn't really a great place for this processing, since it has a scratch disk space limit of 500MB.

Note that while signed in to the aws cli, you need to add --request-payer to do anything with a requester pays bucket. I.e.

aws s3 ls s3://sentinel-s2-l2a/ --request-payer
kylebarron commented 4 years ago

Still worth a look at https://sentinelhub-py.readthedocs.io/ to see if it would make downloading easier

kylebarron commented 4 years ago

And awesome-sentinel: https://github.com/Fernerkundung/awesome-sentinel#search--download

kylebarron commented 4 years ago

Note that when you're creating the tiles, you should try to use -addalpha instead of applying -srcnodata on the black portions. This doesn't work for fstopo because it has a color table and not rgb bands, but I'm pretty sure Sentinel has rgb bands.

gdalbuildvrt -b 1 -b 2 -b 3 -addalpha naip.vrt *.jp2

See https://github.com/nst-guide/naip/issues/1