rio-toa icon indicating copy to clipboard operation
rio-toa copied to clipboard

KeyError: 'L1_METADATA_FILE'

Open jaimebayes opened this issue 4 years ago • 4 comments

Hi guys,

I am getting this error from a couple of 2014 Landsat8 images. I installed rio-toa using pip and github but nothing works. Any advice?

Thanks in advance, JL


KeyError Traceback (most recent call last) in () 53 creation_options=creation_options, 54 bands=[band], dst_dtype=dtype, ---> 55 processes=processes, pixel_sunangle=True) 56 57 # Just copy the metadata from source to destination in case we need it in the future.

/usr/local/lib/python3.7/dist-packages/rio_toa/reflectance.py in calculate_landsat_reflectance(src_paths, src_mtl, dst_path, rescale_factor, creation_options, bands, dst_dtype, processes, pixel_sunangle, clip) 152 """ 153 mtl = toa_utils._load_mtl(src_mtl) --> 154 metadata = mtl['L1_METADATA_FILE'] 155 156 M = [metadata['RADIOMETRIC_RESCALING']

KeyError: 'L1_METADATA_FILE'

jaimebayes avatar May 08 '21 04:05 jaimebayes

Hi,

I don't know if you still need a help with this issue @jaimebayes but I had the same problem and I've pushed pull request with a solution: https://github.com/mapbox/rio-toa/pull/36

SimonMolinsky avatar Nov 24 '21 18:11 SimonMolinsky

Hi Simon

Thanks for the advice, I run it again without the same error , but it throws a related error this time:

E = metadata['IMAGE_ATTRIBUTES']['SUN_ELEVATION'] --> 164 date_collected = metadata['PRODUCT_METADATA']['DATE_ACQUIRED'] 165 time_collected_utc = metadata['PRODUCT_METADATA']['SCENE_CENTER_TIME'] 166

KeyError: 'PRODUCT_METADATA'

Any advice will be welcome, Thanks, JL

jaimebayes avatar Nov 28 '21 22:11 jaimebayes

Hi @jaimebayes ,

I'll continue our conversation here -> from here.

I've asked for MTL files and a code snippet. You may attach a file into an issue if you drag & drop it into a text area or by clicking on the small area below a text area (there is a text Attach files by...).

You may paste code here. You can insert it within code brackets (three single apostrophes or toolbar above text area with <> characters).

sample code

SimonMolinsky avatar Nov 29 '21 16:11 SimonMolinsky

Hi @jaimebayes ,

I've made a PR with the correct algorithm to retrieve metadata values. Could you please check how it works within your environment? PR is here: https://github.com/mapbox/rio-toa/pull/36 Should be ok, even if metadata structure changes again... (btw, it was a surprise for me that the meta structure has been changed so many times in such a short time).

I'll run some calculations within my env today and update info for the package maintainers if everything will run smoothly.

SimonMolinsky avatar Dec 05 '21 14:12 SimonMolinsky