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

Adding new components from a Python session #8

Open
robintw opened this issue May 20, 2016 · 1 comment
Open

Adding new components from a Python session #8

robintw opened this issue May 20, 2016 · 1 comment

Comments

@robintw
Copy link
Collaborator

robintw commented May 20, 2016

I've had a bit of a play around with the example IPython notebook you provided, and found that the API is fairly easy to navigate - thanks!

I didn't want to submit this as a PR as it a) it isn't really designed for this repo (it's more general Glue), and b) It's definitely not robust enough or general enough to be used generically...but I wanted to show what I've done.

I've written a simple qadd function, that works like qglue, but adds an array as an extra component to an already-existing DataCollection. This is the kind of thing that would be very useful to me, so that I can add in various different 'partially-processed' bits of satellite imagery and compare them.

def qadd(arr, label, collection_id=None):
    if len(app.data_collection) > 1 and collection_id is None:
        raise ValueError('More than one collection exists, you must specify a collection_id')

    collection_id = collection_id or 0

    dc = app.data_collection[collection_id]
    dc.add_component(arr, label=label)
@astrofrog
Copy link
Member

astrofrog commented May 21, 2016

Just for information, I also merged a PR after our chat that adds a new add_data method on the application instance: glue-viz/glue#993 - this can be used similarly to qglue, e.g.:

app.add_data(myarray=array)

and I think it will suggest to merge with an existing dataset. However, it would be nice to have a way to add components to existing datasets, so maybe we can think of how to modify add_data to allow for that.

Alternatively, we could make it easier for you to get the data object that corresponds to data you created with qglue so you can then add components to it. For instance, if we could do:

app = qglue(myarray=array)
data = app.data_collection['myarray']
data['mylabel'] = newarray  # add new component

So this would require allowing data to be accessed by key in data_collection, which is not currently possible because we don't (yet) enforce unique data labels (this is a to-do: glue-viz/glue#773).

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

2 participants