astropy/specutils — pull request #6 by wkerzendorf (2012-03-08 05:59:46+00:00)
Title: Spectrum1d 2nd draft

So I think I have most things that we talked about implemented. I have tried to put comments in the code to explain some of the things I did. There's also some questions in there (mainly about logging).

The main issue I encountered when writing this up was the problem of handling errors and masks.
Both errors and masks have different arithmetic (and interpolation) behaviour depending on what they are.
Fortunatley, this behaviour is the same for all children of nddata, be it a 1d Spectrum, an image or an n-dimensional simulation. Thus I believe that errors and masks should be implemented with nddata.

As an example I have implemented a BoolMask and SDError.

The arithmetic operations are implemented for the mask with mask_add, mask_sub, ... which does always the same thing - a logical_or (if only one of the values is masked the result will also be masked there). For interpolation the result will automatically be masked outside the data range and will flag pixels that used flagged pixels to be interpolated. Another mask could be a bitflag mask that would need to be added instead of a logical_or.

I have chosen a simple standard deviation error as an example for an error. The arithmetic operations are implemented for the error with error_add, error_sub, ... . For the SDError the interpolate function Another error would be VarianceError.

I should reiterate that both of these apply to all nddata objects and we should utilise this to avoid code duplication.

Finally here's a couple of initialization examples and one can play with the results.

```python
easy_spec = Spectrum1D(rand(1000), linspace(3000, 6000, 1000))

my_first_spec = Spectrum1D(np.random.rand(1000),
linspace(4000, 7000, 1000),
error=SDError(np.random.rand(1000)),
mask = BoolMask(np.random.rand(1000) > .5),
meta = dict(a=5, b=7, c=9))

my_second_spec = Spectrum1D(np.random.rand(1000),
linspace(4000, 7000, 1000),
error=SDError(np.random.rand(1000)),
mask = BoolMask(np.random.rand(1000) > .5),
meta = dict(c=9, d=11, e=13))
```

I believe this might spark a lot of discussion and maybe we want to have a quick video chat again.