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

(Add config object to) separate code from data/settings #6

Open
Peter9192 opened this issue Apr 6, 2022 · 0 comments
Open

(Add config object to) separate code from data/settings #6

Peter9192 opened this issue Apr 6, 2022 · 0 comments

Comments

@Peter9192
Copy link
Contributor

The example notebook (https://github.com/AI4S2S/proto/blob/master/seasonal_mode.ipynb) seems to couple a folder that's meant for input data to a folder that (I guess) represents the base path of the source code of RGCPD:

main_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory

# define input: 
path_test = os.path.join(main_dir, 'data') # path of test data
# format list_of_name_path = [('TVname', 'TVpath'), ('prec_name', 'prec_path')]
list_of_name_path = [(3, os.path.join(path_test, 'tf5_nc5_dendo_80d77.nc')),
                    ('sst', os.path.join(path_test,'sst_daily_1979-2018_5deg_Pacific_175_240E_25_50N.nc'))]

It might be more robust to separate the two, i.e. just pass in the data path directly:

input_folder = '/some/what/ever/directory/anywhere/on/your/system/testdata/'

That way, it doesn't matter where the data is on your disk.

If there's other places in the code where assumptions are made about paths of certain data files, we might want to consider adding a config object that's passed around inside the code. So you can always start with

from rgcpd import CFG

# e.g. use case configuration or settings files
CFG.load_from_file('config_file')

# Or update settings dynamically:
CFG.set_input_folder('/some/path/to/data/folder')

Then, in the source code, you can always just access CFG['input_folder'].

This can also be a good way to set default settings. Now, I see e.g. Root folder for output. If None, default is your '/users/{username}/Download'.

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

1 participant