Skip to content

Commit a317c05

Browse files
Merge pull request #50 from matthewtownson/master
Tidying function names ready for v1.0
2 parents f55ac77 + 0a39916 commit a317c05

14 files changed

+75
-200
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ branches:
88
- v*
99

1010
python:
11-
- 2.7
1211
# - 3.4 Not in travis repositories
13-
- 3.5
12+
#- 3.5 Not in travis repositories
1413
- 3.6
1514
- 3.7
1615

aotools/functions/_functions.py

+1-83
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import numpy
2-
from . import pupil
3-
import warnings
42

53

64
def gaussian2d(size, width, amplitude=1., cent=None):
@@ -40,84 +38,4 @@ def gaussian2d(size, width, amplitude=1., cent=None):
4038
image = amplitude * numpy.exp(
4139
-(((xCent - X) / xWidth) ** 2 + ((yCent - Y) / yWidth) ** 2) / 2)
4240

43-
return image
44-
45-
46-
def aziAvg(data):
47-
"""
48-
Measure the azimuthal average of a 2d array
49-
50-
Args:
51-
data (ndarray): A 2-d array of data
52-
53-
Returns:
54-
ndarray: A 1-d vector of the azimuthal average
55-
"""
56-
warnings.warn("This function will be removed in version 0.5, instead use aotools.image_processing.azimuthal_average",
57-
DeprecationWarning)
58-
59-
size = data.shape[0]
60-
avg = numpy.empty(int(size / 2), dtype="float")
61-
for i in range(int(size / 2)):
62-
ring = pupil.circle(i + 1, size) - pupil.circle(i, size)
63-
avg[i] = (ring * data).sum() / (ring.sum())
64-
65-
return avg
66-
67-
68-
def encircledEnergy(data,
69-
fraction=0.5, center=None,
70-
eeDiameter=True):
71-
"""
72-
Return the encircled energy diameter for a given fraction
73-
(default is ee50d).
74-
Can also return the encircled energy function.
75-
Translated and extended from YAO.
76-
77-
Parameters:
78-
data : 2-d array
79-
fraction : energy fraction for diameter calculation
80-
default = 0.5
81-
center : default = center of image
82-
eeDiameter : toggle option for return.
83-
If False returns two vectors: (x, ee(x))
84-
Default = True
85-
Returns:
86-
Encircled energy diameter
87-
or
88-
2 vectors: diameters and encircled energies
89-
90-
"""
91-
warnings.warn(
92-
"This function will be removed in version 0.5, instead use aotools.image_processing.encircled_energy",
93-
DeprecationWarning)
94-
95-
dim = data.shape[0] // 2
96-
if center is None:
97-
center = [dim, dim]
98-
xc = center[0]
99-
yc = center[1]
100-
e = 1.9
101-
npt = 20
102-
rad = numpy.linspace(0, dim**(1. / e), npt)**e
103-
ee = numpy.empty(rad.shape)
104-
105-
for i in range(npt):
106-
pup = pupil.circle(rad[i],
107-
int(dim) * 2,
108-
circle_centre=(xc, yc),
109-
origin='corner')
110-
rad[i] = numpy.sqrt(numpy.sum(pup) * 4 / numpy.pi) # diameter
111-
ee[i] = numpy.sum(pup * data)
112-
113-
rad = numpy.append(0, rad)
114-
ee = numpy.append(0, ee)
115-
ee /= numpy.sum(data)
116-
xi = numpy.linspace(0, dim, int(4 * dim))
117-
yi = numpy.interp(xi, rad, ee)
118-
119-
if eeDiameter is False:
120-
return xi, yi
121-
else:
122-
ee50d = float(xi[numpy.argmin(numpy.abs(yi - fraction))])
123-
return ee50d
41+
return image

aotools/functions/zernike.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def phaseFromZernikes(zCoeffs, size, norm="noll"):
2828
return phase
2929

3030

31-
def zernike(j, N):
31+
def zernike_noll(j, N):
3232
"""
3333
Creates the Zernike polynomial with mode index j,
3434
where j = 1 corresponds to piston.
@@ -143,7 +143,7 @@ def zernikeArray(J, N, norm="noll"):
143143
nJ = len(J)
144144
Zs = numpy.empty((nJ, N, N))
145145
for i in xrange(nJ):
146-
Zs[i] = zernike(J[i], N)
146+
Zs[i] = zernike_noll(J[i], N)
147147

148148
# Else, cast to int and create up to that number
149149
except TypeError:
@@ -154,7 +154,7 @@ def zernikeArray(J, N, norm="noll"):
154154
Zs = numpy.empty((maxJ, N, N))
155155

156156
for j in xrange(1, maxJ+1):
157-
Zs[j-1] = zernike(j, N)
157+
Zs[j-1] = zernike_noll(j, N)
158158

159159

160160
if norm=="p2v":

aotools/image_processing/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from .centroiders import *
2-
from ._image_processing import *
32
from .contrast import *
43
from .psf import *

aotools/image_processing/_image_processing.py

-43
This file was deleted.

aotools/image_processing/centroiders.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def correlation_centroid(im, ref, threshold=0., padding=1):
4141
# Correlate frame with reference image
4242
corr = cross_correlate(im[frame], ref, padding=padding)
4343

44-
cx, cy = centreOfGravity(corr, threshold=threshold)
44+
cx, cy = centre_of_gravity(corr, threshold=threshold)
4545

4646
cy -= float(ny) / 2. * (float(padding) - 1)
4747
cx -= float(nx) / 2. * (float(padding) - 1)
@@ -51,20 +51,16 @@ def correlation_centroid(im, ref, threshold=0., padding=1):
5151
return centroids
5252

5353

54-
def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs):
54+
def centre_of_gravity(img, threshold=0, min_threshold=0, **kwargs):
5555
"""
5656
Centroids an image, or an array of images.
5757
Centroids over the last 2 dimensions.
5858
Sets all values under "threshold*max_value" to zero before centroiding
5959
Origin at 0,0 index of img.
6060
61-
The value under which pixels are set to 0
62-
is max(threshold*max_value, minThreshold)
63-
6461
Parameters:
6562
img (ndarray): ([n, ]y, x) 2d or greater rank array of imgs to centroid
6663
threshold (float): Percentage of max value under which pixels set to 0
67-
minThreshold (float): Absolute max value under which pixels set to 0
6864
6965
Returns:
7066
ndarray: Array of centroid values (2[, n])
@@ -73,10 +69,10 @@ def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs):
7369

7470
if threshold != 0:
7571
if len(img.shape) == 2:
76-
thres = numpy.max((threshold*img.max(), minThreshold))
72+
thres = numpy.max((threshold*img.max(), min_threshold))
7773
img = numpy.where(img > thres, img - thres, 0)
7874
else:
79-
thres = numpy.maximum(threshold*img.max(-1).max(-1), [minThreshold]*img.shape[0])
75+
thres = numpy.maximum(threshold*img.max(-1).max(-1), [min_threshold]*img.shape[0])
8076
img_temp = (img.T - thres).T
8177
zero_coords = numpy.where(img_temp < 0)
8278
img[zero_coords] = 0
@@ -94,7 +90,7 @@ def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs):
9490
return numpy.array([x_centroid, y_centroid])
9591

9692

97-
def brightestPxl(img, threshold, **kwargs):
93+
def brightest_pixel(img, threshold, **kwargs):
9894
"""
9995
Centroids using brightest Pixel Algorithm
10096
(A. G. Basden et al, MNRAS, 2011)
@@ -124,7 +120,7 @@ def brightestPxl(img, threshold, **kwargs):
124120
img[:] = (img.T - pxlValues).T
125121
img = img.clip(0, img.max(), out=img)
126122

127-
return centreOfGravity(img)
123+
return centre_of_gravity(img)
128124

129125

130126
def cross_correlate(x, y, padding=1):

aotools/turbulence/slopecovariance.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
1616
"""
1717

18-
import time
1918
import multiprocessing
2019

2120
import numpy
2221
import scipy.special
2322

24-
from ..functions import circle
2523

2624
class CovarianceMatrix(object):
2725
"""

appveyor.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ build: false
22

33
environment:
44
matrix:
5-
- PYTHON_VERSION: 2.7
6-
MINICONDA: C:\Miniconda-x64
7-
85
- PYTHON_VERSION: 3.5
96
MINICONDA: C:\Miniconda35-x64
107

8+
- PYTHON_VERSION: 3.6
9+
MINICONDA: C:\Miniconda36-x64
10+
11+
- PYTHON_VERSION: 3.7
12+
MINICONDA: C:\Miniconda37-x64
13+
1114

1215
branches:
1316
only:

doc/source/conf.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,20 @@ def __getattr__(cls, name):
8080

8181
# General information about the project.
8282
project = u'AOtools'
83-
copyright = u'2016, Centre for Advanced Instrumentation'
84-
author = u'Centre for Advanced Instrumentation'
83+
copyright = u'2019, The Authors'
84+
author = u'AOtools'
8585

8686
# The version info for the project you're documenting, acts as replacement for
8787
# |version| and |release|, also used in various other places throughout the
8888
# built documents.
8989
#
9090
# The short X.Y version.
91-
version = u'0.1'
91+
full_version = aotools.__version__
92+
version_parts = full_version.split('.')
93+
print(version_parts)
94+
version = u'0.5'
9295
# The full version, including alpha/beta/rc tags.
93-
release = u'0.1.0'
96+
release = aotools.__version__ # '0.1.0'
9497

9598
# The language for content autogenerated by Sphinx. Refer to documentation
9699
# for a list of supported languages.

test/test_centroiders.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33
from nose.tools import raises
44

55

6-
def test_centreOfGravity_single():
6+
def test_centre_of_gravity_single():
77
img = numpy.random.random((10, 10))
8-
com = image_processing.centreOfGravity(img, 0.1)
8+
com = image_processing.centre_of_gravity(img, 0.1)
99
assert(com.shape[0]) == 2
1010

1111

12-
def test_centreOfGravity_many():
12+
def test_centre_of_gravity_many():
1313
img = numpy.random.random((5, 10, 10))
14-
com = image_processing.centreOfGravity(img, 0.1)
14+
com = image_processing.centre_of_gravity(img, 0.1)
1515
assert(com.shape[0] == 2)
1616
assert(com.shape[1] == 5)
1717

18-
def test_centreOfGravity_value():
18+
def test_centre_of_gravity_value():
1919
img = numpy.zeros((1, 5, 5))
2020
img[0, 1:3, 2:4] = 1.
21-
centroid = image_processing.centreOfGravity(img)
21+
centroid = image_processing.centre_of_gravity(img)
2222
numpy.testing.assert_almost_equal(centroid, numpy.array([[2.5], [1.5]]))
2323

24-
def test_brightestPxl_single():
24+
def test_brightest_pixel_single():
2525
img = numpy.random.random((10, 10))
26-
com = image_processing.brightestPxl(img, 0.3)
26+
com = image_processing.brightest_pixel(img, 0.3)
2727
assert(com.shape[0] == 2)
2828

2929

3030
def test_brightestPxl_many():
3131
img = numpy.random.random((5, 10, 10))
32-
com = image_processing.brightestPxl(img, 0.1)
32+
com = image_processing.brightest_pixel(img, 0.1)
3333
assert(com.shape[0] == 2)
3434
assert(com.shape[1] == 5)
3535

test/test_functions.py

-23
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,3 @@ def test_gaussian2d_2d():
1111
gaussian = functions.gaussian2d((10, 8), (3, 2), 10., (4, 3))
1212
print(gaussian.shape)
1313
assert gaussian.shape == (10, 8)
14-
15-
16-
def test_encircledEnergy():
17-
data = numpy.random.rand(32, 32)
18-
ee50d = functions.encircledEnergy(data)
19-
print(ee50d)
20-
assert type(ee50d) == float
21-
22-
23-
def test_encircledEnergy_func():
24-
data = numpy.random.rand(32, 32)
25-
x, y = functions.encircledEnergy(data, eeDiameter=False)
26-
print(y.min(), y.max())
27-
assert len(x) == len(y)
28-
assert numpy.max(y) <= 1
29-
assert numpy.min(y) >= 0
30-
31-
32-
def test_aziAvg():
33-
data = numpy.random.rand(32, 32)
34-
azi = functions.aziAvg(data)
35-
print(azi.shape)
36-
assert azi.shape == (16,)

0 commit comments

Comments
 (0)