@@ -666,29 +666,33 @@ def au2rads(in_file, newpath=None):
666
666
data = im .get_fdata (dtype = 'float32' )
667
667
hdr = im .header .copy ()
668
668
669
- dmin , dmax = data .min (), data .max ()
669
+ if np .allclose ((data .min (), data .max ()), (- np .pi , np .pi ), atol = 0.01 ):
670
+ # Already in rads, but wrap to 0 - 2pi
671
+ data [data < 0 ] += 2 * np .pi
672
+ else :
673
+ dmin , dmax = data .min (), data .max ()
670
674
671
- # Find the mode ignoring outliers on the far max/min, to allow for junk outside the FoV
672
- fudge = 0.05 * (dmax - dmin )
673
- mode = stats .mode (data [(data > dmin + fudge ) & (data < dmax - fudge )])[0 ][0 ]
675
+ # Find the mode ignoring outliers on the far max/min, to allow for junk outside the FoV
676
+ fudge = 0.05 * (dmax - dmin )
677
+ mode = stats .mode (data [(data > dmin + fudge ) & (data < dmax - fudge )])[0 ][0 ]
674
678
675
- # Center data around 0.0
676
- data -= mode
679
+ # Center data around 0.0
680
+ data -= mode
677
681
678
- # Provide a less opaque error if we still can't figure it out
679
- neg = data < 0
680
- pos = data > 0
681
- if not (neg .any () and pos .any ()):
682
- raise ValueError ("Could not find an appropriate mode to center phase values around" )
682
+ # Provide a less opaque error if we still can't figure it out
683
+ neg = data < 0
684
+ pos = data > 0
685
+ if not (neg .any () and pos .any ()):
686
+ raise ValueError ("Could not find an appropriate mode to center phase values around" )
683
687
684
- # Scale lower tail
685
- data [neg ] = - np .pi * data [neg ] / data [neg ].min ()
688
+ # Scale lower tail
689
+ data [neg ] = - np .pi * data [neg ] / data [neg ].min ()
686
690
687
- # Scale upper tail
688
- data [pos ] = np .pi * data [pos ] / data [pos ].max ()
691
+ # Scale upper tail
692
+ data [pos ] = np .pi * data [pos ] / data [pos ].max ()
689
693
690
- # Offset to 0 - 2pi
691
- data += np .pi
694
+ # Offset to 0 - 2pi
695
+ data += np .pi
692
696
693
697
# Clip
694
698
data = np .clip (data , 0.0 , 2 * np .pi )
0 commit comments