Skip to content

Commit

Permalink
Merge branch 'vortex-exoplanet:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
IainHammond authored Jan 22, 2025
2 parents 9c10a1c + a097370 commit dba55b8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
19 changes: 17 additions & 2 deletions vip_hci/config/utils_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,23 @@ def pool_map(nproc, fkt, *args, **kwargs):
else:
# Check available start methods and pick accordingly (machine-dependent)
avail_methods = multiprocessing.get_all_start_methods()
# if 'forkserver' in avail_methods: # fast and safe, if available
# multiprocessing.set_start_method("forkserver", force=True)
# LATEST:
# if 'forkserver' in avail_methods: # fast but unsafe, if available
# # faster when available
# try:
# multiprocessing.set_start_method("forkserver", force=True)
# print("start method set to forkserver")
# except (DeprecationWarning, OSError):
# multiprocessing.set_start_method("spawn", force=True)
# else: # slower but safe
# multiprocessing.set_start_method("spawn", force=True)

# BEFORE:
if 'fork' in avail_methods:
# faster when available
warnings.filterwarnings("error") # allows to catch warning as error
# warnings.filterwarnings("error") # to catch warning as error
try:
multiprocessing.set_start_method("fork", force=True)
except (DeprecationWarning, OSError):
Expand All @@ -485,7 +499,8 @@ def pool_map(nproc, fkt, *args, **kwargs):
multiprocessing.set_start_method("forkserver", force=True)
else:
multiprocessing.set_start_method("spawn", force=True)
warnings.resetwarnings() # reset warning behaviour to default
# warnings.resetwarnings() # reset warning behaviour to default

from multiprocessing import Pool

# deactivate multithreading
Expand Down
23 changes: 17 additions & 6 deletions vip_hci/fm/fakecomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ def cube_inject_companions(array, psf_template, angle_list, flevel, rad_dists,
radial_gradient: bool, optional
Whether to apply a radial gradient to the psf image at the moment of
injection. By default False, i.e. the flux of the psf image is scaled
only considering the value of tramnsmission at the exact radius the
companion is injected. Setting it to False may better represent the
transmission at the very edge of a physical mask though.
only considering the value of transmission at the exact radius the
companion is injected (e.g. this is the case for the vortex
coronagraph). Setting it to True may better represent the transmission
at the very edge of a physical mask though (e.g. ALC).
full_output : bool, optional
Returns the ``x`` and ``y`` coordinates of the injections, additionally
to the new array.
Expand Down Expand Up @@ -814,7 +815,8 @@ def psf_norm_2d(psf, fwhm, threshold, mask_core, full_output, verbose):


def cube_planet_free(planet_parameter, cube, angs, psfn, imlib='vip-fft',
interpolation='lanczos4', transmission=None):
interpolation='lanczos4', transmission=None,
radial_gradient=False):
"""Return a cube in which we have injected negative fake companion at the\
position/flux given by planet_parameter.
Expand Down Expand Up @@ -843,6 +845,13 @@ def cube_planet_free(planet_parameter, cube, angs, psfn, imlib='vip-fft',
radial separation in pixels, while the other column(s) are the
corresponding off-axis transmission (between 0 and 1), for either all,
or each spectral channel (only relevant for a 4D input cube).
radial_gradient: bool, optional
Whether to apply a radial gradient to the psf image at the moment of
injection. By default False, i.e. the flux of the psf image is scaled
only considering the value of transmission at the exact radius the
companion is injected (e.g. this is the case for the vortex
coronagraph). Setting it to True may better represent the transmission
at the very edge of a physical mask though (e.g. ALC).
Returns
-------
Expand Down Expand Up @@ -883,13 +892,15 @@ def cube_planet_free(planet_parameter, cube, angs, psfn, imlib='vip-fft',
imlib=imlib,
interpolation=interpolation,
verbose=False,
transmission=transmission)
transmission=transmission,
radial_gradient=radial_gradient)
else:
cpf = cube_inject_companions(cube_temp, psfn, angs, n_branches=1,
flevel=-planet_parameter[i, 2],
rad_dists=[planet_parameter[i, 0]],
theta=planet_parameter[i, 1],
imlib=imlib, verbose=False,
interpolation=interpolation,
transmission=transmission)
transmission=transmission,
radial_gradient=radial_gradient)
return cpf
60 changes: 38 additions & 22 deletions vip_hci/var/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@


def dist(yc, xc, y1, x1):
"""
Return the Euclidean distance between two points, or between an array
of positions and a point.
"""
"""Return the Euclidean distance between two points, or between an array \
of positions and a point."""
return np.hypot(yc - y1, xc - x1)


Expand Down Expand Up @@ -62,9 +60,9 @@ def dist_matrix(n, cx=None, cy=None):

def frame_center(array, verbose=False):
"""
Return the coordinates y,x of the frame(s) center.
If odd: dim/2-0.5
If even: dim/2
Return the coordinates y,x of the frame(s) center.\
If odd: dim/2-0.5\
If even: dim/2.
Parameters
----------
Expand Down Expand Up @@ -102,17 +100,20 @@ def frame_center(array, verbose=False):
return int(cy), int(cx)


def cart_to_pol(x, y, cx=0, cy=0, astro_convention=False):
"""
Returns polar coordinates for input cartesian coordinates
def cart_to_pol(x, y, x_err=0, y_err=0, cx=0, cy=0, astro_convention=False):
"""Return polar coordinates for input cartesian coordinates, with error\
propagation.
Parameters
----------
x : float or numpy ndarray
x coordinates with respect to the center
y : float or numpy ndarray
y coordinates with respect to the center
x_err : float, optional
Error on x coordinate. Default is 0
y_err : float, optional
Error on y coordinate. Default is 0
cx, cy : float or numpy ndarray
x, y coordinates of the center of the image to be considered for
conversion to cartesian coordinates.
Expand All @@ -124,20 +125,36 @@ def cart_to_pol(x, y, cx=0, cy=0, astro_convention=False):
-------
r, theta: floats or numpy ndarrays
radii and polar angles corresponding to the input x and y.
"""
dr, dtheta: floats or numpy arrays
[if x_err != 0 or y_err != 0] dr, dtheta uncertainties on radius and
azimuth from input uncertainties on x and y, if provided.
"""
r = dist(cy, cx, y, x)
theta = np.rad2deg(np.arctan2(y-cy, x-cx))
if astro_convention:
theta -= 90

return r, theta
dx = (x-cx)
dy = (y-cy)

r1 = dx*x_err/np.sqrt(dx**2+dy**2)
r2 = dy*y_err/np.sqrt(dx**2+dy**2)
t1 = (1/(1+(dy/dx)**2)) * (1/dx) * y_err
t2 = (1/(1+(dy/dx)**2)) * (-1) * (dy/dx**2) * x_err

r_err = np.sqrt(r1**2 + r2**2)
theta_err = np.rad2deg(np.sqrt(t1**2 + t2**2))

if x_err != 0 or y_err != 0:
return r, theta, r_err, theta_err
else:
return r, theta


def pol_to_cart(r, theta, r_err=0, theta_err=0, cx=0, cy=0,
astro_convention=False):
"""
Returns cartesian coordinates for input polar coordinates, with error
"""Return cartesian coordinates for input polar coordinates, with error\
propagation.
Parameters
Expand All @@ -161,10 +178,10 @@ def pol_to_cart(r, theta, r_err=0, theta_err=0, cx=0, cy=0,
x, y: floats or numpy ndarrays
x, y positions corresponding to input radii and position angles.
dx, dy: floats or numpy arrays
dx, dy uncertainties on positions propagated from input uncertainties
on r and theta.
"""
[if r_err != 0 or theta_err != 0] dx, dy uncertainties on positions
propagated from input uncertainties on r and theta, if provided.
"""
if astro_convention:
theta += 90
sign = -1
Expand Down Expand Up @@ -193,7 +210,7 @@ def pol_to_cart(r, theta, r_err=0, theta_err=0, cx=0, cy=0,

def pol_to_eq(r, t, rError=0, tError=0, astro_convention=False, plot=False):
r"""
Converts a position (r,t) given in polar coordinates into :math:`\Delta` RA
Convert a position (r,t) given in polar coordinates into :math:`\Delta` RA
and :math:`\Delta` DEC (equatorial coordinates), with error propagation.
Note: regardless of the assumption on input angle t (see description for
`astro_convention`), the output RA is counted positive towards left.
Expand All @@ -220,7 +237,6 @@ def pol_to_eq(r, t, rError=0, tError=0, astro_convention=False, plot=False):
((RA, RA error), (DEC, DEC error))
"""

if not astro_convention:
t -= 90

Expand Down Expand Up @@ -266,7 +282,7 @@ def pol_to_eq(r, t, rError=0, tError=0, astro_convention=False, plot=False):
def QU_to_QUphi(Q, U, delta_x=0, delta_y=0, scale_r2=False,
north_convention=False):
"""
Returns Qphi and Uphi images, from input Q and U images.
Return Qphi and Uphi images, from input Q and U images.
Parameters
----------
Expand All @@ -288,8 +304,8 @@ def QU_to_QUphi(Q, U, delta_x=0, delta_y=0, scale_r2=False,
-------
Qphi, Uphi: numpy ndarrays
Qphi and Uphi images
"""
"""
cy, cx = frame_center(Q)
Qphi = np.zeros_like(Q)
Uphi = np.zeros_like(U)
Expand Down

0 comments on commit dba55b8

Please sign in to comment.