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

Allow alternative formats for input and snapshots variables #28

Closed
benbovy opened this issue Feb 26, 2018 · 1 comment
Closed

Allow alternative formats for input and snapshots variables #28

benbovy opened this issue Feb 26, 2018 · 1 comment
Milestone

Comments

@benbovy
Copy link
Member

benbovy commented Feb 26, 2018

Currently the only accepted format for input and snapshots variables is nested dictionaries of processes and variables, e.g.,

in_ds = xsimlab.create_setup(
    ...
    input_vars={
        'grid': {
            'x_size': 201,
            'y_size': 101,
            'x_length': 1e5,
            'y_length': 1e5
        },
        'topography': {
            'elevation': (('y', 'x'), np.random.rand(101, 101))
        }
    },
    snapshot_vars={
        'out': {
            'topography': 'elevation'
        },
        None: {
            'grid': ('x', 'y')
        }
    }
)

Although a bit more verbose, flat dictionaries may be better in some cases (It is also consistent with the flat mapping of data variables in new returned xarray.Dataset objects):

in_ds = xsimlab.create_setup(
    ...
    input_vars={
        'grid__x_size': 201,
        'grid__y_size': 101,
        'grid__x_length': 2e5,
        'grid__y_length': 1e5,
        'topography__elevation': (('y', 'x'), np.random.rand(101, 201))
    },
    snapshot_vars={
        'out': ('topography__elevation'),
        None: ('grid__x', 'grid__y')
    }
)

We might also accept tuples, which are easier to use programmatically (this may be useful if someday "virtual groups" get implemented in xarray, see this issue comment):

in_ds = xsimlab.create_setup(
    ...
    input_vars={
        ('grid', 'x_size'): 201,
        ('grid', 'y_size'): 101,
        ('grid', 'x_length'): 2e5,
        ('grid', 'y_length'): 1e5,
        ('topography', 'elevation'):  (('y', 'x'), np.random.rand(101, 201))
    },
    snapshot_vars={
        'out': (('topography', 'elevation'),),
        None: (('grid', 'x'), ('grid', 'y'))
    }
)

If we support the three different formats, we also need to decide if we allow mixing these formats. It should be easy to implement (i.e., test if key is tuple, or <process> or <process__variable>).

@benbovy
Copy link
Member Author

benbovy commented May 7, 2018

Closed in #33

@benbovy benbovy closed this as completed May 7, 2018
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