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

Transforming data and broadcasting #237

Closed
vascotenner opened this issue Aug 21, 2015 · 4 comments
Closed

Transforming data and broadcasting #237

vascotenner opened this issue Aug 21, 2015 · 4 comments
Assignees
Milestone

Comments

@vascotenner
Copy link
Contributor

Quite often, I want to substract a mean background from an Image or a Curve. This mean background is often calculated by reducing an image twice. Is it possible to substract a single number from an Image?

In numpy this would work like:
image = img_raw - bg.mean()

Or more complicated:

image.shape  = (10,20,300,300)
dark.shape  = (1,20,300,300)
image -= dark.mean(axis=-1)[...,np.newaxis]

I tried to accomplish this first in 1D (a Curve minus a number), but this is also not very easy.

Is this covered in the upcomming first part of the transformation tutorial?

@philippjfr
Copy link
Member

I'd recommend just doing the following:

img = hv.Image(np.random.rand(10,10))
img.clone(img.data - img.data.mean())

or on a HoloMap:

imgmap = hv.HoloMap({i: hv.Image(np.random.rand(10,10)) for i in range(3)})
imgmap.map(lambda x: x.clone(x.data - x.data.mean()), [hv.Image])

for Curves this is more difficult because of the way the data is stored (we're hoping to improve that in future), I can imagine something like this being supported:

curve = hv.Curve(np.random.rand(10))
curve.clone({'y': curve.data['y'] - curve.data['y'].mean()})

@jlstevens
Copy link
Contributor

Perhaps there is a new way to do it using the Data API? Otherwise, if we feel this is resolved or don't have any new suggestions, we should close this issue.

@philippjfr
Copy link
Member

Hmm, I've considered whether Columns should support a setitem so you could do something like:

curve = hv.Curve(np.random.rand(10))
curve['y'] = curve['y'] - curve['y'].mean()
# Or even
curve['y'] -= curve['y'].mean()

We also still need to add the columns method which returns the Columns dictionary, that would at least allowRight now you can do:

curve = hv.Curve(np.random.rand(10))
columns = curve.columns()
columns['y'] = columns['y'] - columns['y'].mean()
curve.clone(columns)

@philippjfr
Copy link
Member

Dataset.transform was merged in #4080 which allows specifying transforms. In future we may also add Dataset.assign.

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

3 participants