aditya-grover / climate-learn

Source code for ClimateLearn
MIT License
310 stars 50 forks source link

ImportError for the command "from climate_learn.data import DataModule" #117

Open jdberman opened 1 year ago

jdberman commented 1 year ago

Describe the bug

I am following the code on page 25 in the ClimateLearn paper (https://arxiv.org/pdf/2307.01909.pdf) and when I try to do the import for DataModule I get the following error:

In [1]: from climate_learn.data import DataModule

ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 from climate_learn.data import DataModule

ImportError: cannot import name 'DataModule' from 'climate_learn.data' (/home/user/miniconda3/envs/precip/lib/python3.11/site-packages/climate_learn/data/init.py)

Could someone explain why this import is not working? Perhaps it is related to missing information in the file climate_learn/data/init.py.

As a side question, are there any examples of downscaling with a CNN that could be included in another QuickStart notebook example? For example, similar to the one used in the paper. If so, that would be incredibly helpful.

Thank you for your help! Jeremy

Environment

blue-ocean-climate commented 12 months ago

Change the current directory where climate_learn is installed on your system For instance,

cd /home/user/miniconda3/envs/precip/lib/python3.11/site-packages/

then check in which file does the module exist, now run the import

from climate_learn.data import DataModule

jdberman commented 12 months ago

Thanks @blue-ocean-climate!

It worked with the command climate_learn.data.module import DataModule

I saw in previous versions of this repo that the init.py file had the line from .module import * which I believe would've made the paper's command ( climate_learn.data import DataModule ) work.

@blue-ocean-climate - on a side note, I am trying to run downscaling and I keep getting errors when using the DataModule like below:

data_module= DataModule(task= "downscaling", dataset= "ERA5", root_dir= f"{data_dir_storage}/data/weatherbench/era5/5.625", root_highres_dir= f"{data_dir_storage}/data/weatherbench/era5/2.8125", in_vars= ["2m_temperature"], out_vars= ["2m_temperature"], train_start_year= Year(2014), val_start_year= Year(2015), test_start_year= Year(2016), end_year= Year(2018), subsample= Hours(6), batch_size= 128, num_workers= 1)

but it keeps giving the error: TypeError: DataModule.init() got an unexpected keyword argument 'task'

Do you know how to use this Module? And also how to set what resolution increase for the downscaling?

blue-ocean-climate commented 12 months ago

This how you can use the data module, dm = cl.data.IterDataModule( task, inp_root_dir, out_root_dir, in_vars, out_vars, src="era5", history=3, window=6, pred_range=args.pred_range, subsample=6, batch_size=128, num_workers=8, ) as mentioned in the "data loading section" of documentation. I am not very sure about changing the resolution for down-scaling, I will have to dig deeper into that.