spacetelescope / cubeviz

Data analysis package for cubes. https://cubeviz.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
15 stars 27 forks source link

Arithmetic Tasks #80

Closed brechmos-stsci closed 6 years ago

brechmos-stsci commented 6 years ago

SK +, -, *, / operations on 3D data using 1D, 2D, 3D inputs

HF We'll need to define this better. Probably makes sense to layer a 3D-spectrum class on top of NDData, defining sensible defaults for handling masks, uncertainties, WCS, and metadata propagation for the JWST IFU use cases.

We punted on a gui interface for arithmetic during the 1-d spectral viewing sprint.

Robitaille specutils data object

PL pysynphot can already do arithmetic on 1D spectra

SK mean, median, mode (over a given wavelength range or entire wavelength range) (over a given spatial region or entire spatial region)

Imported from Trello https://trello.com/c/Klv10jH4

brechmos-stsci commented 6 years ago

We will also have a notebook to demonstrate some of this ( @kassin and jesse )

nmearl commented 6 years ago

SpectralCube package supports basic arithmetic.

brechmos-stsci commented 6 years ago

Was there an idea of an interface for this? I can think of a couple of ways of doing the gui:

  1. an input box where one could type things like "3 * FLUX" or " FLUX + FLUX_manga". This would take some parsing of the text. But it would make it reasonably extensible.

  2. Alternatively "we" could make it more rigid and have things like:

add/multiply by a constant: +/* +/-/*/div and operator would be dropdowns.

I am not sure what people are used to or if you guys have thought this through previously?

@kassin @hcferguson @nmearl @astrofrog

hcferguson commented 6 years ago

I would be inclined to keep this pretty simple and then have a tutorial for how to pop up the ipython window and use python to do anything more complex. But I could be over-ruled :)

I do think that inventing a grammar for this kind of thing is a slippery slope...

kassin commented 6 years ago

I agree- let's keep things simple. A pop-uo box to so simple add, multiple, divide, exponent, and subtract would be great.

brechmos-stsci commented 6 years ago

So.... not to over-rule @hcferguson but there is a package I found that might actually might make the text input idea actually reasonably simple. The package is https://newville.github.io/asteval/basics.html.

In [1]: from asteval import Interpreter

In [2]: aeval = Interpreter()

In [3]: import numpy as np

In [4]: aeval('x=sqrt(3)')

In [7]: aeval('print(x)')
1.73205080757

In [8]: aeval.symtable['x']
Out[8]: 1.7320508075688772

In [9]: aeval.symtable['y'] = 12

In [10]: aeval('print(y)')
12

In [11]: a = 3*np.ones((3,3))

In [12]: aeval.symtable['a'] = a

In [13]: aeval('print(a)')
[[ 3.  3.  3.]
 [ 3.  3.  3.]
 [ 3.  3.  3.]]

In [14]: b = 5*np.ones((3,3))

In [15]: aeval.symtable['b'] = b

In [16]: aeval('c = a + b')

In [17]: c = aeval.symtable['c']

In [18]: c
Out[18]:
array([[ 8.,  8.,  8.],
       [ 8.,  8.,  8.],
       [ 8.,  8.,  8.]])

So, it basically means we could have a text box and could do just about any type of calculations that numpy allows. It would just be a matter of passing the necessary data into the package and then taking it out.

I think at this point, this would be even easier than doing a whole bunch of drop-downs etc. So, unless there is a compelling reason to not do it this way, I think I will aim for this.

kassin commented 6 years ago

Oh this is neat. I'm in favor of using this. I need to remember to provide examples in the documentation.

nmearl commented 6 years ago

@brechmos-stsci SpecViz uses py-expression-eval for its spectrum arithmetic, which is a simple textual input popup box that matches variables to spectrum object names.

screen shot 2017-12-01 at 9 58 05 am