搜索、下载和预处理陆地卫星图像

pylandsat的Python项目详细描述


说明

pylandsat是一个python包,允许您搜索和下载 托管在上的公共数据集中的陆地卫星场景 Google Cloud。 此外,它还包括一组类和方法来访问 对下载的场景进行预处理。

仅支持陆地卫星Collection 1,即来自以下传感器和卫星任务的一级数据产品:

  • 陆地卫星8号奥利/蒂尔斯
  • 陆地卫星7号ETM+
  • 陆地卫星4-5 TM
  • 陆地卫星1-5号

安装

pip install pylandsat

命令行界面

下载一个或多个场景

使用量

Usage: pylandsat download [OPTIONS][PRODUCTS]...

  Download a Landsat product according to its identifier.

Options:
  -d, --output-dir PATH  Output directory.
  -f, --files TEXT       Comma-separated list of files to download.
  --help                 Show this message and exit.

示例

# Download an entire product in the current directory
pylandsat download LE07_L1TP_205050_19991104_20170216_01_T1

# Download multiple products
pylandsat download \
    LE07_L1TP_205050_19991104_20170216_01_T1 \
    LE07_L1TP_206050_19991111_20170216_01_T1

# Download only the blue, green and red bands
pylandsat download --files B1.TIF,B2.TIF,B3.TIF \
    LE07_L1TP_205050_19991104_20170216_01_T1

# Download only quality band
pylandsat download --files BQA.TIF \
    LE07_L1TP_205050_19991104_20170216_01_T1

搜索场景

为了允许大而快的查询,pylandsat与托管在google云上的landsat目录的本地转储一起工作。因此,需要初始同步:

# Sync local Landsat catalog
pylandsat sync-database

# Force update
pylandsat -f sync-database

数据库存储在可使用以下命令显示的本地目录中:

pylandsat print-datadir

创建数据库后,可以查询本地目录。

使用量

Usage: pylandsat search [OPTIONS]

  Search for scenes in the Google Landsat Public Dataset catalog.

Options:
  -b, --begin TEXT       Begin search date (YYYY-MM-DD).
  -e, --end TEXT         End search date (YYYY-MM-DD).
  -g, --geojson PATH     Area of interest (GeoJSON file).
  -l, --latlon FLOAT...  Point of interest (decimal lat/lon).
  -p, --path INTEGER     WRS2 path.
  -r, --row INTEGER      WRS2 row.
  -c, --clouds FLOAT     Max. cloud cover percentage.
  -s, --sensors TEXT     Comma-separated list of possible sensors.
  -t, --tiers TEXT       Comma-separated list of possible collection tiers.
  --slcoff               Include SLC-off LE7 scenes.
  -o, --output PATH      Output CSV file.
  --help                 Show this message and exit.

必须提供至少三个选项:--begin--end(即兴趣期),以及地理范围(--path--row--latlon--address--geojson)。默认情况下,pylandsat列出与查询匹配的所有产品ID。可以使用--output选项将完整响应导出到csv文件。请注意,空间范围是作为geojson文件提供的,只考虑第一个特性。

示例

# If only the year is provided, date is set to January 1st
pylandsat search \
    --begin 1999 --end 2000\
    --path 206 --row 50\
    --clouds 0# Using latitude and longitude
pylandsat search \
    --begin 2000 --end 2010\
    --latlon 50.85 4.34

# Using a polygon in a GeoJSON file
pylandsat search \
    --begin 2000 --end 2010\
    --geojson brussels.geojson

# Using an address that will be geocoded
pylandsat search \
    --begin 2000 --end 2010\
    --address 'Brussels, Belgium'# Limit to TM and ETM sensors
pylandsat search \
    --begin 1990 --end 2010\
    --address 'Brussels, Belgium'\
    --sensors LT04,LT05,LE07

# Export results into a CSV file
pylandsat search \
    --begin 1990 --end 2010\
    --address 'Brussels, Belgium'\
    --sensors LT04,LT05,LE07 \
    --output scenes.csv
# List available sensors, i.e. possible values# for the `--sensors` option
pylandsat list-sensors

# List available files for a given sensor
pylandsat list-available-files LT05

python api

搜索目录

fromdatetimeimportdatetimeimportpandasaspdfromshapely.geometryimportPointfrompylandsatimportCatalog,Productcatalog=Catalog()begin=datetime(2000,1,1)end=datetime(2010,1,1)geom=Point(4.34,50.85)# Results are returned as a pandas dataframescenes=catalog.search(begin=begin,end=end,geom=geom,sensors=['ETM','LC08'])# Get the product ID of the scene with the lowest cloud coverscenes=scenes.sort_values(by='cloud_cover',ascending=True)product_id=scenes.index[0]# Download the sceneproduct=Product(product_id)product.download(out_dir='data')

加载和预处理数据

importnumpyasnpimportrasterioimportmatplotlib.pyplotaspltfrompylandsatimportScene# Access datascene=Scene('data/LE07_L1TP_205050_19991104_20170216_01_T1')print(scene.available_bands())print(scene.product_id)print(scene.sensor)print(scene.date)# Access MTL metadataprint(scene.mtl['IMAGE_ATTRIBUTES']['CLOUD_COVER_LAND'])# Quality bandplt.imshow(scene.quality.read())# Access band datanir=scene.nir.read(1)red=scene.red.read(1)ndvi=(nir+red)/(nir-red)# Access band metadataprint(scene.nir.bname)print(scene.nir.fname)print(scene.nir.profile)print(scene.nir.width,scene.nir.height)print(scene.nir.crs)# Use reflectance values instead of DNnir=scene.nir.to_reflectance()# ..or brightness temperaturetirs=scene.tirs.to_brightness_temperature()# Save file to diskwithrasterio.open('temperature.tif','w',**scene.tirs.profile)asdst:dst.write(tirs,1)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在java中使用鼠标在画布上绘制线而不使用Swing   java如何调试库代码中发生的NullPointerException?   java GWT在发送前在JSON中序列化POST参数   java如何在失去internet连接时停止脚本执行,并在重新连接internet时重新恢复?   尝试通过上下文菜单更新适配器时引发java Null异常   如果不更改Jersey路径,java执行器端点将无法工作   java Spring AuthenticationManager是否将有效令牌保存在内存中的某个位置?   java游戏!2.0应用程序启动时数据库覆盖。(MYSQL)   java使用spring表达式语言计算二维数组中的单元格   java为什么在这个Spring应用程序中使用JdbcTemplate BeanPropertyRowMapper类时获得这个实例化异常?   在Java中使用自定义JMXAuthenticator以编程方式从客户端远程连接到JMX的身份验证   hibernate JBoss+Java:尝试使用其他模块会话对象时出现事务未激活错误   java在JavaFX setOnAction()方法中写入OutputStream   java Spring AWS上下文凭据不工作   将@index添加到字段后,java Objectify筛选器不起作用   java我在Mac上安装了java6和java8,我使用的是哪一种?   java下面这两种语言的区别是什么?