ConservationInternational / trends.earth

trends.earth - measure land change
http://trends.earth
GNU General Public License v2.0
109 stars 45 forks source link

Error for downloading Land Data for Malawi #502

Open Ishimotojuri opened 3 years ago

Ishimotojuri commented 3 years ago

I would like to download the land cover data (ESA CCI Land Cover) and Land productivity data for Malawi, but the error message popped out: KeyError: 'year_start'

2021-08-21T22:56:34 WARNING Traceback (most recent call last): File "C:\Users/ishim/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LDMP\jobs.py", line 331, in btn_download download_cloud_results(job, f, self.tr) File "C:\Users/ishim/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LDMP\jobs.py", line 455, in download_cloud_results add_layer(out_file, band_number, band_info) File "C:\Users/ishim/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LDMP\layers.py", line 356, in add_layer title = get_band_title(band_info) File "C:\Users/ishim/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LDMP\layers.py", line 496, in get_band_title return tr_style_text(style['title']).format(**band_info['metadata']) KeyError: 'year_start'

How can I fix this? Does anyone have an idea?

image

azvoleff commented 3 years ago

What version of the plugin are you? This I think is a bug in a past version.

chinwuchen commented 2 years ago

I encountered the same KeyError: 'year_start' in a similar situation. The error occurred when I tried to "load data" from a previously downloaded file (also from ESA CCI Land Cover).

The plugin version is 1.0.8, apparently the most recent stable one.

My system is MacOS Big Sur (11.6.1), Python version: 3.8.7 (default, Feb 10 2021, 09:04:08) [Clang 12.0.0 (clang-1200.0.32.29)] 
QGIS version: 3.16.15-Hannover Hannover, e7fdad6431 


Screen Shot 2022-01-03 at 10 07 48 PM
Jay-Qu commented 2 years ago

I have the issue on MacOS Big Sur (11.6.2) when trying to load a previously downloaded "Trends.Earth" dataset into QGIS. Any help is much appreciated :)

Python version: 3.9.4 (v3.9.4:1f2e3088f3, Apr 4 2021, 12:32:44) [Clang 6.0 (clang-600.0.57)] QGIS version: 3.18.3-Zürich Zürich, exported

Here is the Error Message:

An error has occurred while executing Python code:

KeyError: 'year_start' Traceback (most recent call last): File "/Users/USERNAME/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/LDMP/data_io.py", line 507, in browse_file res = self.update_layer_list(f) File "/Users/USERNAME/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/LDMP/data_io.py", line 515, in update_layer_list self.layer_list = get_layer_info_from_file(os.path.normcase(os.path.normpath(f))) File "/Users/USERNAME/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/LDMP/data_io.py", line 1223, in get_layer_info_from_file layers_filtered.append((data_file, get_band_title(band_info), n + 1, band_info)) File "/Users/USERNAME/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/LDMP/layers.py", line 496, in get_band_title return tr_style_text(style['title']).format(**band_info['metadata']) KeyError: 'year_start'

sebjwallace commented 2 years ago

It's a quick hack, but you can give this a try.

Find the file: /Users/Username/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/LDMP/layers.py

Find the function get_band_title then add a try/except around the line where the error occurs, so it looks like this:

def get_band_title(band_info):
    style = styles.get(band_info['name'], None)
    if style:
        try: 
            return tr_style_text(style['title']).format(**band_info['metadata'])
        except:
            return band_info['name']
    else:
        return band_info['name']

As far as I can read, this is just text styling, which doesn't seem to be critical. This amendment will just return the default anyway.

Note: you will need to restart QGIS for it to take affect.

sebjwallace commented 2 years ago

@azvoleff do you know if a fix is already in for this in the develop branch? Else I can create a PR ^.