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

KeyError: 'L1_METADATA_FILE' #35

Open
jaimebayes opened this issue May 8, 2021 · 4 comments
Open

KeyError: 'L1_METADATA_FILE' #35

jaimebayes opened this issue May 8, 2021 · 4 comments

Comments

@jaimebayes
Copy link

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'

@SimonMolinsky
Copy link

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: #36

@jaimebayes
Copy link
Author

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

@SimonMolinsky
Copy link

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
Copy link

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: #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.

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

2 participants