desihub / speclite

Lightweight utilities for working with spectroscopic data
14 stars 19 forks source link

FilterSequence get_abmag as array? #30

Closed grburgess closed 4 years ago

grburgess commented 7 years ago

Do you think it would be easy to have an option to have FilterSequence.get_ab_magnitudes have an option to return an array instead of a table?

Currently, I need to do this type of operation:

 def ab_magnitudes(self):
        """
        return the effective stimulus of the model and filter for the given
        magnitude system
        :return: np.ndarray of ab magnitudes
        """

        assert self._model_set, 'no likelihood model has been set'

        return self._filters.get_ab_magnitudes(self._wrapped_model).to_pandas().loc[0]

because I may mask some of the filters if a user wants to do a fit without them. Like so:

 def _get_expectations(self):

        return self._filter_set.ab_magnitudes()[self._mask]

where self._mask is a numpy boolean array. I am not sure how to do this cleanly with a table and Table.as_array() returns a structured np array which does not understand the indexing. However, going to pandas is incredibly slow!

I was thinking to modify the _get_table() method to just build up a np 2D array optionally. Or do you think there is a better way?

dkirkby commented 7 years ago

If you just want to drop some columns from the returned table, you could use, e.g.

sdss = speclite.filters.load_filters('sdss2010-*')
mags = sdss.get_ab_magnitudes(flux, wlen)
print mags[['sdss2010-g', 'sdss2010-r']]

Alternatively, you could use, e.g.

mags.remove_columns(['sdss2010-g', 'sdss2010-z'])
grburgess commented 7 years ago

Ok. This was actually a little slower than using the pandas conversion. Strange. I bet a straight numpy array would be much faster. The problem is that this routine is called by the fitting engine as right now it is rather slow.

I'll see if I can get a working version of my idea going. Ideally, one would call sdss.get_ab_magnitudes(blah,blah, as_array=True)

grburgess commented 7 years ago

@dkirkby also, here is the idea of what we are using: https://github.com/giacomov/3ML/blob/photo_like/examples/Photometry_demo.ipynb

dkirkby commented 6 years ago

Is this still a blocking factor for your project @grburgess?

weaverba137 commented 4 years ago

Closing, having never heard a reply from @grburgess.