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

Cartopy wmts KeyError issue : Content metadata for layer "AMSUA_NOAA15_..." already exists #768

Closed
CTOH-LEGOS opened this issue Apr 16, 2021 · 4 comments
Labels

Comments

@CTOH-LEGOS
Copy link

#Since a while, I am using the wmts function of cartopy but since last week this function does not works returning this error:

KeyError: 'Content metadata for layer "AMSUA_NOAA15_Brightness_Temp_Channel_10" already exists'

The run code is coming from the cartopy web doc.

below the code:

`
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

def main():
url = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
layer = 'VIIRS_CityLights_2012'

 fig = plt.figure()
 ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
 ax.add_wmts(url, layer)
 ax.set_extent([-15, 25, 35, 60], crs=ccrs.PlateCarree())

 ax.set_title('Suomi NPP Earth at night April/October 2012')
 plt.show()

if name == 'main':
main()
`

The issue come from _buildMetadata method into WebMapTileService class. The function called gather_layers raise an KeyError if there are duplicated element... But It should be better to add elements if they are not already in the dictionary called "contents"? And just add a warning for duplicate layers.

Below example to fix this issue:
def gather_layers(parent_elem, parent_metadata): for index, elem in enumerate(parent_elem.findall(_LAYER_TAG)): cm = ContentMetadata( elem, parent=parent_metadata, index=index + 1,parse_remote_metadata=parse_remote_metadata) if cm.id: if not cm.id in self.contents: self.contents[cm.id] = cm else: warnings.war('Content metadata for layer "%s" ' 'already exists' % cm.id) gather_layers(elem, cm)

Thank for help.
Fabien Blarel

@nickdodds
Copy link

I tried to implement this in my version, and it then triggered a load more KeyErrors later in the _buildMetadata method. I also had to just change these to warnings.warn (not .war?...). Seems to kick up a fuss but got the end result for me. Thanks for posting this!

@zfasnacht
Copy link

Any plans to permanently fix this in future updates? Seems it's even breaking active online examples of it's use...

https://scitools.org.uk/cartopy/docs/v0.19/gallery/web_services/wmts_time.html

Copy link

github-actions bot commented Oct 6, 2024

This Issue has been inactive for 90 days. In order to manage maintenance burden, it will be automatically closed in 7 days.

@github-actions github-actions bot added the stale label Oct 6, 2024
Copy link

This Issue has been closed due to there being no activity for more than 90 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants