[AstroPy] Remove a model from a composite model in astropy.modeling

Erik Bray embray at stsci.edu
Fri Aug 21 10:57:54 EDT 2015


On 08/21/2015 10:48 AM, Erik Bray wrote:
> This is even easier if you give names to the individual models so that you don't
> have to worry about their numeric index.  Although in this case it's a little
> awkward because when you use names in slices the end points are *inclusive* so
> you have to know which models come before and after 'B'
>
>   >>> model = model1.rename('A') + model2.rename('B') + model3.rename('C')
>   >>> model = model[:'A'] + model['C':]

Another thought I just had is that it would be good to have a method to map a 
model's label (if it has one) to its index within the ordering of the 
submodules.  For example in the above case:

 >>> model.index('B')
1

Then you could do:

 >>> model = model[:model.index('B')] + model[model.index('B') + 1:]

Erik



More information about the AstroPy mailing list