<commit_before>"""
Tests for the post-processing pipeline, using the functional API.

"""

import copy
import vip_hci as vip
from .helpers import np, parametrize, fixture


def print_debug(s, *args, **kwargs):
    print(("\033[34m" + s + "\033[0m").format(*args, **kwargs))


@fixture(scope="module")
def injected_cube_position(example_dataset_ifs):
    """
    Inject a fake companion into an example cube.

    Parameters
    ----------
    example_dataset_ifs : fixture
        Taken automatically from ``conftest.py``.

    Returns
    -------
    dsi : VIP Dataset
    injected_position_yx : tuple(y, x)

    """
    print_debug("injecting fake planet...")
    dsi = copy.copy(example_dataset_ifs)
    # we chose a shallow copy, as we will not use any in-place operations
    # (like +=). Using `deepcopy` would be safer, but consume more memory.

    dsi.inject_companions(50, rad_dists=30)

    return dsi, dsi.injections_yx[0]

@fixture(scope="module")
def estimated_scal_factor(example_dataset_ifs):
    """
    Estimate the scaling factor required to align stellar halo in IFS cube.

    Parameters
    ----------
    example_dataset_ifs : fixture
        Taken automatically from ``conftest.py``.

    Returns
    -------
    dsi : VIP Dataset
    injected_position_yx : tuple(y, x)

    """
    print_debug("estimating scaling factor...")
    dsi = copy.copy(example_dataset_ifs)
    # we chose a shallow copy, as we will not use any in-place operations
    # (like +=). Using `deepcopy` would be safer, but consume more memory.

    dsi_flux = np.ones_like(dsi.wavelengths)
    scal_fac = vip.preproc.find_scal_vector(dsi.psf, dsi.wavelengths, dsi_flux, 
                                            nfp=2, fm="stddev")

    return scal_fac

# ====== algos
def algo_medsub(ds, sc):
    return vip.medsub.median_sub(ds.cube, ds.angles, fwhm=ds.fwhm,
                                 scale_list=sc)

<commit_msg>Bug fix for SDI tests<commit_after>"""
Tests for the post-processing pipeline, using the functional API.

"""

import copy
import vip_hci as vip
from .helpers import np, parametrize, fixture


def print_debug(s, *args, **kwargs):
    print(("\033[34m" + s + "\033[0m").format(*args, **kwargs))


@fixture(scope="module")
def injected_cube_position(example_dataset_ifs):
    """
    Inject a fake companion into an example cube.

    Parameters
    ----------
    example_dataset_ifs : fixture
        Taken automatically from ``conftest.py``.

    Returns
    -------
    dsi : VIP Dataset
    injected_position_yx : tuple(y, x)

    """
    print_debug("injecting fake planet...")
    dsi = copy.copy(example_dataset_ifs)
    # we chose a shallow copy, as we will not use any in-place operations
    # (like +=). Using `deepcopy` would be safer, but consume more memory.

    dsi.inject_companions(50, rad_dists=30)

    return dsi, dsi.injections_yx[0]

@fixture(scope="module")
def estimated_scal_factor(example_dataset_ifs):
    """
    Estimate the scaling factor required to align stellar halo in IFS cube.

    Parameters
    ----------
    example_dataset_ifs : fixture
        Taken automatically from ``conftest.py``.

    Returns
    -------
    dsi : VIP Dataset
    injected_position_yx : tuple(y, x)

    """
    print_debug("estimating scaling factor...")
    dsi = copy.copy(example_dataset_ifs)
    # we chose a shallow copy, as we will not use any in-place operations
    # (like +=). Using `deepcopy` would be safer, but consume more memory.

    dsi_flux = np.ones_like(dsi.wavelengths)
    scal_fac, _ = vip.preproc.find_scal_vector(dsi.psf, dsi.wavelengths, 
                                               dsi_flux, nfp=2, fm="stddev")

    return scal_fac

# ====== algos
def algo_medsub(ds, sc):
    return vip.medsub.median_sub(ds.cube, ds.angles, fwhm=ds.fwhm,
                                 scale_list=sc)


{'fraction_non_alphanumeric': 0.12156557801969933, 'fraction_numerical': 0.007776049766718507, 'mean_word_length': 2.6857688634192933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4862548', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1214, 'n_words': 332}