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

Samncorn patch 1 #818

Merged
merged 5 commits into from
Feb 13, 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
6 changes: 4 additions & 2 deletions src/sorcha/modules/PPFootprintFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

logger = logging.getLogger(__name__)


def distToSegment(points, x0, y0, x1, y1):
"""Compute the distance from each point to the line segment defined by
the points (x0, y0) and (x1, y1). Returns the distance in the same
Expand Down Expand Up @@ -523,14 +524,15 @@ def __init__(self, path=None, detectorName="detector"):
else:
try:
default_camera_config_file = "data/LSST_detector_corners_100123.csv"
stream = pkg_resources.resource_stream(__name__, default_camera_config_file)
# stream = pkg_resources.resource_stream(__name__, default_camera_config_file)
# stream = importlib_resources.as_file( default_camera_config_file )
stream = importlib_resources.files(__name__).joinpath(default_camera_config_file)
logger.info(f"Using built-in CCD Detector file: {default_camera_config_file}")
allcornersdf = pd.read_csv(stream)
except IOError:
logger.error(f"Error loading default camera footprint, exiting ...")
sys.exit(1)


# build dictionary of detectorName:[list_of_inds]
det_to_inds = {}
for det in allcornersdf.detector.unique():
Expand Down
58 changes: 54 additions & 4 deletions tests/sorcha/test_PPFootprintFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,67 @@ def test_applyFootprint():
footprintf = Footprint(get_test_filepath("detectors_corners.csv"))
onSensor, detectorIDs = footprintf.applyFootprint(observations)

assert_equal(onSensor, [0, 1, 6, 5, 7, 8, 9, 4, 2, 3,])
assert_equal(detectorIDs, [35., 35., 60., 88., 100., 106., 114., 127., 130., 130.,])
assert_equal(
onSensor,
[
0,
1,
6,
5,
7,
8,
9,
4,
2,
3,
],
)
assert_equal(
detectorIDs,
[
35.0,
35.0,
60.0,
88.0,
100.0,
106.0,
114.0,
127.0,
130.0,
130.0,
],
)

# Setting an edge threshold to 0.0005 radians will further filter points 0, 7, 8, and 9.
onSensor, detectorIDs = footprintf.applyFootprint(
observations,
edge_thresh=(np.degrees(0.0005) * 3600), # as arcseconds
)

assert_equal(onSensor, [0, 1, 6, 8, 9, 2, 3,])
assert_equal(detectorIDs, [35., 35., 60., 106., 114., 130., 130.,])
assert_equal(
onSensor,
[
0,
1,
6,
8,
9,
2,
3,
],
)
assert_equal(
detectorIDs,
[
35.0,
35.0,
60.0,
106.0,
114.0,
130.0,
130.0,
],
)


def test_distToSegment():
Expand Down
Loading