Skip to content

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

@Peter9192

Description

@Peter9192

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions