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

group_dict variable #140

Closed
benbovy opened this issue Oct 13, 2020 · 3 comments · Fixed by #159
Closed

group_dict variable #140

benbovy opened this issue Oct 13, 2020 · 3 comments · Fixed by #159
Milestone

Comments

@benbovy
Copy link
Member

benbovy commented Oct 13, 2020

xsimlab.group_dict() variable would be like to xsimlab.group(), but instead of iterating over the values only, it would provide dict-like access where keys are 2-length tuples ('process_name', 'variable_name').

@benbovy
Copy link
Member Author

benbovy commented Oct 13, 2020

One problem is that 'process_name' is not known before creating a xsimlab.Model object...

@ethho
Copy link

ethho commented Oct 15, 2020

+1 to this feature, even if process_name is not included in the dict. For my particular use case (N-D DataArray construction), I think it would be really useful to expose variable metadata in the group (and generally across the package, but that's a different point):

@xs.process
class CoordsX:
    x = xs.index(groups=['coords'], dims='x')
    
    def initialize(self):
        self.x = range(3)

@xs.process
class CoordsY:
    y = xs.index(groups=['coords'], dims='y')
    
    def initialize(self):
        self.y = range(5)
        
@xs.process
class InitArray:
    DIMS = ('x', 'y')
    
    arr = xs.variable(dims=DIMS, intent='out')
    coords = xs.group('coords')
    
    def initialize(self):
        self.arr = xr.DataArray(
            data=0.,
            dims=self.DIMS,
            # Attribute.name in this instance
            coords={k: self.coords[k] for k in self.DIMS}
        )

My suboptimal workaround has been to use xs.utils.variables_dict(CoordsY)['y'] to retrieve metadata. Apologies in advance if there exists an elegant alternative to this, and thanks for giving us this package!

@benbovy
Copy link
Member Author

benbovy commented Oct 16, 2020

@eho-tacc your code example made me think about a possible way in #141 to better access variable metadata across the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants