pro shapelets_rotate, structure, angle, $
CENTRE=centre, $
POLAR=polar, $
CARTESIAN=cartesian, $
ORDER=order, $
EXTEND=extend, $
THETA_ZERO=theta_zero, $
NOHISTORY=nohistory, $
MAINTAIN=maintain
;$Id: shapelets_rotate.pro, v2$
;
; Copyright © 2005 Richard Massey and Alexandre Refregier.
;
; This file is a part of the Shapelets analysis code.
; www.astro.caltech.edu/~rjm/shapelets/
;
; The Shapelets code is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public Licence as published
; by the Free Software Foundation; either version 2 of the Licence, or
; (at your option) any later version.
;
; The Shapelets code is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public Licence for more details.
;
; You should have received a copy of the GNU General Public Licence
; along with the Shapelets code; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
;
;+
; NAME:
; SHAPELETS_ROTATE
;
; CATEGORY:
; Shapelets.
;
; PURPOSE:
; Rotates an object by converting it's Cartesian shapelet coefficients to
; polar shapelet coefficients, then applying the rotation matrix - which,
; in this basis, is a simple multiplication.
;
; INPUTS:
; STRUCTURE - Shapelet decomp or shapecat structure.
; ANGLE - Anticlockwise, in degrees.
;
; OPTIONAL INPUTS:
; CENTRE - Centre of rotation.
; DEFAULT: shapelet centre
; Apply Translation operator before & after?
; MATRIX - Cartesian to polar shapelet conversion matrix, if it has
; already been calculated. Useful only for increased speed.
;
; KEYWORD PARAMETERS:
; THETA_ZERO- Rotate the direction used as the origin of angles, but
; leave the object itself unchanged.
; DEFAULT: Actually rotate the object.
; POLAR - Perform translation in polar shapelet space.
; DEFAULT: Cartesian.
; MAINTAIN - Restore the (polar/Cartesian) input format on output.
; NOHISTORY - Do not record this operation in the object's history tag.
;
; OPTIONAL OUTPUTS:
; MATRIX - Cartesian to polar shapelet conversion matrix, so that it
; doesn't have to be calculated again in the future, for speed.
;
; OUTPUTS:
; STRUCTURE - Rotated shapelet model(s).
;
; MODIFICATION HISTORY:
; Jul 07 - Fixed to work with older versions of IDL by RM.
; Apr 07 - THETA_ZERO option added by RM.
; Apr 07 - Ability to coppe with elliptical shapelets added by RM.
; Jun 05 - Routine condensed by RM.
; Apr 05 - Generalised to accept shapecats as input by RM.
; Feb 02 - Written by Richard Massey.
;-
COMPILE_OPT idl2
; Backwardly compatible
if not shapelets_structure_type(structure,message=message) then message,message
; Remember input format for later use
polar_input=structure.polar
; Parse input
if keyword_set(extend) then shapelets_extend_nmax,structure,round(extend)
if keyword_set(centre) then message,"Code for CENTRE keyword not yet written!"
case message of
"decomp": begin
shapelets_make_nvec, structure.n_max, n, m, /POLAR
angle_string=strtrim(angle,2)+" degrees"
end
"shapecat": begin
shapelets_make_nvec, structure.maxn_max, n, m, /POLAR
m=m##replicate(1,structure.n)
message,"Need to calculate transformation of objects' global coordinates!",/info
if n_elements(angle) eq 1 then angle_string=strtrim(angle,2)+" degrees" else angle_string="various angles"
end
else: message,"Cannot rotate objects in "+message+" structures!"
endcase
if keyword_set(order) then if order ne 1 then message,"Rotations are trivial. This operation will automatically be done analytically.",/info
if keyword_set(theta_zero) then begin
; Add operation to object's history record
if not keyword_set(nohistory) then shapelets_update_history,structure,"Theta_zero changed by "+angle_string
; Change theta_zero. Object will then be unrotated via its coefficients.
structure.theta_zero=structure.theta_zero+angle
structure.theta_zero=((structure.theta_zero+180) mod 360)-180
endif else begin
; Add operation to object's history record
if not keyword_set(nohistory) then shapelets_update_history,structure,"Rotated by "+angle_string
; Rotate ellipticity of elliptical shapelet basis functions
if tag_exist(structure,"basis_ellipticity") then begin
abs_basis_ellipticity=abs(structure.basis_ellipticity)
if max(abs_basis_ellipticity) gt 0. then begin
basis_ellipticity_angle=atan(imaginary(structure.basis_ellipticity),float(structure.basis_ellipticity))/2.+angle/!radeg
structure.basis_ellipticity=abs_basis_ellipticity*complex(cos(2*basis_ellipticity_angle),sin(2*basis_ellipticity_angle))
endif
endif
; Take easy option if it's appropriate
if tag_exist(structure,"theta_zero") then if max(abs(structure.theta_zero) ne 0.) then begin
structure.theta_zero=structure.theta_zero+angle
return
endif
endelse
; Convert to polar coefficients
shapelets_polar_convert,structure,/POLAR,/SILENT
; Convert polar coefficients to {mag,phase}
phase = atan(imaginary(structure.coeffs),double(structure.coeffs))
modulus = abs(structure.coeffs)
ephase = atan(imaginary(structure.coeffs_error),double(structure.coeffs_error))
emodulus = abs(structure.coeffs_error)
; Perform the actual rotation, which simply involves a change in the phase
; of shapelet coefficients, modulated by their spin
angles = m*angle*(1-2*keyword_set(theta_zero))/!radeg
phase = phase+angles
ephase = ephase+angles
; Convert polar coefficients back to {real,imaginary}
structure.coeffs = modulus*complex(cos(phase),sin(phase))
structure.coeffs_error = emodulus*complex(cos(ephase),sin(ephase))
; Convert back to Cartesian shapelets if necessary
if keyword_set(maintain) then $
shapelets_polar_convert,structure,polar=polar_input,cartesian=1-polar_input,/SILENT
end
Return to the shapelets web page or the code help menu.
| Last modified on 2nd Mar 2009 by Richard Massey. |