5 : "nir" ,
6 : "swir1" ,
7 : "swir2" ,
+ 8 : "pan" ,
10 : "thermal" ,
}
BAND_TITLES = {
@@ -345,6 +403,7 @@ Source code for xlandsat._io
5 : "near-infrared" ,
6 : "short-wave infrared 1" ,
7 : "short-wave infrared 2" ,
+ 8 : "panchromatic" ,
10 : "thermal" ,
}
BAND_UNITS = {
@@ -355,6 +414,7 @@ Source code for xlandsat._io
5 : "reflectance" ,
6 : "reflectance" ,
7 : "reflectance" ,
+ 8 : "reflectance" ,
10 : "Kelvin" ,
}
@@ -424,69 +484,187 @@ Source code for xlandsat._io
"""
path = pathlib . Path ( path )
if bands is None :
- bands = BAND_NAMES . values ()
- if path . is_file () and ".tar" in path . suffixes :
- reader_class = TarReader
- else :
- reader_class = FolderReader
- with reader_class ( path ) as reader :
+ bands = [
+ "coastal_aerosol" ,
+ "blue" ,
+ "green" ,
+ "red" ,
+ "nir" ,
+ "swir1" ,
+ "swir2" ,
+ "thermal" ,
+ ]
+ with choose_reader ( path )( path ) as reader :
metadata = reader . read_metadata ()
- available_bands = [ int ( str ( f ) . split ( "_B" )[ - 1 ][: - 4 ]) for f in reader . band_files ]
- scene_region = (
- metadata [ "corner_ll_projection_x_product" ],
- metadata [ "corner_lr_projection_x_product" ],
- metadata [ "corner_ll_projection_y_product" ],
- metadata [ "corner_ul_projection_y_product" ],
- )
- shape = ( metadata [ "reflective_lines" ], metadata [ "reflective_samples" ])
- coords = {
- "easting" : np . linspace ( * scene_region [: 2 ], shape [ 1 ]),
- "northing" : np . linspace ( * scene_region [ 2 :], shape [ 0 ]),
- }
+ coords = coordinates_from_metadata ( metadata , "reflective" )
data_vars = {}
- dims = ( "northing" , "easting" )
- for number , fname in zip ( available_bands , reader . band_files ):
+ for fname in reader . band_files :
+ number = int ( str ( fname ) . split ( "_B" )[ - 1 ][: - 4 ])
if BAND_NAMES [ number ] not in bands :
continue
- mult , add = None , None
- mult_entries = [ f "mult_band_ { number } " , f "mult_band_st_b { number } " ]
- add_entries = [ f "add_band_ { number } " , f "add_band_st_b { number } " ]
- for key in metadata :
- if any ( key . endswith ( entry ) for entry in mult_entries ):
- mult = metadata [ key ]
- if any ( key . endswith ( entry ) for entry in add_entries ):
- add = metadata [ key ]
- band = reader . read_band ( fname ) . astype ( dtype )[:: - 1 , :]
- band [ band == 0 ] = np . nan
- band *= mult
- band += add
- band_attrs = {
- "long_name" : BAND_TITLES [ number ],
- "units" : BAND_UNITS [ number ],
- "number" : number ,
- "filename" : pathlib . Path ( fname ) . name ,
- "scaling_mult" : mult ,
- "scaling_add" : add ,
- }
- data_vars [ BAND_NAMES [ number ]] = xr . DataArray (
- data = band ,
- dims = dims ,
- coords = coords ,
- attrs = band_attrs ,
- name = BAND_NAMES [ number ],
+ data_vars [ BAND_NAMES [ number ]] = read_and_scale_band (
+ fname , reader , dtype , number , coords , metadata , region
)
- if region is not None :
- data_vars [ BAND_NAMES [ number ]] = data_vars [ BAND_NAMES [ number ]] . sel (
- easting = slice ( * region [: 2 ]), northing = slice ( * region [ 2 :])
- )
- attrs = {
- "Conventions" : "CF-1.8" ,
- "title" : (
- f " { metadata [ 'spacecraft_id' ] . replace ( '_' , ' ' ) . title () } scene from "
- f " { metadata [ 'date_acquired' ] } "
- f "(path/row= { metadata [ 'wrs_path' ] } / { metadata [ 'wrs_row' ] } )"
- ),
+ if data_vars :
+ scene = xr . Dataset ( data_vars , attrs = attrs_from_metadata ( metadata ))
+ scene . easting . attrs = {
+ "long_name" : "UTM easting" ,
+ "standard_name" : "projection_x_coordinate" ,
+ "units" : "m" ,
+ }
+ scene . northing . attrs = {
+ "long_name" : "UTM northing" ,
+ "standard_name" : "projection_y_coordinate" ,
+ "units" : "m" ,
+ }
+ return scene
+ else :
+ raise ValueError (
+ f "No Landsat Collection 2 Level 2 band files found in ' { str ( path ) } '."
+ )
+
+
+[docs] def load_panchromatic ( path , region = None , dtype = "float32" ):
+
"""
+
Load the panchromatic band from a USGS EarthExplorer Level 1 Landsat scene.
+
+
Can read from a folder with the ``*.TIF`` file and an ``*_MTL.txt`` file or
+
directly from a tar archive (compressed or not) without the need to first
+
unpack the archive. The band is converted to reflectance units using
+
appropriate scaling parameters and UTM coordinates are set in the returned
+
:class:`xarray.DataArray`.
+
+
.. important::
+
+
Do not rename the TIF or MTL files. The folder/archive can have any
+
name but TIF and MTL files need their original names.
+
+
.. note::
+
+
Only supports Landsat 8 and 9 Collection 2 Level 1 scenes containing
+
the panchromatic band.
+
+
Parameters
+
----------
+
path : str or :class:`pathlib.Path`
+
The path to a folder or tar archive containing the TIF file for the
+
panchromatic band. **Must** include the ``*_MTL.txt`` metadata file.
+
Other band files may be present but will be ignored.
+
region : None or list
+
Crop the band to this bounding box given as a list of West, East,
+
South, and North coordinate values (UTM in meters). If None, no
+
cropping is performed on the band. Default is None.
+
dtype : str or numpy dtype object
+
The type used for the band array. Integer types will result in rounding
+
so floating point is recommended. Default is float16.
+
+
Returns
+
-------
+
panchromatic : :class:`xarray.DataArray`
+
The loaded band including UTM easting and northing as dimensional
+
coordinates and metadata read from the MTL file and other CF compliant
+
fields in the ``attrs`` attribute.
+
"""
+
path = pathlib . Path ( path )
+
with choose_reader ( path )( path ) as reader :
+
metadata = reader . read_metadata ()
+
coords = coordinates_from_metadata ( metadata , "panchromatic" )
+
available_bands = {
+
int ( str ( fname ) . split ( "_B" )[ - 1 ][: - 4 ]): fname for fname in reader . band_files
+
}
+
if 8 not in available_bands :
+
raise ValueError (
+
f "Could not find the panchromatic band (8) in ' { str ( path ) } '."
+
)
+
band = read_and_scale_band (
+
available_bands [ 8 ], reader , dtype , 8 , coords , metadata , region
+
)
+
attrs = dict ( band . attrs )
+
attrs . update ( attrs_from_metadata ( metadata ))
+
attrs [ "title" ] = (
+
f " { metadata [ 'spacecraft_id' ] . replace ( '_' , ' ' ) . title () } panchromatic band from "
+
f " { metadata [ 'date_acquired' ] } "
+
f "(path/row= { metadata [ 'wrs_path' ] } / { metadata [ 'wrs_row' ] } )"
+
)
+
band . attrs = attrs
+
band . easting . attrs = {
+
"long_name" : "UTM easting" ,
+
"standard_name" : "projection_x_coordinate" ,
+
"units" : "m" ,
+
}
+
band . northing . attrs = {
+
"long_name" : "UTM northing" ,
+
"standard_name" : "projection_y_coordinate" ,
+
"units" : "m" ,
}
+
return band
+
+
+def read_and_scale_band ( fname , reader , dtype , number , coords , metadata , region ):
+ """
+ Read the band and return a DataArray with the scaled values.
+ """
+ band_data = reader . read_band ( fname ) . astype ( dtype )[:: - 1 , :]
+ band_data [ band_data == 0 ] = np . nan
+ mult , add = scaling_parameters ( metadata , number )
+ band_data *= mult
+ band_data += add
+ band = xr . DataArray (
+ data = band_data ,
+ dims = ( "northing" , "easting" ),
+ name = BAND_NAMES [ number ],
+ coords = coords ,
+ attrs = {
+ "long_name" : BAND_TITLES [ number ],
+ "units" : BAND_UNITS [ number ],
+ "number" : number ,
+ "filename" : pathlib . Path ( fname ) . name ,
+ "scaling_mult" : mult ,
+ "scaling_add" : add ,
+ },
+ )
+ if region is not None :
+ band = band . sel ( easting = slice ( * region [: 2 ]), northing = slice ( * region [ 2 :]))
+ return band
+
+
+def scaling_parameters ( metadata , number ):
+ """
+ Get the scaling parameters for the band of the given number.
+ """
+ mult , add = None , None
+ mult_entries = [ f "mult_band_ { number } " , f "mult_band_st_b { number } " ]
+ add_entries = [ f "add_band_ { number } " , f "add_band_st_b { number } " ]
+ for key in metadata :
+ if any ( key . endswith ( entry ) for entry in mult_entries ):
+ mult = metadata [ key ]
+ if any ( key . endswith ( entry ) for entry in add_entries ):
+ add = metadata [ key ]
+ return mult , add
+
+
+def coordinates_from_metadata ( metadata , band_type ):
+ """
+ Generate the UTM pixel coordinate arrays from the metadata.
+ """
+ shape = ( metadata [ f " { band_type } _lines" ], metadata [ f " { band_type } _samples" ])
+ scene_region = (
+ metadata [ "corner_ll_projection_x_product" ],
+ metadata [ "corner_lr_projection_x_product" ],
+ metadata [ "corner_ll_projection_y_product" ],
+ metadata [ "corner_ul_projection_y_product" ],
+ )
+ coords = {
+ "easting" : np . linspace ( * scene_region [: 2 ], shape [ 1 ]),
+ "northing" : np . linspace ( * scene_region [ 2 :], shape [ 0 ]),
+ }
+ return coords
+
+
+def attrs_from_metadata ( metadata ):
+ """
+ Create the xarray attrs dictionary from the metadata dictionary.
+ """
metadata_to_keep = [
"digital_object_identifier" ,
"origin" ,
@@ -506,19 +684,27 @@ Source code for xlandsat._io
"wrs_row" ,
"mtl_file" ,
]
- attrs . update ({ key : metadata [ key ] for key in metadata_to_keep })
- scene = xr . Dataset ( data_vars , attrs = attrs )
- scene . easting . attrs = {
- "long_name" : "UTM easting" ,
- "standard_name" : "projection_x_coordinate" ,
- "units" : "m" ,
- }
- scene . northing . attrs = {
- "long_name" : "UTM northing" ,
- "standard_name" : "projection_y_coordinate" ,
- "units" : "m" ,
+ attrs = {
+ "Conventions" : "CF-1.8" ,
+ "title" : (
+ f " { metadata [ 'spacecraft_id' ] . replace ( '_' , ' ' ) . title () } scene from "
+ f " { metadata [ 'date_acquired' ] } "
+ f "(path/row= { metadata [ 'wrs_path' ] } / { metadata [ 'wrs_row' ] } )"
+ ),
}
- return scene
+ attrs . update ({ key : metadata [ key ] for key in metadata_to_keep })
+ return attrs
+
+
+def choose_reader ( path ):
+ """
+ Return the appropriate reader class depending on what "path" is.
+ """
+ if path . is_file () and ".tar" in path . suffixes :
+ reader_class = TarReader
+ else :
+ reader_class = FolderReader
+ return reader_class
def parse_metadata ( text ):
@@ -548,6 +734,8 @@ Source code for xlandsat._io
"UTM_ZONE" ,
"REFLECTIVE_LINES" ,
"REFLECTIVE_SAMPLES" ,
+ "PANCHROMATIC_LINES" ,
+ "PANCHROMATIC_SAMPLES" ,
"THERMAL_LINES" ,
"THERMAL_SAMPLES" ,
]
@@ -751,10 +939,16 @@ Source code for xlandsat._io
or "CORNER_UR_PROJECTION_Y_PRODUCT" in line
):
line = line . split ( " = " )[ 0 ] + f " = { scene . northing . max () . values } "
- if "REFLECTIVE_LINES" in line or "THERMAL_LINES" in line :
- line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'northing' ] } "
- if "REFLECTIVE_SAMPLES" in line or "THERMAL_SAMPLES" in line :
- line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'easting' ] } "
+ if "pan" in scene :
+ if "PANCHROMATIC_LINES" in line :
+ line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'northing' ] } "
+ if "PANCHROMATIC_SAMPLES" in line :
+ line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'easting' ] } "
+ else :
+ if "REFLECTIVE_LINES" in line or "THERMAL_LINES" in line :
+ line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'northing' ] } "
+ if "REFLECTIVE_SAMPLES" in line or "THERMAL_SAMPLES" in line :
+ line = line . split ( " = " )[ 0 ] + f " = { scene . dims [ 'easting' ] } "
mtl_file . append ( line )
mtl_file = " \n " . join ( mtl_file )
# Add the MTL file to the archive
@@ -794,7 +988,7 @@ Source code for xlandsat._io
diff --git a/dev/_modules/xlandsat/_pansharpen.html b/dev/_modules/xlandsat/_pansharpen.html
new file mode 100644
index 0000000..fed38e6
--- /dev/null
+++ b/dev/_modules/xlandsat/_pansharpen.html
@@ -0,0 +1,460 @@
+
+
+
+
+
+
+
+
+
+ xlandsat._pansharpen | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Source code for xlandsat._pansharpen
+# Copyright (c) 2022 The xlandsat developers.
+# Distributed under the terms of the MIT License.
+# SPDX-License-Identifier: MIT
+"""
+Pansharpening methods.
+"""
+
+
+[docs] def pansharpen ( scene , panchromatic , weights = ( 1 , 1 , 0.2 )):
+
"""
+
Pansharpen the red, green, and blue bands of a scene.
+
+
The pansharpened scene will have the same coordinate values of the given
+
panchromatic band. Uses a weighted version of the Brovey Transform
+
[Pohl_and_VanGenderen1998]_ to account for the smaller blue footprint in
+
Landsat 8/9 panchromatic band, following
+
https://github.com/mapbox/rio-pansharpen (MIT license).
+
+
Parameters
+
----------
+
scene : :class:`xarray.Dataset`
+
A Landsat scene, as read with :func:`xlandsat.load_scene`. The scene
+
must contain the red, green, and blue bands. Other bands are ignored.
+
panchromatic : :class:`xarray.DataArray`
+
A Landsat panchromatic band, as read with
+
:func:`xlandsat.load_panchromatic`.
+
weights : tuple
+
The weights applied to the red, green, and blue bands, respectively.
+
+
Returns
+
-------
+
scene_sharpened : :class:`xarray.Dataset`
+
The pandsharpened scene including the red, green, and blue bands only.
+
Metadata from the original scene is copied into the pandsharpened
+
version.
+
"""
+
bands = [ "red" , "green" , "blue" ]
+
sharp = scene [ bands ] . interp_like (
+
panchromatic , method = "nearest" , kwargs = { "fill_value" : "extrapolate" }
+
)
+
band_average = sum (
+
sharp [ band ] * weight for band , weight in zip ( bands , weights )
+
) / sum ( weights )
+
sharp *= panchromatic
+
sharp /= band_average
+
sharp . attrs = {
+
key : value for key , value in scene . attrs . items () if key not in ( "mtl_file" )
+
}
+
sharp . attrs [ "title" ] = f "Pansharpend { scene . attrs [ 'title' ] } "
+
sharp . attrs [ "pansharpening_method" ] = "Weighted Brovey Transform"
+
sharp . attrs [ "pansharpening_rgb_weights" ] = weights
+
sharp . attrs [ "pansharpening_band_filename" ] = panchromatic . attrs [ "filename" ]
+
for band in sharp :
+
sharp [ band ] . attrs = scene [ band ] . attrs
+
return sharp
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/_modules/xlandsat/datasets.html b/dev/_modules/xlandsat/datasets.html
new file mode 100644
index 0000000..cdbddfb
--- /dev/null
+++ b/dev/_modules/xlandsat/datasets.html
@@ -0,0 +1,592 @@
+
+
+
+
+
+
+
+
+
+ xlandsat.datasets | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Source code for xlandsat.datasets
+# Copyright (c) 2022 The xlandsat developers.
+# Distributed under the terms of the MIT License.
+# SPDX-License-Identifier: MIT
+"""
+Functions for downloading and caching sample datasets.
+"""
+import pathlib
+
+import pooch
+
+
+[docs] def fetch_brumadinho_after ( untar = False ):
+
"""
+
Download a sample scene from after the Brumadinho tailings dam disaster
+
+
This is a cropped version of a Landsat 8 scene from 2019/01/30. It was
+
taken after the `Brumadinho tailings dam in Brazil
+
<https://en.wikipedia.org/wiki/Brumadinho_dam_disaster>`__ collapsed,
+
flooding a whole region.
+
+
The scene was downloaded from `USGS Earth Explorer
+
<https://earthexplorer.usgs.gov/>`__. Original data are in the public
+
domain and are redistributed here in accordance with the `Landsat Data
+
Distribution Policy
+
<https://www.usgs.gov/media/files/landsat-data-distribution-policy>`__.
+
+
Source: https://doi.org/10.6084/m9.figshare.21665630
+
(`CC0 <https://creativecommons.org/publicdomain/zero/1.0/>`__)
+
+
Parameters
+
----------
+
untar : bool
+
If True, unpack the tar archive after downloading and return a path to
+
the folder containing the unpacked files instead. Default is False.
+
+
Returns
+
-------
+
path : str
+
The path to the downloaded `.tar` file that contains the scene.
+
"""
+
if untar :
+
processor = pooch . Untar ()
+
else :
+
processor = None
+
path = pooch . retrieve (
+
"https://figshare.com/ndownloader/files/38902290" ,
+
fname = "LC08_L2SP_218074_20190130_20200829_02_T1-cropped.tar.gz" ,
+
known_hash = "md5:4ae61a2d7a8b853c727c0c433680cece" ,
+
processor = processor ,
+
)
+
if untar :
+
# Get the folder name in case we unpacked the archive
+
path = pathlib . Path ( path [ 0 ]) . parent
+
return path
+
+
+[docs] def fetch_brumadinho_before ( untar = False ):
+
"""
+
Download a sample scene from before the Brumadinho tailings dam disaster
+
+
This is a cropped version of a Landsat 8 scene from 2019/01/14. It was
+
taken before the `Brumadinho tailings dam in Brazil
+
<https://en.wikipedia.org/wiki/Brumadinho_dam_disaster>`__ collapsed,
+
flooding a whole region.
+
+
The scene was downloaded from `USGS Earth Explorer
+
<https://earthexplorer.usgs.gov/>`__. Original data are in the public
+
domain and are redistributed here in accordance with the `Landsat Data
+
Distribution Policy
+
<https://www.usgs.gov/media/files/landsat-data-distribution-policy>`__.
+
+
Source: https://doi.org/10.6084/m9.figshare.21665630
+
(`CC0 <https://creativecommons.org/publicdomain/zero/1.0/>`__)
+
+
Parameters
+
----------
+
untar : bool
+
If True, unpack the tar archive after downloading and return a path to
+
the folder containing the unpacked files instead. Default is False.
+
+
Returns
+
-------
+
path : str
+
The path to the downloaded `.tar` file that contains the scene.
+
"""
+
if untar :
+
processor = pooch . Untar ()
+
else :
+
processor = None
+
path = pooch . retrieve (
+
"https://figshare.com/ndownloader/files/38902284" ,
+
fname = "LC08_L2SP_218074_20190114_20200829_02_T1-cropped.tar.gz" ,
+
known_hash = "md5:d2a503c944bb7ef3b41294d44b77e98c" ,
+
processor = processor ,
+
)
+
if untar :
+
# Get the folder name in case we unpacked the archive
+
path = pathlib . Path ( path [ 0 ]) . parent
+
return path
+
+
+[docs] def fetch_liverpool ( untar = False ):
+
"""
+
Download a sample scene from the city of Liverpool, UK
+
+
This is a cropped version of a Landsat 8 scene from 2020/09/27. It was
+
taken on a virtually cloud-free day and shows the Mersey river delta and
+
some off-shore wind turbines.
+
+
The scene was downloaded from `USGS Earth Explorer
+
<https://earthexplorer.usgs.gov/>`__. Original data are in the public
+
domain and are redistributed here in accordance with the `Landsat Data
+
Distribution Policy
+
<https://www.usgs.gov/media/files/landsat-data-distribution-policy>`__.
+
+
Source: https://doi.org/10.6084/m9.figshare.22041353
+
(`CC0 <https://creativecommons.org/publicdomain/zero/1.0/>`__)
+
+
Parameters
+
----------
+
untar : bool
+
If True, unpack the tar archive after downloading and return a path to
+
the folder containing the unpacked files instead. Default is False.
+
+
Returns
+
-------
+
path : str
+
The path to the downloaded `.tar` file that contains the scene.
+
"""
+
if untar :
+
processor = pooch . Untar ()
+
else :
+
processor = None
+
path = pooch . retrieve (
+
"https://figshare.com/ndownloader/files/39121064" ,
+
fname = "LC08_L2SP_204023_20200927_20201006_02_T1-cropped.tar.gz" ,
+
known_hash = "md5:3c07e343ccf959be4e5dd5c9aca4e0a4" ,
+
processor = processor ,
+
)
+
if untar :
+
# Get the folder name in case we unpacked the archive
+
path = pathlib . Path ( path [ 0 ]) . parent
+
return path
+
+
+[docs] def fetch_liverpool_panchromatic ( untar = False ):
+
"""
+
Download a sample panchromatic band from the city of Liverpool, UK
+
+
This is a cropped version of the panchromatic band from a Landsat 8 Level 1
+
scene from 2020/09/27. It was taken on a virtually cloud-free day and shows
+
the Mersey river delta and some off-shore wind turbines.
+
+
The scene was downloaded from `USGS Earth Explorer
+
<https://earthexplorer.usgs.gov/>`__. Original data are in the public
+
domain and are redistributed here in accordance with the `Landsat Data
+
Distribution Policy
+
<https://www.usgs.gov/media/files/landsat-data-distribution-policy>`__.
+
+
Source: https://doi.org/10.6084/m9.figshare.22041353
+
(`CC0 <https://creativecommons.org/publicdomain/zero/1.0/>`__)
+
+
Parameters
+
----------
+
untar : bool
+
If True, unpack the tar archive after downloading and return a path to
+
the folder containing the unpacked files instead. Default is False.
+
+
Returns
+
-------
+
path : str
+
The path to the downloaded `.tar` file that contains the scene.
+
"""
+
if untar :
+
processor = pooch . Untar ()
+
else :
+
processor = None
+
path = pooch . retrieve (
+
"https://figshare.com/ndownloader/files/39121061" ,
+
fname = "LC08_L1TP_204023_20200927_20201006_02_T1-cropped.tar.gz" ,
+
known_hash = "md5:7d43f8580b8e583d137a93f9ae51a73d" ,
+
processor = processor ,
+
)
+
if untar :
+
# Get the folder name in case we unpacked the archive
+
path = pathlib . Path ( path [ 0 ]) . parent
+
return path
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_after.rst.txt b/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_after.rst.txt
new file mode 100644
index 0000000..3824360
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_after.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.datasets.fetch\_brumadinho\_after
+==========================================
+
+.. currentmodule:: xlandsat.datasets
+
+.. autofunction:: fetch_brumadinho_after
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_before.rst.txt b/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_before.rst.txt
new file mode 100644
index 0000000..05b4f41
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.datasets.fetch_brumadinho_before.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.datasets.fetch\_brumadinho\_before
+===========================================
+
+.. currentmodule:: xlandsat.datasets
+
+.. autofunction:: fetch_brumadinho_before
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool.rst.txt b/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool.rst.txt
new file mode 100644
index 0000000..d6b0b04
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.datasets.fetch\_liverpool
+==================================
+
+.. currentmodule:: xlandsat.datasets
+
+.. autofunction:: fetch_liverpool
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.rst.txt b/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.rst.txt
new file mode 100644
index 0000000..cadb14f
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.datasets.fetch\_liverpool\_panchromatic
+================================================
+
+.. currentmodule:: xlandsat.datasets
+
+.. autofunction:: fetch_liverpool_panchromatic
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/generated/xlandsat.load_panchromatic.rst.txt b/dev/_sources/api/generated/xlandsat.load_panchromatic.rst.txt
new file mode 100644
index 0000000..c34d6bf
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.load_panchromatic.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.load\_panchromatic
+===========================
+
+.. currentmodule:: xlandsat
+
+.. autofunction:: load_panchromatic
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/generated/xlandsat.pansharpen.rst.txt b/dev/_sources/api/generated/xlandsat.pansharpen.rst.txt
new file mode 100644
index 0000000..b4a47dc
--- /dev/null
+++ b/dev/_sources/api/generated/xlandsat.pansharpen.rst.txt
@@ -0,0 +1,10 @@
+xlandsat.pansharpen
+===================
+
+.. currentmodule:: xlandsat
+
+.. autofunction:: pansharpen
+
+.. raw:: html
+
+
diff --git a/dev/_sources/api/index.rst.txt b/dev/_sources/api/index.rst.txt
index 5a1bde3..59a1537 100644
--- a/dev/_sources/api/index.rst.txt
+++ b/dev/_sources/api/index.rst.txt
@@ -7,9 +7,36 @@ List of functions and classes (API)
.. currentmodule:: xlandsat
+Input and output
+----------------
+
.. autosummary::
:toctree: generated/
load_scene
save_scene
+ load_panchromatic
+
+Processing
+----------
+
+.. autosummary::
+ :toctree: generated/
+
composite
+ pansharpen
+
+Sample datasets
+---------------
+
+.. automodule:: xlandsat.datasets
+
+.. currentmodule:: xlandsat
+
+.. autosummary::
+ :toctree: generated/
+
+ datasets.fetch_brumadinho_after
+ datasets.fetch_brumadinho_before
+ datasets.fetch_liverpool
+ datasets.fetch_liverpool_panchromatic
diff --git a/dev/_sources/changes.rst.txt b/dev/_sources/changes.rst.txt
index e1ec8a3..032cc4a 100644
--- a/dev/_sources/changes.rst.txt
+++ b/dev/_sources/changes.rst.txt
@@ -3,6 +3,26 @@
Changelog
=========
+Version 0.3.0
+-------------
+
+Released on: 2023/02/08
+
+doi: https://doi.org/10.5281/zenodo.7619773
+
+New features:
+
+* Create a datasets module to automate downloading: https://github.com/compgeolab/xlandsat/pull/24
+* Add pansharpening (Weighted Brovey Transform): https://github.com/compgeolab/xlandsat/pull/23
+
+Documentation:
+
+* Add a favicon image to the docs: https://github.com/compgeolab/xlandsat/pull/22
+
+This release contains contributions from:
+
+* Leonardo Uieda
+
Version 0.2.0
-------------
diff --git a/dev/_sources/composites.rst.txt b/dev/_sources/composites.rst.txt
new file mode 100644
index 0000000..44ad4db
--- /dev/null
+++ b/dev/_sources/composites.rst.txt
@@ -0,0 +1,107 @@
+.. _composites:
+
+Composites
+==========
+
+Plotting individual bands is good but we usually want to make some composite
+images to visualize information from multiple bands at once.
+For that, we have to create **composites**.
+We provide the :func:`xlandsat.composite` function to make this process easier.
+
+As an example, let's load two example scenes from the
+`Brumadinho tailings dam disaster `__:
+
+.. jupyter-execute::
+
+ import xlandsat as xls
+ import matplotlib.pyplot as plt
+
+ path_before = xls.datasets.fetch_brumadinho_before()
+ path_after = xls.datasets.fetch_brumadinho_after()
+
+ before = xls.load_scene(path_before)
+ after = xls.load_scene(path_after)
+
+
+Creating composites
+-------------------
+
+Let's make both RGB (true color) and CIR (color infrared) composites for both
+of our scenes:
+
+.. jupyter-execute::
+
+ # Make the composite and add it as a variable to the scene
+ before = before.assign(rgb=xls.composite(before, rescale_to=[0.03, 0.2]))
+ cir_bands = ("nir", "red", "green")
+ before = before.assign(
+ cir=xls.composite(before, bands=cir_bands, rescale_to=[0, 0.4]),
+ )
+ before
+
+The composites have a similar layout as the bands but with an extra
+``"channel"`` dimension corresponding to red, green, blue, and
+alpha/transparency. The values are scaled to the [0, 255] range and the
+composite is an array of unsigned 8-bit integers.
+
+.. admonition:: Transparency
+ :class: note
+
+ If any of the bands used for the composite have NaNs, those pixels will
+ have their transparency set to the maximum value of 255. If there are no
+ NaNs in any band, then the composite will only have 3 channels (red, green,
+ blue).
+
+
+Now do the same for the after scene:
+
+.. jupyter-execute::
+
+ after = after.assign(rgb=xls.composite(after, rescale_to=[0.03, 0.2]))
+ after = after.assign(
+ cir=xls.composite(after, bands=cir_bands, rescale_to=[0, 0.4]),
+ )
+ after
+
+
+Plotting composites
+-------------------
+
+Composites can be plotted using :meth:`xarray.DataArray.plot.imshow` (using
+:meth:`~xarray.DataArray.plot` won't work and will display histograms instead).
+Let's make the before and after figures again for each of the composites we
+generated.
+
+.. jupyter-execute::
+
+ fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
+
+ # Plot the composites
+ before.rgb.plot.imshow(ax=ax1)
+ after.rgb.plot.imshow(ax=ax2)
+
+ # The "long_name" of the composite is the band combination
+ ax1.set_title(f"Before: {before.rgb.attrs['long_name']}")
+ ax2.set_title(f"After: {after.rgb.attrs['long_name']}")
+
+ ax1.set_aspect("equal")
+ ax2.set_aspect("equal")
+
+ plt.show()
+
+And now the CIR composites:
+
+.. jupyter-execute::
+
+ fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
+
+ before.cir.plot.imshow(ax=ax1)
+ after.cir.plot.imshow(ax=ax2)
+
+ ax1.set_title(f"Before: {before.cir.attrs['long_name']}")
+ ax2.set_title(f"After: {after.cir.attrs['long_name']}")
+
+ ax1.set_aspect("equal")
+ ax2.set_aspect("equal")
+
+ plt.show()
diff --git a/dev/_sources/index.rst.txt b/dev/_sources/index.rst.txt
index b00448a..1f11cc6 100644
--- a/dev/_sources/index.rst.txt
+++ b/dev/_sources/index.rst.txt
@@ -30,19 +30,20 @@ Here's a quick example:
.. jupyter-execute::
import xlandsat as xls
- import pooch # for downloading sample data
- # Download a cropped scene from the Brumadinho dam (Brazil)
- path = pooch.retrieve(
- "doi:10.6084/m9.figshare.21665630.v1/cropped-after.tar.gz",
- known_hash="md5:4ae61a2d7a8b853c727c0c433680cece",
- )
+ # Download a cropped Landsat 8 scene from the Brumadinho dam disaster
+ # (Brazil). The function downloads it and returns the path to the .tar file
+ # containing the scene.
+ path = xls.datasets.fetch_brumadinho_after()
+
# Load the scene directly from the archive (no need to unpack it)
scene = xls.load_scene(path)
- # Make an RGB composite and add it to the scene Dataset
- scene = scene.assign(rgb=xls.composite(scene, rescale_to=[0, 0.2]))
+
+ # Make an RGB composite and stretch the contrast
+ rgb = xls.composite(scene, rescale_to=[0.03, 0.2])
+
# Plot the composite
- scene.rgb.plot.imshow()
+ rgb.plot.imshow()
----
@@ -143,6 +144,15 @@ Here's a quick example:
overview.rst
install.rst
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+ :caption: User Guide
+
+ composites.rst
+ indices.rst
+ pansharpen.rst
+
.. toctree::
:maxdepth: 2
:hidden:
@@ -150,6 +160,7 @@ Here's a quick example:
api/index.rst
citing.rst
+ references.rst
changes.rst
compatibility.rst
versions.rst
diff --git a/dev/_sources/indices.rst.txt b/dev/_sources/indices.rst.txt
new file mode 100644
index 0000000..91f0334
--- /dev/null
+++ b/dev/_sources/indices.rst.txt
@@ -0,0 +1,107 @@
+.. _indices:
+
+Indices
+-------
+
+Indices calculated from multispectral satellite imagery are powerful ways to
+quantitatively analyze these data.
+They take advantage of different spectral properties of materials to
+differentiate between them.
+Many of these indices can be calculated with simple arithmetic operations.
+So now that our data are in :class:`xarray.Dataset`'s it's fairly easy to
+calculate them.
+
+NDVI
+----
+
+As an example, let's load two example scenes from the
+`Brumadinho tailings dam disaster `__:
+
+.. jupyter-execute::
+
+ import xlandsat as xls
+ import matplotlib.pyplot as plt
+
+ path_before = xls.datasets.fetch_brumadinho_before()
+ path_after = xls.datasets.fetch_brumadinho_after()
+
+ before = xls.load_scene(path_before)
+ after = xls.load_scene(path_after)
+
+
+We can calculate the
+`NDVI `__
+for these scenes to see if we can isolate the effect of the flood following the
+dam collapse:
+
+
+.. jupyter-execute::
+
+ before = before.assign(
+ ndvi=(before.nir - before.red) / (before.nir + before.red),
+ )
+ after = after.assign(
+ ndvi=(after.nir - after.red) / (after.nir + after.red),
+ )
+
+ # Set some metadata for xarray to find
+ before.ndvi.attrs["long_name"] = "normalized difference vegetation index"
+ before.ndvi.attrs["units"] = "dimensionless"
+ after.ndvi.attrs["long_name"] = "normalized difference vegetation index"
+ after.ndvi.attrs["units"] = "dimensionless"
+
+ after
+
+And now we can make pseudo-color plots of the NDVI:
+
+.. jupyter-execute::
+
+ fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
+
+ # Limit the scale to [-1, +1] so the plots are easier to compare
+ before.ndvi.plot(ax=ax1, vmin=-1, vmax=1, cmap="RdBu_r")
+ after.ndvi.plot(ax=ax2, vmin=-1, vmax=1, cmap="RdBu_r")
+
+ ax1.set_title(f"Before: {before.attrs['title']}")
+ ax2.set_title(f"After: {after.attrs['title']}")
+
+ ax1.set_aspect("equal")
+ ax2.set_aspect("equal")
+
+ plt.show()
+
+Finally, we can calculate the change in NDVI from one scene to the other by
+taking the difference:
+
+.. jupyter-execute::
+
+ ndvi_change = before.ndvi - after.ndvi
+ ndvi_change.name = "ndvi_change"
+ ndvi_change.attrs["long_name"] = (
+ f"NDVI change between {before.attrs['date_acquired']} and "
+ f"{after.attrs['date_acquired']}"
+ )
+ ndvi_change
+
+.. admonition:: Did you notice?
+ :class: hint
+
+ The keen-eyed among you may have noticed that the number of points along
+ the ``"easting"`` dimension has decreased. This is because :mod:`xarray`
+ only makes the calculations for pixels where the two scenes coincide. In
+ this case, there was an East-West shift between scenes but our calculations
+ take that into account.
+
+Now lets plot it:
+
+.. jupyter-execute::
+
+
+ fig, ax = plt.subplots(1, 1, figsize=(10, 6))
+ ndvi_change.plot(ax=ax, vmin=-1, vmax=1, cmap="PuOr")
+ ax.set_aspect("equal")
+ plt.show()
+
+There's some noise in the cloudy areas of both scenes in the northeast but
+otherwise this plots highlights the area affected by flooding from the dam
+collapse in bright red at the center.
diff --git a/dev/_sources/install.rst.txt b/dev/_sources/install.rst.txt
index fe4d6dd..e7ab468 100644
--- a/dev/_sources/install.rst.txt
+++ b/dev/_sources/install.rst.txt
@@ -54,6 +54,7 @@ xlandsat with ``pip`` or ``conda``:
* `numpy `__
* `xarray `__
* `scikit-image `__
+* `pooch `__
See :ref:`dependency-versions` for the our policy of oldest supported versions
of each dependency.
diff --git a/dev/_sources/overview.rst.txt b/dev/_sources/overview.rst.txt
index edcb614..e26f600 100644
--- a/dev/_sources/overview.rst.txt
+++ b/dev/_sources/overview.rst.txt
@@ -23,42 +23,33 @@ As an example, lets download a tar archive of a Landsat 8 scene of the
`Brumadinho tailings dam disaster `__
that happened in 2019 in Brazil.
The archive is available on figshare at
-https://doi.org/10.6084/m9.figshare.21665630.v1 and includes scenes from before
+https://doi.org/10.6084/m9.figshare.21665630 and includes scenes from before
and after the disaster as both the full scene and a cropped version.
-We'll use :mod:`pooch` to download the scenes from before and after the
-disaster to our computer.
-To save space and bandwidth, we'll use the cropped version here.
+We'll use the functions in :mod:`xlandsat.datasets` to download the scenes from
+before and after the disaster to our computer. To save space and bandwidth,
+these are cropped versions of the full Landsat scenes.
.. jupyter-execute::
- import pooch
-
- path_before = pooch.retrieve(
- "doi:10.6084/m9.figshare.21665630.v1/cropped-before.tar.gz",
- known_hash="md5:d2a503c944bb7ef3b41294d44b77e98c",
- )
- path_after = pooch.retrieve(
- "doi:10.6084/m9.figshare.21665630.v1/cropped-after.tar.gz",
- known_hash="md5:4ae61a2d7a8b853c727c0c433680cece",
- )
+ path_before = xls.datasets.fetch_brumadinho_before()
+ path_after = xls.datasets.fetch_brumadinho_after()
print(path_before)
print(path_after)
.. tip::
- Running the code above will only download the data once since Pooch is
- smart enough to check if the file already exists on your computer.
- See :func:`pooch.retrieve` for more information.
+ Running the code above will only download the data once. We use `Pooch
+ `__ to handle the downloads and it's smart
+ enough to check if the file already exists on your computer. See
+ :func:`pooch.retrieve` for more information.
.. seealso::
- If you want to use the full scene instead of the cropped version,
- substitute the file name to ``full-after.tar.gz`` and
- ``full-before.tar.gz``. Don't forget to also update the MD5 hashes
- accordingly, which you can find on `the figshare archive
- `__.
+ If you want to use the full scenes instead of the cropped version,
+ use :func:`pooch.retrieve` to fetch them from the figshare archive
+ https://doi.org/10.6084/m9.figshare.21665630.
Load the scenes
@@ -119,173 +110,15 @@ automatically add labels and annotations to the plot.
plt.show()
-Make composites
----------------
-
-Plotting individual bands is good but we usually want to make some composite
-images to visualize information from multiple bands at once.
-Let's make both RGB (true color) and CIR (color infrared) composites for both
-of our scenes using :func:`xlandsat.composite`:
-
-.. jupyter-execute::
-
- # Make the composite and add it as a variable to the scene
- before = before.assign(rgb=xls.composite(before, rescale_to=[0, 0.2]))
- cir_bands = ("nir", "red", "green")
- before = before.assign(
- cir=xls.composite(before, bands=cir_bands, rescale_to=[0, 0.4]),
- )
- before
-
-The composites have a similar layout as the bands but with an extra
-``"channel"`` dimension corresponding to red, green, blue, and
-alpha/transparency. The values are scaled to the [0, 255] range and the
-composite is an array of unsigned 8-bit integers.
-
-.. admonition:: Transparency
- :class: note
-
- If any of the bands used for the composite have NaNs, those pixels will
- have their transparency set to the maximum value of 255. If there are no
- NaNs in any band, then the composite will only have 3 channels (red, green,
- blue).
-
-
-Now do the same for the after scene:
-
-.. jupyter-execute::
-
- after = after.assign(rgb=xls.composite(after, rescale_to=[0, 0.2]))
- after = after.assign(
- cir=xls.composite(after, bands=cir_bands, rescale_to=[0, 0.4]),
- )
- after
-
-
-Plot the composites
--------------------
-
-Composites can be plotted using :meth:`xarray.DataArray.plot.imshow` (using
-:meth:`~xarray.DataArray.plot` won't work and will display histograms instead).
-Let's make the before and after figures again for each of the composites we
-generated.
-
-.. jupyter-execute::
-
- fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
-
- # Plot the composites
- before.rgb.plot.imshow(ax=ax1)
- after.rgb.plot.imshow(ax=ax2)
-
- # The "long_name" of the composite is the band combination
- ax1.set_title(f"Before: {before.rgb.attrs['long_name']}")
- ax2.set_title(f"After: {after.rgb.attrs['long_name']}")
-
- ax1.set_aspect("equal")
- ax2.set_aspect("equal")
-
- plt.show()
-
-And now the CIR composites:
-
-.. jupyter-execute::
-
- fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
-
- before.cir.plot.imshow(ax=ax1)
- after.cir.plot.imshow(ax=ax2)
-
- ax1.set_title(f"Before: {before.cir.attrs['long_name']}")
- ax2.set_title(f"After: {after.cir.attrs['long_name']}")
-
- ax1.set_aspect("equal")
- ax2.set_aspect("equal")
-
- plt.show()
-
-Calculating indices
--------------------
-
-Producing indices from these scenes is straightforward thanks to
-:mod:`xarray`'s excelled support for coordinate-aware operations.
-As an example, let's calculate the
-`NDVI `__:
-
-.. jupyter-execute::
-
- before = before.assign(
- ndvi=(before.nir - before.red) / (before.nir + before.red),
- )
- after = after.assign(
- ndvi=(after.nir - after.red) / (after.nir + after.red),
- )
-
- # Set some metadata for xarray to find
- before.ndvi.attrs["long_name"] = "normalized difference vegetation index"
- before.ndvi.attrs["units"] = "dimensionless"
- after.ndvi.attrs["long_name"] = "normalized difference vegetation index"
- after.ndvi.attrs["units"] = "dimensionless"
-
- after
-
-And now we can make pseudocolor plots of the NDVI:
-
-.. jupyter-execute::
-
- fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 12))
-
- # Limit the scale to [-1, +1] so the plots are easier to compare
- before.ndvi.plot(ax=ax1, vmin=-1, vmax=1, cmap="RdBu_r")
- after.ndvi.plot(ax=ax2, vmin=-1, vmax=1, cmap="RdBu_r")
-
- ax1.set_title(f"Before: {before.attrs['title']}")
- ax2.set_title(f"After: {after.attrs['title']}")
-
- ax1.set_aspect("equal")
- ax2.set_aspect("equal")
-
- plt.show()
-
-Finally, we can calculate the change in NDVI from one scene to the other by
-taking the difference:
-
-.. jupyter-execute::
-
- ndvi_change = before.ndvi - after.ndvi
- ndvi_change.name = "ndvi_change"
- ndvi_change.attrs["long_name"] = (
- f"NDVI change between {before.attrs['date_acquired']} and "
- f"{after.attrs['date_acquired']}"
- )
- ndvi_change
-
-.. admonition:: Did you notice?
- :class: hint
-
- The keen-eyed among you may have noticed that the number of points along
- the ``"easting"`` dimension has decreased. This is because :mod:`xarray`
- only makes the calculations for pixels where the two scenes coincide. In
- this case, there was an East-West shift between scenes but our calculations
- take that into account.
-
-Now lets plot it:
-
-.. jupyter-execute::
-
-
- fig, ax = plt.subplots(1, 1, figsize=(10, 6))
- ndvi_change.plot(ax=ax, vmin=-1, vmax=1, cmap="RdBu_r")
- ax.set_aspect("equal")
- plt.show()
-
-There's some noise in the cloudy areas of both scenes in the northeast but
-otherwise this plots highlights the area affected by flooding from the dam
-collapse in bright red at the center.
-
What now?
---------
+Learn more about what you can do with xlandsat and xarray:
+
+* :ref:`composites`
+* :ref:`indices`
+* :ref:`pansharpen`
+
By getting the data into an :class:`xarray.Dataset`, xlandsat opens the door
for a huge range of operations. You now have access to everything that
:mod:`xarray` can do: interpolation, reduction, slicing, grouping, saving to
diff --git a/dev/_sources/pansharpen.rst.txt b/dev/_sources/pansharpen.rst.txt
new file mode 100644
index 0000000..986efc4
--- /dev/null
+++ b/dev/_sources/pansharpen.rst.txt
@@ -0,0 +1,78 @@
+.. _pansharpen:
+
+Pansharpening
+=============
+
+Landsat includes a **panchromatic band** which has greater spatial resolution
+(15 m versus the standard 30 m of visible bands).
+It can be used to artificially increase the resolution of the visible bands
+(red, green, and blue) in a process called **pansharpening**.
+
+To illustrate this concept, let's download a scene from just North of the city
+of Liverpool, UK:
+
+.. jupyter-execute::
+
+ import xlandsat as xls
+ import matplotlib.pyplot as plt
+
+ path = xls.datasets.fetch_liverpool()
+ path_pan = xls.datasets.fetch_liverpool_panchromatic()
+
+Load the scene with :func:`xlandsat.load_scene`:
+
+.. jupyter-execute::
+
+ scene = xls.load_scene(path)
+ scene
+
+
+And load the panchromatic band with :func:`xlandsat.load_panchromatic`:
+
+.. jupyter-execute::
+
+ panchromatic = xls.load_panchromatic(path_pan)
+ panchromatic
+
+Now we can plot an RGB composite and the panchromatic band for comparison:
+
+.. jupyter-execute::
+
+ rgb = xls.composite(scene, rescale_to=(0, 0.25))
+
+ plt.figure(figsize=(16, 10))
+ ax = plt.subplot(2, 1, 1)
+ rgb.plot.imshow(ax=ax)
+ ax.set_aspect("equal")
+ ax.set_title("RGB")
+ ax = plt.subplot(2, 1, 2)
+ panchromatic.plot.pcolormesh(
+ ax=ax, cmap="gray", vmin=0.02, vmax=0.1, add_colorbar=False,
+ )
+ ax.set_aspect("equal")
+ ax.set_title("Panchromatic")
+ plt.tight_layout()
+
+The pansharpening is implemented in :func:`xlandsat.pansharpen`:
+
+.. jupyter-execute::
+
+ scene_sharp = xls.pansharpen(scene, panchromatic)
+ scene_sharp
+
+Finally, let's compare the sharpened and original RGB composites:
+
+.. jupyter-execute::
+
+ rgb_sharp = xls.composite(scene_sharp, rescale_to=(0, 0.15))
+
+ plt.figure(figsize=(16, 10))
+ ax = plt.subplot(2, 1, 1)
+ rgb.plot.imshow(ax=ax)
+ ax.set_aspect("equal")
+ ax.set_title("Original")
+ ax = plt.subplot(2, 1, 2)
+ rgb_sharp.plot.imshow(ax=ax)
+ ax.set_aspect("equal")
+ ax.set_title("Pansharpened")
+ plt.tight_layout()
diff --git a/dev/_sources/references.rst.txt b/dev/_sources/references.rst.txt
new file mode 100644
index 0000000..790b5cc
--- /dev/null
+++ b/dev/_sources/references.rst.txt
@@ -0,0 +1,4 @@
+References
+==========
+
+.. [Pohl_and_VanGenderen1998] C. Pohl & J. L. Van Genderen (1998) Review article Multisensor image fusion in remote sensing: Concepts, methods and applications, International Journal of Remote Sensing, 19:5, 823-854, doi:`10.1080/014311698215748 `__
diff --git a/dev/_static/favicon.png b/dev/_static/favicon.png
index cd2f71e..3b9494d 100644
Binary files a/dev/_static/favicon.png and b/dev/_static/favicon.png differ
diff --git a/dev/_static/readme-example.jpg b/dev/_static/readme-example.jpg
index a52122e..fcd52f5 100644
Binary files a/dev/_static/readme-example.jpg and b/dev/_static/readme-example.jpg differ
diff --git a/dev/api/generated/xlandsat.composite.html b/dev/api/generated/xlandsat.composite.html
index 1404d30..aee0159 100644
--- a/dev/api/generated/xlandsat.composite.html
+++ b/dev/api/generated/xlandsat.composite.html
@@ -8,7 +8,7 @@
- xlandsat.composite | xlandsat v0.0.post32
+ xlandsat.composite | xlandsat v0.0.post36
@@ -49,8 +49,8 @@
-
-
+
+
@@ -86,7 +86,7 @@
- xlandsat v0.0.post32
+ xlandsat v0.0.post36
diff --git a/dev/api/generated/xlandsat.datasets.fetch_brumadinho_after.html b/dev/api/generated/xlandsat.datasets.fetch_brumadinho_after.html
new file mode 100644
index 0000000..f6ea7d0
--- /dev/null
+++ b/dev/api/generated/xlandsat.datasets.fetch_brumadinho_after.html
@@ -0,0 +1,510 @@
+
+
+
+
+
+
+
+
+
+
+ xlandsat.datasets.fetch_brumadinho_after | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
xlandsat.datasets.fetch_brumadinho_after
+
+
+
+
+
+
+
+
+xlandsat.datasets.fetch_brumadinho_after
+
+
+xlandsat.datasets. fetch_brumadinho_after ( untar = False ) [source]
+Download a sample scene from after the Brumadinho tailings dam disaster
+This is a cropped version of a Landsat 8 scene from 2019/01/30. It was
+taken after the Brumadinho tailings dam in Brazil collapsed,
+flooding a whole region.
+The scene was downloaded from USGS Earth Explorer . Original data are in the public
+domain and are redistributed here in accordance with the Landsat Data
+Distribution Policy .
+Source: https://doi.org/10.6084/m9.figshare.21665630
+(CC0 )
+
+Parameters
+untar (bool ) – If True, unpack the tar archive after downloading and return a path to
+the folder containing the unpacked files instead. Default is False.
+
+Returns
+path (str ) – The path to the downloaded .tar file that contains the scene.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/api/generated/xlandsat.datasets.fetch_brumadinho_before.html b/dev/api/generated/xlandsat.datasets.fetch_brumadinho_before.html
new file mode 100644
index 0000000..911de1c
--- /dev/null
+++ b/dev/api/generated/xlandsat.datasets.fetch_brumadinho_before.html
@@ -0,0 +1,510 @@
+
+
+
+
+
+
+
+
+
+
+ xlandsat.datasets.fetch_brumadinho_before | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
xlandsat.datasets.fetch_brumadinho_before
+
+
+
+
+
+
+
+
+xlandsat.datasets.fetch_brumadinho_before
+
+
+xlandsat.datasets. fetch_brumadinho_before ( untar = False ) [source]
+Download a sample scene from before the Brumadinho tailings dam disaster
+This is a cropped version of a Landsat 8 scene from 2019/01/14. It was
+taken before the Brumadinho tailings dam in Brazil collapsed,
+flooding a whole region.
+The scene was downloaded from USGS Earth Explorer . Original data are in the public
+domain and are redistributed here in accordance with the Landsat Data
+Distribution Policy .
+Source: https://doi.org/10.6084/m9.figshare.21665630
+(CC0 )
+
+Parameters
+untar (bool ) – If True, unpack the tar archive after downloading and return a path to
+the folder containing the unpacked files instead. Default is False.
+
+Returns
+path (str ) – The path to the downloaded .tar file that contains the scene.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/api/generated/xlandsat.datasets.fetch_liverpool.html b/dev/api/generated/xlandsat.datasets.fetch_liverpool.html
new file mode 100644
index 0000000..5a4aff2
--- /dev/null
+++ b/dev/api/generated/xlandsat.datasets.fetch_liverpool.html
@@ -0,0 +1,510 @@
+
+
+
+
+
+
+
+
+
+
+ xlandsat.datasets.fetch_liverpool | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
xlandsat.datasets.fetch_liverpool
+
+
+
+
+
+
+
+
+xlandsat.datasets.fetch_liverpool
+
+
+xlandsat.datasets. fetch_liverpool ( untar = False ) [source]
+Download a sample scene from the city of Liverpool, UK
+This is a cropped version of a Landsat 8 scene from 2020/09/27. It was
+taken on a virtually cloud-free day and shows the Mersey river delta and
+some off-shore wind turbines.
+The scene was downloaded from USGS Earth Explorer . Original data are in the public
+domain and are redistributed here in accordance with the Landsat Data
+Distribution Policy .
+Source: https://doi.org/10.6084/m9.figshare.22041353
+(CC0 )
+
+Parameters
+untar (bool ) – If True, unpack the tar archive after downloading and return a path to
+the folder containing the unpacked files instead. Default is False.
+
+Returns
+path (str ) – The path to the downloaded .tar file that contains the scene.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.html b/dev/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.html
new file mode 100644
index 0000000..84bf3ab
--- /dev/null
+++ b/dev/api/generated/xlandsat.datasets.fetch_liverpool_panchromatic.html
@@ -0,0 +1,510 @@
+
+
+
+
+
+
+
+
+
+
+ xlandsat.datasets.fetch_liverpool_panchromatic | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
xlandsat.datasets.fetch_liverpool_panchromatic
+
+
+
+
+
+
+
+
+xlandsat.datasets.fetch_liverpool_panchromatic
+
+
+xlandsat.datasets. fetch_liverpool_panchromatic ( untar = False ) [source]
+Download a sample panchromatic band from the city of Liverpool, UK
+This is a cropped version of the panchromatic band from a Landsat 8 Level 1
+scene from 2020/09/27. It was taken on a virtually cloud-free day and shows
+the Mersey river delta and some off-shore wind turbines.
+The scene was downloaded from USGS Earth Explorer . Original data are in the public
+domain and are redistributed here in accordance with the Landsat Data
+Distribution Policy .
+Source: https://doi.org/10.6084/m9.figshare.22041353
+(CC0 )
+
+Parameters
+untar (bool ) – If True, unpack the tar archive after downloading and return a path to
+the folder containing the unpacked files instead. Default is False.
+
+Returns
+path (str ) – The path to the downloaded .tar file that contains the scene.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/api/generated/xlandsat.load_panchromatic.html b/dev/api/generated/xlandsat.load_panchromatic.html
new file mode 100644
index 0000000..de5c9a7
--- /dev/null
+++ b/dev/api/generated/xlandsat.load_panchromatic.html
@@ -0,0 +1,527 @@
+
+
+
+
+
+
+
+
+
+
+ xlandsat.load_panchromatic | xlandsat v0.0.post36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Toggle navigation sidebar
+
+
+
+
+ Toggle in-page Table of Contents
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
xlandsat.load_panchromatic
+
+
+
+
+
+
+
+
+xlandsat.load_panchromatic
+
+
+xlandsat. load_panchromatic ( path , region = None , dtype = 'float32' ) [source]
+Load the panchromatic band from a USGS EarthExplorer Level 1 Landsat scene.
+Can read from a folder with the *.TIF
file and an *_MTL.txt
file or
+directly from a tar archive (compressed or not) without the need to first
+unpack the archive. The band is converted to reflectance units using
+appropriate scaling parameters and UTM coordinates are set in the returned
+xarray.DataArray
.
+
+
Important
+
Do not rename the TIF or MTL files. The folder/archive can have any
+name but TIF and MTL files need their original names.
+
+
+
Note
+
Only supports Landsat 8 and 9 Collection 2 Level 1 scenes containing
+the panchromatic band.
+
+
+Parameters
+
+path (str or pathlib.Path
) – The path to a folder or tar archive containing the TIF file for the
+panchromatic band. Must include the *_MTL.txt
metadata file.
+Other band files may be present but will be ignored.
+region (None or list ) – Crop the band to this bounding box given as a list of West, East,
+South, and North coordinate values (UTM in meters). If None, no
+cropping is performed on the band. Default is None.
+dtype (str or numpy dtype object ) – The type used for the band array. Integer types will result in rounding
+so floating point is recommended. Default is float16.
+
+
+Returns
+panchromatic (xarray.DataArray
) – The loaded band including UTM easting and northing as dimensional
+coordinates and metadata read from the MTL file and other CF compliant
+fields in the attrs
attribute.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/api/generated/xlandsat.load_scene.html b/dev/api/generated/xlandsat.load_scene.html
index 3c4bf42..31455d1 100644
--- a/dev/api/generated/xlandsat.load_scene.html
+++ b/dev/api/generated/xlandsat.load_scene.html
@@ -8,7 +8,7 @@
- xlandsat.load_scene | xlandsat v0.0.post32
+ xlandsat.load_scene | xlandsat v0.0.post36
@@ -86,7 +86,7 @@
- xlandsat v0.0.post32
+ xlandsat v0.0.post36