-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from andrewpaulreeves/NewStructure
New structure for AOTools
- Loading branch information
Showing
18 changed files
with
269 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .astronomy import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .functions import * | ||
from .pupil import * | ||
from .zernike import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import numpy | ||
|
||
|
||
def gaussian2d(size, width, amplitude=1., cent=None): | ||
''' | ||
Generates 2D gaussian distribution | ||
Args: | ||
size (tuple, float): Dimensions of Array to place gaussian | ||
width (tuple, float): Width of distribution. | ||
Accepts tuple for x and y values. | ||
amplitude (float): Amplitude of guassian distribution | ||
cent (tuple): Centre of distribution on grid. | ||
''' | ||
|
||
try: | ||
xSize = size[0] | ||
ySize = size[1] | ||
except (TypeError, IndexError): | ||
xSize = ySize = size | ||
|
||
try: | ||
xWidth = float(width[0]) | ||
yWidth = float(width[1]) | ||
except (TypeError, IndexError): | ||
xWidth = yWidth = float(width) | ||
|
||
if not cent: | ||
xCent = size[0] / 2. | ||
yCent = size[1] / 2. | ||
else: | ||
xCent = cent[0] | ||
yCent = cent[1] | ||
|
||
X, Y = numpy.meshgrid(range(0, xSize), range(0, ySize)) | ||
|
||
image = amplitude * numpy.exp( | ||
-(((xCent - X) / xWidth) ** 2 + ((yCent - Y) / yWidth) ** 2) / 2) | ||
|
||
return image | ||
|
||
|
||
def aziAvg(data): | ||
""" | ||
Measure the azimuthal average of a 2d array | ||
Args: | ||
data (ndarray): A 2-d array of data | ||
Returns: | ||
ndarray: A 1-d vector of the azimuthal average | ||
""" | ||
|
||
size = data.shape[0] | ||
avg = numpy.empty(size / 2, dtype="float") | ||
for i in range(size / 2): | ||
ring = circle(i + 1, size) - circle(i, size) | ||
avg[i] = (ring * data).sum() / (ring.sum()) | ||
|
||
return avg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
def circle(radius, size, circle_centre=(0, 0), origin="middle"): | ||
""" | ||
Create a 2-D array: elements equal 1 within a circle and 0 outside. | ||
The default centre of the coordinate system is in the middle of the array: | ||
circle_centre=(0,0), origin="middle" | ||
This means: | ||
if size is odd : the centre is in the middle of the central pixel | ||
if size is even : centre is in the corner where the central 4 pixels meet | ||
origin = "corner" is used e.g. by psfAnalysis:radialAvg() | ||
Examples: | ||
circle(1,5) circle(0,5) circle(2,5) circle(0,4) circle(0.8,4) circle(2,4) | ||
00000 00000 00100 0000 0000 0110 | ||
00100 00000 01110 0000 0110 1111 | ||
01110 00100 11111 0000 0110 1111 | ||
00100 00000 01110 0000 0000 0110 | ||
00000 00000 00100 | ||
circle(1,5,(0.5,0.5)) circle(1,4,(0.5,0.5)) | ||
.-->+ | ||
| 00000 0000 | ||
| 00000 0010 | ||
+V 00110 0111 | ||
00110 0010 | ||
00000 | ||
Args: | ||
radius (float) : radius of the circle | ||
size (int) : size of the 2-D array in which the circle lies | ||
circle_centre (tuple): coords of the centre of the circle | ||
origin (str) : where is the origin of the coordinate system | ||
in which circle_centre is given; | ||
allowed values: {"middle", "corner"} | ||
Returns: | ||
ndarray (float64) : the circle array | ||
Raises: | ||
TypeError if input is of wrong type | ||
Exception if a bug in generation of coordinates is detected (see code) | ||
""" | ||
# (2) Generate the output array: | ||
C = numpy.zeros((size, size)) | ||
|
||
# (3.a) Generate the 1-D coordinates of the pixel's centres: | ||
# coords = numpy.linspace(-size/2.,size/2.,size) # Wrong!!: | ||
# size = 5: coords = array([-2.5 , -1.25, 0. , 1.25, 2.5 ]) | ||
# size = 6: coords = array([-3. , -1.8, -0.6, 0.6, 1.8, 3. ]) | ||
# (2015 Mar 30; delete this comment after Dec 2015 at the latest.) | ||
|
||
# Before 2015 Apr 7 (delete 2015 Dec at the latest): | ||
# coords = numpy.arange(-size/2.+0.5, size/2.-0.4, 1.0) | ||
# size = 5: coords = array([-2., -1., 0., 1., 2.]) | ||
# size = 6: coords = array([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5]) | ||
|
||
coords = numpy.arange(0.5, size, 1.0) | ||
# size = 5: coords = [ 0.5 1.5 2.5 3.5 4.5] | ||
# size = 6: coords = [ 0.5 1.5 2.5 3.5 4.5 5.5] | ||
|
||
# (3.b) Just an internal sanity check: | ||
if len(coords) != size: | ||
raise exceptions.Bug("len(coords) = {0}, ".format(len(coords)) + | ||
"size = {0}. They must be equal.".format(size) + | ||
"\n Debug the line \"coords = ...\".") | ||
|
||
# (3.c) Generate the 2-D coordinates of the pixel's centres: | ||
x, y = numpy.meshgrid(coords, coords) | ||
|
||
# (3.d) Move the circle origin to the middle of the grid, if required: | ||
if origin == "middle": | ||
x -= size / 2. | ||
y -= size / 2. | ||
|
||
# (3.e) Move the circle centre to the alternative position, if provided: | ||
x -= circle_centre[0] | ||
y -= circle_centre[1] | ||
|
||
# (4) Calculate the output: | ||
# if distance(pixel's centre, circle_centre) <= radius: | ||
# output = 1 | ||
# else: | ||
# output = 0 | ||
mask = x * x + y * y <= radius * radius | ||
C[mask] = 1 | ||
|
||
# (5) Return: | ||
return C |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .centroiders import * | ||
from .image_processing import * |
File renamed without changes.
Oops, something went wrong.