<commit_before>
import pytest

import numpy as np
import numpy.testing as npt
import astropy.units as u
from astropy.wcs import WCS
import warnings

from ..filament import Filament2D, FilamentNDBase


def test_Filament2D():

    pixels = (np.array([0, 0, 0]), np.array([0, 1, 2]))

    image = np.zeros((1, 3))
    image[0, :] = 2.

    fil = Filament2D(pixels)

    assert all([(out == inp).all() for out, inp in
                zip(fil.pixel_coords, pixels)])
    assert fil.pixel_extents == [(0, 0), (0, 2)]

    assert fil.position() == [0 * u.pix, 1 * u.pix]

    # Should return pixels again because no WCS info is given
    with warnings.catch_warnings(record=True) as w:
        assert fil.position(world_coord=True) == [0 * u.pix, 1 * u.pix]

    assert len(w) == 1
    assert w[0].category == UserWarning
    assert str(w[0].message) == ("No WCS information given. Returning pixel"
                                 " position.")

    mask_expect = np.zeros((1, 3), dtype=bool)
    mask_expect[pixels] = True

    mask = fil.skeleton()

    assert (mask == mask_expect).all()

    # Test out the padding
    pad = 1
    mask_expect = np.zeros((1 + 2 * pad, 3 + 2 * pad), dtype=bool)
    mask_expect[pixels[0] + pad, pixels[1] + pad] = True

    mask = fil.skeleton(pad_size=pad)

    assert (mask == mask_expect).all()

    # Long path mask should fail without skeleton_analysis
    with pytest.raises(AttributeError):
        fil.skeleton(out_type='longpath')

    # Now run the skeleton analysis
    fil.skeleton_analysis(image)

    mask = fil.skeleton(out_type='longpath', pad_size=pad)
    assert (mask == mask_expect).all()

    # Check the length
    assert fil.length().value == 2.0
    assert fil.length().unit == u.pix

    # Angular and physical conversion should fail b/c no WCS or distance is
    # given
    with pytest.raises(AttributeError):
        fil.length(unit=u.deg)

    with pytest.raises(AttributeError):
        fil.length(unit=u.pc)<commit_msg>Add tests for the end and intersection points<commit_after>
import pytest

import numpy as np
import numpy.testing as npt
import astropy.units as u
from astropy.wcs import WCS
import warnings

from ..filament import Filament2D, FilamentNDBase


def test_Filament2D():

    pixels = (np.array([0, 0, 0]), np.array([0, 1, 2]))

    image = np.zeros((1, 3))
    image[0, :] = 2.

    fil = Filament2D(pixels)

    assert all([(out == inp).all() for out, inp in
                zip(fil.pixel_coords, pixels)])
    assert fil.pixel_extents == [(0, 0), (0, 2)]

    assert fil.position() == [0 * u.pix, 1 * u.pix]

    # Should return pixels again because no WCS info is given
    with warnings.catch_warnings(record=True) as w:
        assert fil.position(world_coord=True) == [0 * u.pix, 1 * u.pix]

    assert len(w) == 1
    assert w[0].category == UserWarning
    assert str(w[0].message) == ("No WCS information given. Returning pixel"
                                 " position.")

    mask_expect = np.zeros((1, 3), dtype=bool)
    mask_expect[pixels] = True

    mask = fil.skeleton()

    assert (mask == mask_expect).all()

    # Test out the padding
    pad = 1
    mask_expect = np.zeros((1 + 2 * pad, 3 + 2 * pad), dtype=bool)
    mask_expect[pixels[0] + pad, pixels[1] + pad] = True

    mask = fil.skeleton(pad_size=pad)

    assert (mask == mask_expect).all()

    # Long path mask should fail without skeleton_analysis
    with pytest.raises(AttributeError):
        fil.skeleton(out_type='longpath')

    # Now run the skeleton analysis
    fil.skeleton_analysis(image)

    mask = fil.skeleton(out_type='longpath', pad_size=pad)
    assert (mask == mask_expect).all()

    # Check the length
    assert fil.length().value == 2.0
    assert fil.length().unit == u.pix

    # Check the intersection and end points
    assert len(fil.intersec_pts) == 1
    assert len(fil.intersec_pts[0]) == 0
    assert fil.intersec_pts == [[]]
    assert len(fil.end_pts) == 1
    assert fil.end_pts[0][0] == (0 + pad, 0 + pad)
    assert fil.end_pts[0][1] == (0 + pad, 2 + pad)

    # Angular and physical conversion should fail b/c no WCS or distance is
    # given
    with pytest.raises(AttributeError):
        fil.length(unit=u.deg)

    with pytest.raises(AttributeError):
        fil.length(unit=u.pc)
{'fraction_non_alphanumeric': 0.13086074177746676, 'fraction_numerical': 0.019127595054816888, 'mean_word_length': 2.8422939068100357, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2213915', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1419, 'n_words': 401}