[AstroPy] Composite models or input arrays

Eric Emsellem eric.emsellem at eso.org
Wed Aug 26 03:19:48 EDT 2015

> What you want is to use a model set.  This is a still poorly understood feature
> and I'm open to suggestions for how to make this more "obvious" (part of the
> difficulty in that has been supporting a multitude of different use cases
> simultaneously).  You can read about that here:
> http://docs.astropy.org/en/v1.0.4/modeling/models.html
> In short, a*model set*  is what you want if you want to represent a collection
> of independent instances of the same model with different parameters.
wahh... quite powerful. Sorry to have missed that part of the 
documentation. This is really great and solves quite a number of issues 
I had in mind.

At the end, I need to choose between (the examples below would need 
extra lines/variables, but this is I hope explicit enough):

1- for i in range(N) : ModelT += MyModel(par1= , par2= , par3= )

(each Model being the same MyModel but with different instances provided 
as going through the for loop)

(I could also use model_instance = ModelT(....) to set the parameters 
after the fact as you suggested)


2- ModelT = MyModel(par1=[...], par2=[...], par3=[...], n_models=N)

The second option (model set) seems quite natural. It also has the 
advantages to have both the "parameters" as an array including all 
parameters (2d array), and each individual parameter (par1, par2, par3) 
as an individual array (I checked that 'parameters' and e.g., 'par1' are 
views of each others so when I modify one the other one is also 
modified, via a setter/view I guess -> great!).

=> However, I don't know how to slice the model set then (e.g., compute 
ModelT(x) just using e.g., the 1st and 3rd model of that set). By the 
way, with a compound model, I guess I cannot do ModelT[[0,2]] to access 
only model 1 and 3.

=> More generally, and as mentioned in a previous email, I would also 
like to be able to add more instances of MyModel, or remove some of them.

With Option 1, I can just do ModelT = ModelT + MyModel(par1=, par2=, 
par3=) to add one


ModelT = ModelT[0] + ModelT[2] to remove one (as you suggested)

Could you do that easily with a model set? (1- compute the output on a 
slice of the models, a selected subset, and later on add or even remove 
completely one of the models in the model set?).

Anyways, this is quite amazing. I was a bit dubious when I started to 
examine the possibility to use the astropy.modeling. I am more than 
convinced now and this is going well beyond what I had imagined (and I 
haven't seen everything yet by far). Thanks so much for these developments!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150826/67529627/attachment.html>

More information about the AstroPy mailing list