Skip to content

Commit e6cafa9

Browse files
authored
Merge pull request #652 from VChristiaens/master
New options for NEGFC + minor bug fixes
2 parents 820bbb8 + f961f6b commit e6cafa9

File tree

17 files changed

+3418
-2249
lines changed

17 files changed

+3418
-2249
lines changed

docs/source/tutorials/.ipynb_checkpoints/01A_quickstart-checkpoint.ipynb

Lines changed: 0 additions & 1745 deletions
This file was deleted.

docs/source/tutorials/02_preproc.ipynb

Lines changed: 2838 additions & 69 deletions
Large diffs are not rendered by default.

tests/pre_3_10/test_metrics_contrcurve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tests.helpers import fixture
99
from tests.helpers import np
1010
from vip_hci.config import VLT_NACO
11-
from vip_hci.fm.utils_negfc import cube_planet_free
11+
from vip_hci.fm import cube_planet_free
1212
from vip_hci.fm.utils_negfc import find_nearest
1313
from vip_hci.metrics import contrast_curve
1414
from vip_hci.preproc import frame_crop

vip_hci/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.6.2"
1+
__version__ = "1.6.4"
22

33
from . import preproc
44
from . import config

vip_hci/fm/fakecomp.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
'normalize_psf',
77
'cube_inject_companions',
88
'generate_cube_copies_with_injections',
9-
'frame_inject_companion']
9+
'frame_inject_companion',
10+
'cube_planet_free']
1011

1112
from multiprocessing import cpu_count
1213
import numpy as np
@@ -810,3 +811,85 @@ def psf_norm_2d(psf, fwhm, threshold, mask_core, full_output, verbose):
810811
msg += " ``vip_hci.preproc.cube_collapse`` first, or loop on the "
811812
msg += "temporal axis."
812813
raise ValueError(msg.format(array.shape[0]))
814+
815+
816+
def cube_planet_free(planet_parameter, cube, angs, psfn, imlib='vip-fft',
817+
interpolation='lanczos4', transmission=None):
818+
"""Return a cube in which we have injected negative fake companion at the\
819+
position/flux given by planet_parameter.
820+
821+
Parameters
822+
----------
823+
planet_parameter: numpy.array or list or tuple
824+
The (r, theta, flux) for all known companions. For a 3D cube, this
825+
parameter must have a shape (n_pl,3) or (3,) -- the latter case assumes
826+
a single planet in the data. For a 4d cube r, theta and flux
827+
must all be 1d arrays with length equal to cube.shape[0]; i.e.
828+
planet_parameter should have shape: (n_pl,3,n_ch).
829+
cube: numpy ndarray
830+
The cube of fits images expressed as a numpy.array.
831+
angs: numpy ndarray
832+
The parallactic angle fits image expressed as a numpy.array.
833+
psfn: 2d or 3d numpy ndarray
834+
The normalized psf expressed as a numpy ndarray. Can be 3d for a 4d
835+
(spectral+ADI) input cube.
836+
imlib : str, optional
837+
See the documentation of the ``vip_hci.preproc.frame_rotate`` function.
838+
interpolation : str, optional
839+
See the documentation of the ``vip_hci.preproc.frame_rotate`` function.
840+
transmission: numpy array, optional
841+
Radial transmission of the coronagraph, if any. Array with either
842+
2 x n_rad, 1+n_ch x n_rad columns. The first column should contain the
843+
radial separation in pixels, while the other column(s) are the
844+
corresponding off-axis transmission (between 0 and 1), for either all,
845+
or each spectral channel (only relevant for a 4D input cube).
846+
847+
Returns
848+
-------
849+
cpf : numpy.array
850+
The cube with negative companions injected at the position given in
851+
planet_parameter.
852+
853+
"""
854+
cpf = np.zeros_like(cube)
855+
856+
# unify planet_parameter format
857+
planet_parameter = np.array(planet_parameter)
858+
cond1 = cube.ndim == 3 and planet_parameter.ndim < 2
859+
cond2 = cube.ndim == 4 and planet_parameter.ndim < 3
860+
if cond1 or cond2:
861+
planet_parameter = planet_parameter[np.newaxis, :]
862+
863+
if cube.ndim == 4:
864+
if planet_parameter.shape[2] != cube.shape[0]:
865+
raise TypeError("Input planet parameter with wrong dimensions.")
866+
867+
for i in range(planet_parameter.shape[0]):
868+
if i == 0:
869+
cube_temp = cube
870+
else:
871+
cube_temp = cpf
872+
873+
if cube.ndim == 4:
874+
for j in range(cube.shape[0]):
875+
flevel = -planet_parameter[i, 2, j]
876+
r = planet_parameter[i, 0, j]
877+
theta = planet_parameter[i, 1, j]
878+
cpf[j] = cube_inject_companions(cube_temp[j], psfn[j], angs,
879+
flevel=flevel,
880+
rad_dists=[r],
881+
n_branches=1,
882+
theta=theta,
883+
imlib=imlib,
884+
interpolation=interpolation,
885+
verbose=False,
886+
transmission=transmission)
887+
else:
888+
cpf = cube_inject_companions(cube_temp, psfn, angs, n_branches=1,
889+
flevel=-planet_parameter[i, 2],
890+
rad_dists=[planet_parameter[i, 0]],
891+
theta=planet_parameter[i, 1],
892+
imlib=imlib, verbose=False,
893+
interpolation=interpolation,
894+
transmission=transmission)
895+
return cpf

0 commit comments

Comments
 (0)