[AstroPy] Getting errors while fitting polynomial model with tied parameters

rborges at hush.com rborges at hush.com
Thu Mar 19 11:47:00 EDT 2015


Hi Nadia!


Thanks for confirming this is a reproducible bug; I have created a new issue on github, since the open ones do not seem relevant.


Cordially,
Renato.

On Thu, Mar 19, 2015 at 01:51:05PM +0000, Nadezhda Dencheva wrote:
> Hi Renato,
> 
> I can reproduce the problem with the current master.
> Do you mind filing an issue on the astropy github.
> 
> Thanks,
> Nadia
> ________________________________________
> From: astropy-bounces at scipy.org [astropy-bounces at scipy.org] on behalf of rborges at hush.com [rborges at hush.com]
> Sent: Thursday, March 19, 2015 9:21 AM
> To: astropy at scipy.org
> Subject: [AstroPy] Getting errors while fitting polynomial model with tied      parameters
> 
> Hi!
> 
> 
> I am trying to adapt a working code, that fits a model 2nd degree polynomial, to use a model 2nd degree polynomial with "tied" parameters.
> 
> The reason is: the data is supposed to have parabolic symmetry (it is the unwrapped phase map for a Fabry-Perot interferometer), and then I would like to find the best model that fits the data, and necessarily has the second degree coefficients equal to each other.
> 
> I'm using Python 3 in Fedora 21 (therefore Astropy 0.3.2-2.fc20).
> 
> The working code is this excerpt (full code can be found in the project's github repo at https://github.com/rcbrgs/tuna):
> 
> from astropy.modeling import models
> from astropy.modeling.fitting import NonLinearLSQFitter as LevMarLSQFitter
> import numpy
> # ...
> Polynomial2D_model = models.Polynomial2D ( degree = 2 )
> LevMarLSQFitter_fit = LevMarLSQFitter ( )
> polynomial_fit = LevMarLSQFitter_fit ( model = Polynomial2D_model, x = iia_x_dimension, y = iia_y_dimension, z = self.__ffa_unwrapped )
> 
> This works properly, and coefficients always return with a ratio of 0.99 or better. But following documentation at http://astropy.readthedocs.org/en/latest/modeling/fitting.html, I have tried:
> 
> def tied_c2_0 ( o_model ):
>   o_c2_0 = o_model.c0_2
>   return o_c2_0
> 
> Polynomial2D_model = models.Polynomial2D ( degree = 2, tied = { 'c2_0' : tied_c2_0 } )
> LevMarLSQFitter_fit = LevMarLSQFitter ( )
> polynomial_fit = LevMarLSQFitter_fit ( model = Polynomial2D_model, x = iia_x_dimension, y = iia_y_dimension, z = self.__ffa_unwrapped )
> 
> However, this adaptation leads to the following error:
> 
> Traceback (most recent call last):
>   File "./eg_highres_pipeline.py", line 111, in <module>
>     unwrap_phase_map ( )
>   File "./eg_highres_pipeline.py", line 40, in unwrap_phase_map
>     f_scanning_wavelength = 6616.895 )
>   File "/home/nix/cloud_essential2/tuna/github/tools/phase_map/high_resolution.py", line 112, in __init__
>     ffa_unwrapped = self.unwrapped_phase_map )
>   File "/home/nix/cloud_essential2/tuna/github/tools/models/parabola.py", line 80, in fit_parabolic_model_by_Polynomial2D
>     o_parabola.create_model_map_by_Polynomial2D ( )
>   File "/home/nix/cloud_essential2/tuna/github/tools/models/parabola.py", line 36, in create_model_map_by_Polynomial2D
>     tied = { 'c2_0': tied_c2_0 } )
>   File "/usr/lib64/python3.3/site-packages/astropy/modeling/polynomial.py", line 672, in __init__
>     param_dim=param_dim, **params)
>   File "/usr/lib64/python3.3/site-packages/astropy/modeling/polynomial.py", line 131, in __init__
>     self._validate_params(**params)
>   File "/usr/lib64/python3.3/site-packages/astropy/modeling/polynomial.py", line 183, in _validate_params
>     assert(len(params) == numcoeff)
> AssertionError
> 
> 
> I have tried also using the other syntax suggested on the documentation:
> 
> def tied_c2_0 ( o_model ):
>   o_c2_0 = o_model.c0_2
>   return o_c2_0
> 
> Polynomial2D_model = models.Polynomial2D ( degree = 2 )
> Polynomial2D_model.c2_0.tied = tied_c2_0
> LevMarLSQFitter_fit = LevMarLSQFitter ( )
> polynomial_fit = LevMarLSQFitter_fit ( model = Polynomial2D_model, x = iia_x_dimension, y = iia_y_dimension, z = self.__ffa_unwrapped )
> 
> But this yields this other error:
> 
> Traceback (most recent call last):
>   File "./eg_highres_pipeline.py", line 111, in <module>
>     unwrap_phase_map ( )
>   File "./eg_highres_pipeline.py", line 40, in unwrap_phase_map
>     f_scanning_wavelength = 6616.895 )
>   File "/home/nix/cloud_essential2/tuna/github/tools/phase_map/high_resolution.py", line 112, in __init__
>     ffa_unwrapped = self.unwrapped_phase_map )
>   File "/home/nix/cloud_essential2/tuna/github/tools/models/parabola.py", line 80, in fit_parabolic_model_by_Polynomial2D
>     o_parabola.create_model_map_by_Polynomial2D ( )
>   File "/home/nix/cloud_essential2/tuna/github/tools/models/parabola.py", line 46, in create_model_map_by_Polynomial2D
>     z = self.__ffa_unwrapped )
>   File "/usr/lib64/python3.3/site-packages/astropy/modeling/fitting.py", line 465, in __call__
>     full_output=True)
>   File "/usr/lib64/python3.3/site-packages/scipy/optimize/minpack.py", line 369, in leastsq
>     _check_func('leastsq', 'Dfun', Dfun, x0, args, n, (m,n))
>   File "/usr/lib64/python3.3/site-packages/scipy/optimize/minpack.py", line 30, in _check_func
>     raise TypeError(msg)
> TypeError: leastsq: there is a mismatch between the input and output shape of the 'Dfun' argument '_wrap_deriv'.
> 
> 
> I hope this is enough information to spot any known bugs, and I thank you in advance for your time.
> 
> 
> Cordially,
> Renato.
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy




More information about the AstroPy mailing list