Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to src based repository structure #2459

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __pycache__

# ignore version cache file (generated automatically when setup.py is run)
ctapipe/_version_cache.py
ctapipe/_version.py
src/ctapipe/_version.py


# Ignore .c files by default to avoid including generated code. If you want to
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ recursive-include docs *
prune build
prune docs/_build
prune docs/api
prune ctapipe/_dev_version
prune src/ctapipe/_dev_version

global-exclude *.pyc *.o
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test:
pytest

doc:
cd docs && $(MAKE) html SPHINXOPTS="-W --keep-going -n --color -j auto"
cd docs && $(MAKE) html SPHINXOPTS="-W --keep-going -n --color"
@echo "------------------------------------------------"
@echo "Documentation is in: docs/_build/html/index.html"

Expand Down
2 changes: 2 additions & 0 deletions docs/changes/2459.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``ctapipe`` source code repository now uses the ``src/``-based layout.
This fixes the editable installation of ctapipe.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=64", "setuptools_scm[toml]>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "ctapipe/_version.py"
write_to = "src/ctapipe/_version.py"

[tool.black]
line-length = 88
Expand All @@ -25,7 +25,7 @@ exclude = '''

[tool.pytest.ini_options]
minversion = "7"
testpaths = ["ctapipe"]
testpaths = ["src"]
log_cli_level = "INFO"
xfail_strict = true

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ classifiers =

[options]
packages = find:
package_dir =
=src
python_requires = >=3.9
zip_safe = False
install_requires=
Expand Down Expand Up @@ -79,6 +81,7 @@ all =
%(dev)s

[options.packages.find]
where = src
exclude =
ctapipe._dev_version

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
try:
from setuptools_scm import get_version

version = get_version(root="../..", relative_to=__file__)
version = get_version(root="../../..", relative_to=__file__)
except Exception as e:
raise ImportError(f"setuptools_scm broken or not installed: {e}")
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""
from abc import abstractmethod
from enum import IntEnum

import numpy as np

from ctapipe.core import Component, traits

__all__ = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np

from ctapipe.calib.camera.gainselection import (
ManualGainSelector,
ThresholdGainSelector,
GainChannel,
GainSelector,
ManualGainSelector,
ThresholdGainSelector,
)


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import numpy as np
import astropy.units as u
import numpy as np
from astropy.coordinates import (
AffineTransform,
AltAz,
Attribute,
BaseCoordinateFrame,
CartesianRepresentation,
CoordinateAttribute,
QuantityAttribute,
Attribute,
TimeAttribute,
EarthLocationAttribute,
FunctionTransform,
frame_transform_graph,
CartesianRepresentation,
QuantityAttribute,
TimeAttribute,
UnitSphericalRepresentation,
AltAz,
AffineTransform,
frame_transform_graph,
)

from .telescope_frame import TelescopeFrame
from .representation import PlanarRepresentation

from .telescope_frame import TelescopeFrame

__all__ = ["CameraFrame"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This module defines any reference systems which may be needed in addition
"""
from astropy.coordinates import BaseRepresentation, CartesianRepresentation
import astropy.units as u
from collections import OrderedDict
from numpy import broadcast_arrays

import astropy.units as u
from astropy.coordinates import BaseRepresentation, CartesianRepresentation
from numpy import broadcast_arrays

__all__ = ["PlanarRepresentation"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Tests for the conversion between camera coordinate frames
"""
from astropy.coordinates import SkyCoord
import astropy.units as u
from astropy.coordinates import SkyCoord


def test_conversion():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from astropy.coordinates import SkyCoord, AltAz
import astropy.units as u
from astropy.coordinates import AltAz, SkyCoord
from pytest import approx


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from astropy.coordinates import SkyCoord, AltAz
from pytest import approx
import astropy.units as u
from astropy.coordinates import AltAz, SkyCoord
from pytest import approx


def test_roundtrip_camera_horizon():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from astropy.coordinates import SkyCoord, AltAz
import astropy.units as u
from astropy.coordinates import AltAz, SkyCoord
from pytest import approx


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion ctapipe/core/logging.py → src/ctapipe/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
from collections.abc import Mapping


DEFAULT_LOGGING_FORMAT = (
"%(asctime)s %(levelname)s [%(name)s] (%(module)s.%(funcName)s): %(message)s"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion ctapipe/core/support.py → src/ctapipe/core/support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Module implementing supporting classes needed in ctapipe.core"""

__all__ = [
"Singleton",
]


class Singleton(type):
"""" metaclass for singleton pattern """
"""metaclass for singleton pattern"""

instance = None

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions ctapipe/fitting.py → src/ctapipe/fitting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from numba import njit
import numpy as np

from numba import njit

EPS = 2 * np.finfo(np.float64).eps

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import numpy as np
import astropy.units as u
import numpy as np

from ..containers import (
CameraHillasParametersContainer,
ConcentrationContainer,
HillasParametersContainer,
CameraHillasParametersContainer,
)
from .hillas import camera_to_shower_coordinates
from ..instrument import CameraGeometry
from ..utils.quantities import all_to_value
from .hillas import camera_to_shower_coordinates

__all__ = ["concentration_parameters"]

Expand Down Expand Up @@ -53,15 +53,15 @@ def concentration_parameters(geom: CameraGeometry, image, hillas_parameters):
delta_y = pix_y - y

# take pixels within one pixel diameter from the cog
mask_cog = (delta_x ** 2 + delta_y ** 2) < pixel_width ** 2
mask_cog = (delta_x**2 + delta_y**2) < pixel_width**2
conc_cog = np.sum(image[mask_cog]) / h.intensity

if hillas_parameters.width.value != 0:
# get all pixels inside the hillas ellipse
longi, trans = camera_to_shower_coordinates(
pix_x, pix_y, x, y, h.psi.to_value(u.rad)
)
mask_core = (longi ** 2 / length ** 2) + (trans ** 2 / width ** 2) <= 1.0
mask_core = (longi**2 / length**2) + (trans**2 / width**2) <= 1.0
conc_core = image[mask_core].sum() / h.intensity
else:
conc_core = 0.0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from iminuit import Minuit
from astropy.units import Quantity
from iminuit import Minuit

from ctapipe.utils.quantities import all_to_value

Expand Down Expand Up @@ -35,8 +35,8 @@ def kundu_chaudhuri_circle_fit(x, y, weights):
b1 = np.sum(weights * (x - mean_x) * y)
b2 = np.sum(weights * (y - mean_y) * y)

c1 = 0.5 * np.sum(weights * (x - mean_x) * (x ** 2 + y ** 2))
c2 = 0.5 * np.sum(weights * (y - mean_y) * (x ** 2 + y ** 2))
c1 = 0.5 * np.sum(weights * (x - mean_x) * (x**2 + y**2))
c2 = 0.5 * np.sum(weights * (y - mean_y) * (x**2 + y**2))

center_x = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1)
center_y = (a2 * c1 - a1 * c2) / (a2 * b1 - a1 * b2)
Expand Down Expand Up @@ -109,7 +109,7 @@ def taubin_loss_function(xc, yc, r):
"""taubin fit formula
reference : Barcelona_Muons_TPA_final.pdf (slide 6)
"""
upper_term = (((x - xc) ** 2 + (y - yc) ** 2 - r ** 2) ** 2).sum()
upper_term = (((x - xc) ** 2 + (y - yc) ** 2 - r**2) ** 2).sum()

lower_term = (((x - xc) ** 2 + (y - yc) ** 2)).sum()

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import math

import astropy.units as u
import numpy as np
import math
from ctapipe.image.muon.features import ring_containment
from ctapipe.image.muon.features import ring_completeness

from ctapipe.image.muon.features import ring_completeness, ring_containment


def test_ring_containment():
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from ..containers import StatisticsContainer


__all__ = ["descriptive_statistics", "skewness", "kurtosis"]


Expand Down Expand Up @@ -82,7 +81,7 @@ def kurtosis(data, mean=None, std=None, fisher=True):
def descriptive_statistics(
values, container_class=StatisticsContainer
) -> StatisticsContainer:
""" compute intensity statistics of an image """
"""compute intensity statistics of an image"""
mean = values.mean()
std = values.std()
return container_class(
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 7 additions & 8 deletions ctapipe/image/timing.py → src/ctapipe/image/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
Image timing-based shower image parametrization.
"""

import numpy as np
import astropy.units as u
import numpy as np
from numba import njit

from ..containers import (
CameraTimingParametersContainer,
TimingParametersContainer,
CameraHillasParametersContainer,
CameraTimingParametersContainer,
HillasParametersContainer,
TimingParametersContainer,
)
from .hillas import camera_to_shower_coordinates
from ..utils.quantities import all_to_value
from ..fitting import lts_linear_regression

from numba import njit

from ..utils.quantities import all_to_value
from .hillas import camera_to_shower_coordinates

__all__ = ["timing_parameters"]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import astropy.units as u
import numpy as np
import pytest
from numpy.testing import assert_allclose
import astropy.units as u

from ctapipe.image.toymodel import Gaussian
import pytest


def create_mock_image(geom, psi=25 * u.deg):
"""
creates a mock image, which parameters are adapted to the camera size
"""

camera_r = np.max(np.sqrt(geom.pix_x ** 2 + geom.pix_y ** 2))
camera_r = np.max(np.sqrt(geom.pix_x**2 + geom.pix_y**2))
model = Gaussian(
x=0.3 * camera_r,
y=0 * u.m,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from ctapipe.io import EventSource, DataWriter

from ctapipe.io import DataWriter, EventSource


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def test_available_sources():
from ctapipe.io.eventsource import EventSource
from ctapipe.core import non_abstract_children
from ctapipe.io.eventsource import EventSource

# make this before the explicit imports to make sure
# all classes are avaialble even if not explicitly imported
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Tests for the write_table function"""
from astropy.time import Time
from astropy.table import Table
import astropy.units as u
import numpy as np
import pytest
from astropy.table import Table
from astropy.time import Time


def test_write_table(tmp_path):
"""Test write_table"""
from ctapipe.io.astropy_helpers import write_table, read_table
from ctapipe.io.astropy_helpers import read_table, write_table

table = Table(
{
Expand Down
File renamed without changes.
File renamed without changes.
Loading