|
6 | 6 | 'normalize_psf', |
7 | 7 | 'cube_inject_companions', |
8 | 8 | 'generate_cube_copies_with_injections', |
9 | | - 'frame_inject_companion'] |
| 9 | + 'frame_inject_companion', |
| 10 | + 'cube_planet_free'] |
10 | 11 |
|
11 | 12 | from multiprocessing import cpu_count |
12 | 13 | import numpy as np |
@@ -810,3 +811,85 @@ def psf_norm_2d(psf, fwhm, threshold, mask_core, full_output, verbose): |
810 | 811 | msg += " ``vip_hci.preproc.cube_collapse`` first, or loop on the " |
811 | 812 | msg += "temporal axis." |
812 | 813 | 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