-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
122 lines (95 loc) · 4.25 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import numpy as np
from hcipy import *
from astropy.io import fits
### UBVRIJHK Filter Info
## Taken from http://www.astronomy.ohio-state.edu/~martini/usefuldata.html
## Flux0 - erg/cm^2/s/A
## photons0 - photons/cm^2/s/A
## lambda_eff - um
## delta_lambda - um
filters = {
"U": {"Flux0": 4.175e-9, "lambda_eff":0.36 , "delta_lambda":0.06 , "photons0":756.1},
"B": {"Flux0": 6.32e-9 , "lambda_eff":0.438, "delta_lambda":0.09 , "photons0":1392.6},
"V": {"Flux0": 3.631e-9, "lambda_eff":0.545, "delta_lambda":0.085, "photons0":995.5},
"R": {"Flux0": 2.177e-9, "lambda_eff":0.641, "delta_lambda":0.15 , "photons0":702.9},
"I": {"Flux0": 1.126e-9, "lambda_eff":0.798, "delta_lambda":0.15 , "photons0":452},
"J": {"Flux0": 0.315e-9, "lambda_eff":1.22 , "delta_lambda":0.26 , "photons0":193.1},
"H": {"Flux0": 0.114e-9, "lambda_eff":1.63 , "delta_lambda":0.29 , "photons0":93.3},
"K": {"Flux0": 0.004e-9, "lambda_eff":2.19 , "delta_lambda":0.41 , "photons0":43.6},
}
def make_lick_aperture(normalized=False, with_spiders=True):
'''
This is almost a lick aperture, based on the hcipy make_magellan_aperture
Make the Magellan aperture.
Parameters
----------
normalized : boolean
If this is True, the outer diameter will be scaled to 1. Otherwise, the
diameter of the pupil will be 6.5 meters.
with_spiders: boolean
If this is False, the spiders will be left out.
Returns
-------
Field generator
The Magellan aperture.
'''
pupil_diameter = 3.048 #m
spider_width1 = 0.75 * 0.0254 #m
spider_width2 = 1.5 * 0.0254 #m
secondary_diameter = 0.9779 #
central_obscuration_ratio = secondary_diameter/pupil_diameter #
spider_offset = [0,0.34] #m
if normalized:
spider_width1 /= pupil_diameter
spider_width2 /= pupil_diameter
spider_offset = [x / pupil_diameter for x in spider_offset]
pupil_diameter = 1.0
spider_offset = np.array(spider_offset)
mirror_edge1 = (pupil_diameter / (2 * np.sqrt(2)), pupil_diameter / (2 * np.sqrt(2)))
mirror_edge2 = (-pupil_diameter / (2 * np.sqrt(2)), pupil_diameter / (2 * np.sqrt(2)))
mirror_edge3 = (pupil_diameter / (2 * np.sqrt(2)), -pupil_diameter / (2 * np.sqrt(2)))
mirror_edge4 = (-pupil_diameter / (2 * np.sqrt(2)), -pupil_diameter / (2 * np.sqrt(2)))
obstructed_aperture = make_obstructed_circular_aperture(pupil_diameter, central_obscuration_ratio)
if not with_spiders:
return obstructed_aperture
spider1 = make_spider(spider_offset, mirror_edge1, spider_width1)
spider2 = make_spider(spider_offset, mirror_edge2, spider_width1)
spider3 = make_spider(-spider_offset, mirror_edge3, spider_width2)
spider4 = make_spider(-spider_offset, mirror_edge4, spider_width2)
def func(grid):
return obstructed_aperture(grid) * spider1(grid) * spider2(grid) * spider3(grid) * spider4(grid)
return func
def number_of_photons(mag, filter_name, collecting_area):
'''
Return the number of photons/s captured by the collecting
area for the given magnitude and filter
'''
photons0 = filters[filter_name]['photons0'] #units: photons/cm^2/s/A
#Convert to the correct magnitude
photons = photons0*10**(mag/(-2.5))
#Multiply by collecting area
photons = photons*collecting_area*1e4 #Convert to cm^2
#Multiply by filter width
delta_lambda = filters[filter_name]['delta_lambda']
delta_lambda *=1e4 #Convert to of Angstrom
photons = photons*delta_lambda
return photons
def save_field_to_fits(field, filename, path="./", verbose=False,overwrite=False):
'''
Save a field to a fits file
'''
#Convert a field to a numpy array
np_field = np.array(field.shaped)
hdu = fits.PrimaryHDU(np_field)
if verbose:
print("Saving a field to {}".format(path+filename))
hdu.writeto(path+filename,overwrite=overwrite)
def supergauss_hw(HWHM,m,size):
"""
creates a supergaussian window with a given HWHM, order, and size
"""
k = -1.0 / (HWHM**m)
ds = np.array([[np.sqrt(np.array((x-size/2)**2+(y-size/2)**2)) for x in range(size)]
for y in range(size)])
arr = np.exp(k*ds**m)
return arr