modulo operation on flex.double
Hi, I have a flex.double array of phase values between -360 and 360 degrees I would like to cast them all in one go to lie within 0 to 360. Does anybody know if there is a nice way of doing this with flex arrays? The modulo operator doesn't seem to be supported for flex arrays unlike the +, -, * and the / operators. This would otherwise be handy as I could then convert the array in one line of code like phases = phases % 360.0 If not I guess I'll have to numpy the problem :-) Many thanks, Rob
Would not shifting by 360 and dividing by 2 do the job?
Cheers,
Oleg.
________________________________
From: [email protected]
Hi Rob,
I don't really know the answer but instead of
"If not I guess I'll have to numpy the problem :-)"
I'd rather add a functionality to do this to flex or miller.
Pavel
On Thu, Apr 11, 2019, 10:00 AM Robert Oeffner
Hi,
I have a flex.double array of phase values between -360 and 360 degrees I would like to cast them all in one go to lie within 0 to 360. Does anybody know if there is a nice way of doing this with flex arrays? The modulo operator doesn't seem to be supported for flex arrays unlike the +, -, * and the / operators. This would otherwise be handy as I could then convert the array in one line of code like
phases = phases % 360.0
If not I guess I'll have to numpy the problem :-)
Many thanks,
Rob
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
Would not shifting by 360 and dividing by 2 do the job?
Cheers,
Oleg.
________________________________
From: [email protected]
Will flex.fmod_positive help here, e.g.:
"""Modify the calculated phi values so that they match the full rotation
from zero taken from the the observations, rather than being modulo 2*pi."""
x_obs, y_obs, phi_obs = reflections["xyzobs.mm.value"].parts()
x_calc, y_calc, phi_calc = reflections["xyzcal.mm"].parts()
resid = phi_calc - (flex.fmod_positive(phi_obs, TWO_PI))
# ensure this is the smaller of two possibilities
resid = flex.fmod_positive((resid + pi), TWO_PI) - pi
phi_calc = phi_obs + resid
https://github.com/dials/dials/blob/c8692c36577ac3e8b1410e78b6ede7f4e8300392...
Dr Richard Gildea
Data Analysis Scientist
Tel: +441235 77 8078
Diamond Light Source Ltd.
Diamond House
Harwell Science & Innovation Campus
Didcot
Oxfordshire
OX11 0DE
________________________________
From: [email protected]
Thanks Richard, That does the trick for me. Rob On 11/04/2019 18:25, [email protected] wrote:
Will flex.fmod_positive help here, e.g.:
"""Modify the calculated phi values so that they match the full rotation from zero taken from the the observations, rather than being modulo 2*pi."""
x_obs, y_obs, phi_obs = reflections["xyzobs.mm.value"].parts() x_calc, y_calc, phi_calc = reflections["xyzcal.mm"].parts() resid = phi_calc - (flex.fmod_positive(phi_obs, TWO_PI)) # ensure this is the smaller of two possibilities resid = flex.fmod_positive((resid + pi), TWO_PI) - pi phi_calc = phi_obs + resid
https://github.com/dials/dials/blob/c8692c36577ac3e8b1410e78b6ede7f4e8300392...
Dr Richard Gildea Data Analysis Scientist Tel: +441235 77 8078
Diamond Light Source Ltd. Diamond House Harwell Science & Innovation Campus Didcot Oxfordshire OX11 0DE ________________________________ From: [email protected]
on behalf of Robert Oeffner Sent: 11 April 2019 17:46:29 To: [email protected] Subject: [cctbxbb] modulo operation on flex.double Hi,
I have a flex.double array of phase values between -360 and 360 degrees I would like to cast them all in one go to lie within 0 to 360. Does anybody know if there is a nice way of doing this with flex arrays? The modulo operator doesn't seem to be supported for flex arrays unlike the +, -, * and the / operators. This would otherwise be handy as I could then convert the array in one line of code like
phases = phases % 360.0
If not I guess I'll have to numpy the problem :-)
Many thanks,
Rob
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
-- Robert Oeffner, Ph.D. Research Associate, The Read Group Department of Haematology, Cambridge Institute for Medical Research University of Cambridge Cambridge Biomedical Campus The Keith Peters Building Hills Road Cambridge CB2 0XY www.cimr.cam.ac.uk/investigators/read/index.html tel: +44(0)1223 763234
participants (5)
-
Oleg Dolomanov
-
oleg@olexsys.org
-
Pavel Afonine
-
richard.gildea@diamond.ac.uk
-
Robert Oeffner