Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landsat Surface Reflectance bands have tricky metadata 'band' attribute #3108

Closed
rbavery opened this issue Jul 13, 2019 · 3 comments
Closed

Comments

@rbavery
Copy link

rbavery commented Jul 13, 2019

Code Sample, a copy-pastable example if possible

In [31]: band3 = xarray.open_rasterio("LT050320312005040601T1-SC20190418222326/LT05_L1TP_032031_20050
    ...: 406_20160912_01_T1_sr_band3.tif")                                                           

In [32]: band3                                                                                       
Out[32]: 
<xarray.DataArray (band: 1, y: 7041, x: 7821)>
[55067661 values with dtype=int16]
Coordinates:
  * band     (band) int64 1
  * y        (y) float64 4.732e+06 4.732e+06 4.732e+06 ... 4.521e+06 4.521e+06
  * x        (x) float64 6.129e+05 6.129e+05 6.13e+05 ... 8.475e+05 8.475e+05
Attributes:
    transform:     (30.0, 0.0, 612885.0, 0.0, -30.0, 4732515.0)
    crs:           +init=epsg:32613
    res:           (30.0, 30.0)
    is_tiled:      0
    nodatavals:    (-9999.0,)
    scales:        (1.0,)
    offsets:       (0.0,)
    descriptions:  ('band 3 surface reflectance',)

In [33]: band3.band                                                                                  
Out[33]: 
<xarray.DataArray 'band' (band: 1)>
array([1])
Coordinates:
  * band     (band) int64 1

In [35]: band4                                                                                       
Out[35]: 
<xarray.DataArray (band: 1, y: 7041, x: 7821)>
[55067661 values with dtype=int16]
Coordinates:
  * band     (band) int64 1
  * y        (y) float64 4.732e+06 4.732e+06 4.732e+06 ... 4.521e+06 4.521e+06
  * x        (x) float64 6.129e+05 6.129e+05 6.13e+05 ... 8.475e+05 8.475e+05
Attributes:
    transform:     (30.0, 0.0, 612885.0, 0.0, -30.0, 4732515.0)
    crs:           +init=epsg:32613
    res:           (30.0, 30.0)
    is_tiled:      0
    nodatavals:    (-9999.0,)
    scales:        (1.0,)
    offsets:       (0.0,)
    descriptions:  ('band 4 surface reflectance',)

Problem description

Because each band file has the same band index of "1", concatenating on an index called "band" won't result in a dataset where you can subset bands with different indices.

I'm working on this at the scipy sprint, writing a new Landsat SR specific file opener and contacting the data provider to let them know that the metadata's band attribute should reflect the band number

@rabernat
Copy link
Contributor

Hi @rbavery -- I am inclined to consider this a problem with your data, not a problem with xarray.

However, it would be nice to have some tutorial examples of how to deal with such situations. That is what I'm working on in #1391.

@rabernat
Copy link
Contributor

Suggested workaround would be to write a preprocessor function to fix the bad coordinate before concatenating bands.

I'm working on this at the scipy sprint, writing a new Landsat SR specific file opener and contacting the data provider to let them know that the metadata's band attribute should reflect the band number

Are you aware of satyp? https://satpy.readthedocs.io/en/latest/ It sounds like what you are doing is within the scope of that project. (They use xarray under the hood.)

@rbavery
Copy link
Author

rbavery commented Jul 13, 2019

Sounds good, I'll look into contributing a Landsat reader to Satpy, that's a better home for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants