MESMER-group / mesmer

spatially-resolved ESM-specific multi-scenario initial-condition ensemble emulator
https://mesmer-emulator.readthedocs.io/en/latest/
GNU General Public License v3.0
22 stars 17 forks source link

KeyError: 'long_name' #378

Open dongjinchi opened 7 months ago

dongjinchi commented 7 months ago

Hi,

I’m new user to MESMER. This is really a great model. But when I run the code in the 5_MAGICC-MESMER_probabilistic_overview_fig1_fig2.ipynb file:

db = scmdata.database.ScmDatabase(cfg.dir_magicc_probab_emus)
magicc_co2_conc = scmdata.run_append(
    [
        db.load(scenario=s, variable="Atmospheric Concentrations CO2")
        for s in magicc_scenarios_to_run
    ]
)

I got the error:

Failed reading netcdf file: E:/10Julia/05MESMER/path/rcmip-phase-2-archive\rcmip-phase-2\data\processed\submission-database-hadcrut5-target\MAGICCv7.5.1\Surface-Air-Temperature-Change\World\ssp119\MAGICCv7.5.1_Surface-Air-Temperature-Change_World_ssp119.nc
Traceback (most recent call last):
  File "C:\Users\dongj\anaconda3\lib\site-packages\scmdata\netcdf.py", line 222, in nc_to_run
    return _read_nc(cls, fname)
  File "C:\Users\dongj\anaconda3\lib\site-packages\scmdata\netcdf.py", line 81, in _read_nc
    dataframe = _reshape_to_scmrun_dataframe(dataframe, loaded)
  File "C:\Users\dongj\anaconda3\lib\site-packages\scmdata\netcdf.py", line 93, in _reshape_to_scmrun_dataframe
    variable_name_map = {k: v.attrs["long_name"] for k, v in loaded.data_vars.items()}
  File "C:\Users\dongj\anaconda3\lib\site-packages\scmdata\netcdf.py", line 93, in <dictcomp>
    variable_name_map = {k: v.attrs["long_name"] for k, v in loaded.data_vars.items()}
KeyError: 'long_name'

The data I used sourced from:https://doi.org/10.5281/zenodo.4269711.

Do you have any idea on how to solve it.

Many thanks!

mathause commented 7 months ago

Thanks for your interest. Can you post the output of the packages you have installed using conda list

cc @leabeusch and @znicholls.

dongjinchi commented 7 months ago

Here is my packages: packages.txt I also tried using version v0.9.1 of the scmdata, but I got another error when I imported it: ImportError: cannot import name 'inject_binary_ops' from 'xarray.core.ops' (C:\Users\dongj\anaconda3\lib\site-packages\xarray\core\ops.py)

Thanks for your help!

znicholls commented 7 months ago

Hmm welcome to dependency hell :) (Our bad, pinning things wasn't our strong suit back then)

You probably need to roll scmdata back to whatever version was used to write the netCDF file (do ncdump on the file and it says somewhere in the metadata). Then you'll need to roll xarray back to whatever version of it was available around a similar time so that the APIs line up. Good luck :)

dongjinchi commented 7 months ago

Hi,

I find the code works when using scmdata==0.9.1,xarray==0.17.0,pint==0.16.1.

However, the data I download from https://doi.org/10.5281/zenodo.4269711 cannot be directly used with this code. I need to manually change the underscore "_" to a hyphen "-" and add a "-" at end of the data names. For example, MAGICCv7.5.1_Surface-Air-Temperature-Change_World_ssp370.nc should be changed to MAGICCv7.5.1-Surface-Air-Temperature-Change-World-ssp370-.nc. Another solution could be to modify the _get_disk_filename function in the database.py of scmdata package. But this may bacause I downloaded the wrong data.

I would suggest uploading the relevant data in Beusch_et_al_GMD_2021_MAGICC-MESMER_coupling folder. This would help beginners, like me, in more easily understanding and learning how to use the code.

Anyway, many thanks for your kind help. It is really a great model!

dongjinchi commented 7 months ago

By the way, is there a reduced earth system model for precipitation prejection.

Many thanks.