Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LAM-GRD-public
maoppy
Commits
13c5d29e
Commit
13c5d29e
authored
Sep 08, 2021
by
rfetick
Browse files
remove some underscore in imports
parent
1aa1b7c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
maoppy/psfmodel.py
View file @
13c5d29e
...
...
@@ -7,11 +7,11 @@ Created on Mon May 27 17:31:18 2019
"""
import
numpy
as
_np
from
scipy.optimize
import
least_squares
as
_least_squares
from
astropy.io
import
fits
as
_fit
s
import
time
as
_time
import
numpy.fft
as
_fft
import
sys
as
_sys
from
numpy.fft
import
fft2
,
ifft2
,
fftshift
from
scipy.optimize
import
least_square
s
from
astropy.io
import
fits
import
time
import
sys
from
maoppy.utils
import
binning
as
_binning
...
...
@@ -20,7 +20,7 @@ __all__ = ["oversample", "lsq_flux_bck", "psffit", "reduced_coord",
"Gaussian"
,
"ParametricPSFfromPSD"
,
"Turbulent"
,
"Psfao"
]
# Value to compute finite differences
_EPSILON
=
_np
.
sqrt
(
_
sys
.
float_info
.
epsilon
)
_EPSILON
=
_np
.
sqrt
(
sys
.
float_info
.
epsilon
)
#%% FUNCTIONS
def
oversample
(
samp
,
fixed_k
=
None
):
...
...
@@ -194,7 +194,7 @@ def psffit(psf,Model,x0,weights=None,dxdy=(0.,0.),flux_bck=(True,True),
b_up
=
_np
.
concatenate
((
b_up
,[
_np
.
inf
,
_np
.
inf
]))
return
(
b_low
,
b_up
)
result
=
_
least_squares
(
cost
,
input2mini
(
x0
,
dxdy
),
bounds
=
get_bound
(
Model_inst
))
result
=
least_squares
(
cost
,
input2mini
(
x0
,
dxdy
),
bounds
=
get_bound
(
Model_inst
))
print
(
""
)
#finish line of "-"
...
...
@@ -363,7 +363,7 @@ class ParametricPSF(object):
def
otf
(
self
,
*
args
,
**
kwargs
):
"""Return the Optical Transfer Function (OTF)"""
psf
=
self
.
__call__
(
args
,
kwargs
)
return
_fft
.
fftshift
(
_fft
.
fft2
(
psf
))
return
fftshift
(
fft2
(
psf
))
def
mtf
(
self
,
*
args
,
**
kwargs
):
"""Return the Modulation Transfer Function (MTF)"""
...
...
@@ -372,7 +372,7 @@ class ParametricPSF(object):
def
tofits
(
self
,
param
,
filename
,
*
args
,
keys
=
None
,
keys_comment
=
None
,
**
kwargs
):
psf
=
self
.
__call__
(
param
,
*
args
,
**
kwargs
)
hdr
=
self
.
_getfitshdr
(
param
,
keys
=
keys
,
keys_comment
=
keys_comment
)
hdu
=
_
fits
.
PrimaryHDU
(
psf
,
hdr
)
hdu
=
fits
.
PrimaryHDU
(
psf
,
hdr
)
hdu
.
writeto
(
filename
,
overwrite
=
True
)
def
_getfitshdr
(
self
,
param
,
keys
=
None
,
keys_comment
=
None
):
...
...
@@ -380,10 +380,10 @@ class ParametricPSF(object):
if
len
(
keys
)
!=
len
(
param
):
raise
ValueError
(
"When defined, `keys` must be same size as `param`"
)
if
keys_comment
is
not
None
:
if
len
(
keys_comment
)
!=
len
(
param
):
raise
ValueError
(
"When defined, `keys_comment` must be same size as `param`"
)
hdr
=
_
fits
.
Header
()
hdr
=
fits
.
Header
()
hdr
[
"HIERARCH ORIGIN"
]
=
"MAOPPY automatic header"
hdr
[
"HIERARCH CREATION"
]
=
(
_
time
.
ctime
(),
"Date of file creation"
)
hdr
[
"HIERARCH CREATION"
]
=
(
time
.
ctime
(),
"Date of file creation"
)
for
i
in
range
(
len
(
param
)):
if
keys_comment
is
None
:
hdr
[
"HIERARCH PARAM "
+
keys
[
i
]]
=
param
[
i
]
...
...
@@ -601,17 +601,17 @@ class ParametricPSFfromPSD(ParametricPSF):
else
:
PSD
,
integral
=
self
.
psd
(
x0
,
grad
=
False
)
Bphi
=
_np
.
real
(
_fft
.
fft2
(
_fft
.
fftshift
(
PSD
)))
/
L
**
2
#Bphi =
_fft.
fftshift(Bphi[0, 0] - Bphi) # normalized on the numerical FoV
Bphi
=
_fft
.
fftshift
(
integral
-
Bphi
)
# normalized up to infinity
Bphi
=
_np
.
real
(
fft2
(
fftshift
(
PSD
)))
/
L
**
2
#Bphi = fftshift(Bphi[0, 0] - Bphi) # normalized on the numerical FoV
Bphi
=
fftshift
(
integral
-
Bphi
)
# normalized up to infinity
otf
=
_np
.
exp
(
-
Bphi
)
if
grad
:
g2
=
_np
.
zeros
(
g
.
shape
,
dtype
=
complex
)
# I cannot override 'g' here due to float to complex type
for
i
in
range
(
len
(
x0
)):
Bphi
=
_np
.
real
(
_fft
.
fft2
(
_fft
.
fftshift
(
g
[
i
,...])))
/
L
**
2
#Bphi =
_fft.
fftshift(Bphi[0, 0] - Bphi) # normalized on the numerical FoV
Bphi
=
_fft
.
fftshift
(
integral_g
[
i
]
-
Bphi
)
# normalized up to infinity
Bphi
=
_np
.
real
(
fft2
(
fftshift
(
g
[
i
,...])))
/
L
**
2
#Bphi = fftshift(Bphi[0, 0] - Bphi) # normalized on the numerical FoV
Bphi
=
fftshift
(
integral_g
[
i
]
-
Bphi
)
# normalized up to infinity
g2
[
i
,...]
=
-
Bphi
*
otf
return
otf
,
g2
return
otf
...
...
@@ -622,7 +622,7 @@ class ParametricPSFfromPSD(ParametricPSF):
NpupY
=
_np
.
ceil
(
ny
/
self
.
_samp_over
)
tab
=
_np
.
zeros
((
nx
,
ny
),
dtype
=
complex
)
tab
[
0
:
int
(
NpupX
),
0
:
int
(
NpupY
)]
=
self
.
system
.
pupil
((
NpupX
,
NpupY
),
samp
=
self
.
_samp_over
)
self
.
_otfDiffraction
=
_fft
.
fftshift
(
_np
.
abs
(
_fft
.
ifft2
(
_np
.
abs
(
_fft
.
fft2
(
tab
))
**
2
))
/
_np
.
sum
(
tab
))
self
.
_otfDiffraction
=
fftshift
(
_np
.
abs
(
ifft2
(
_np
.
abs
(
fft2
(
tab
))
**
2
))
/
_np
.
sum
(
tab
))
def
_otfShift
(
self
,
dx
,
dy
):
Y
,
X
=
self
.
_fxfy
/
self
.
_pix2freq
# so it is just an array of pixels
...
...
@@ -650,11 +650,11 @@ class ParametricPSFfromPSD(ParametricPSF):
if
grad
:
otf
,
g
=
self
.
otf
(
x0
,
dx
=
dx
,
dy
=
dy
,
_caller
=
'self'
,
grad
=
True
)
for
i
in
range
(
len
(
x0
)):
g
[
i
,...]
=
_np
.
real
(
_fft
.
fftshift
(
_fft
.
ifft2
(
_fft
.
fftshift
(
g
[
i
,...]))))
g
[
i
,...]
=
_np
.
real
(
fftshift
(
ifft2
(
fftshift
(
g
[
i
,...]))))
else
:
otf
=
self
.
otf
(
x0
,
dx
=
dx
,
dy
=
dy
,
_caller
=
'self'
,
grad
=
False
)
psf
=
_np
.
real
(
_fft
.
fftshift
(
_fft
.
ifft2
(
_fft
.
fftshift
(
otf
))))
psf
=
_np
.
real
(
fftshift
(
ifft2
(
fftshift
(
otf
))))
k
=
int
(
self
.
_k
)
if
k
==
1
:
...
...
@@ -911,5 +911,5 @@ class Psfao(ParametricPSFfromPSD):
hdr
[
"HIERARCH SAMP"
]
=
(
self
.
samp
,
"Sampling (eg. 2 for Shannon)"
)
hdr
[
"HIERARCH LEXT"
]
=
(
self
.
Lext
,
"Von-Karman outer scale"
)
hdu
=
_
fits
.
PrimaryHDU
(
psf
,
hdr
)
hdu
=
fits
.
PrimaryHDU
(
psf
,
hdr
)
hdu
.
writeto
(
filename
,
overwrite
=
overwrite
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment