Skip to content

Commit

Permalink
renamed fov to radius
Browse files Browse the repository at this point in the history
  • Loading branch information
cchris28 committed Jul 28, 2023
1 parent d7dea40 commit 7fd20ba
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/kbmod/regionsearch/abstractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, **kwargs):

@abstractmethod
def observations_to_indices(
self, pointing: SkyCoord, time: Time, fov: Angle, location: EarthLocation
self, pointing: SkyCoord, time: Time, radius: Angle, location: EarthLocation
) -> numpy.ndarray:
"""Returns a numpy.ndarray of cluster indices for each of the observations in the arguments.
The interpretation of the cluster indices is up to the implementation. The indices should
Expand All @@ -106,7 +106,7 @@ def observations_to_indices(
The pointing of each observation.
time : astropy.time.Time
The time of each observation.
fov : astropy.coordinates.Angle
radius : astropy.coordinates.Angle
The field of view of each observation. The field of view is the radius of the
circular region centered on the pointing and contains all the data in the observation.
location : astropy.coordinates.EarthLocation
Expand Down
22 changes: 11 additions & 11 deletions src/kbmod/regionsearch/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class ObservationList(Backend):
The time of the observations.
observation_location : coord.EarthLocation
The location of the observations. This should be the location of the telescope.
observation_fov : coord.Angle
observation_radius : coord.Angle
The field of view of the observations. This should enclose any imagery that is associated with the observation.
observation_identifier : np.ndarray
The observation identifier. This is an array of values that uniquely identifies each observation.
Notes
-----
The attributes observation_ra, observation_dec, observation_time, observation_location and observation_fov store lists of values comprising each observation.
The attributes observation_ra, observation_dec, observation_time, observation_location and observation_radius store lists of values comprising each observation.
They must all have the same shape.
"""

observation_ra: coord.Angle
observation_dec: coord.Angle
observation_time: time.Time
observation_location: coord.EarthLocation
observation_fov: coord.Angle
observation_radius: coord.Angle
observation_identifier: np.ndarray

def __init__(
Expand All @@ -51,7 +51,7 @@ def __init__(
observation_dec: coord.Angle,
observation_time: time.Time,
observation_location: coord.EarthLocation,
observation_fov: coord.Angle,
observation_radius: coord.Angle,
observation_identifier: np.ndarray,
**kwargs
) -> None:
Expand All @@ -61,29 +61,29 @@ def __init__(
self.observation_dec = observation_dec
self.observation_time = observation_time
self.observation_location = observation_location
self.observation_fov = observation_fov
self.observation_radius = observation_radius
self.observation_identifier = observation_identifier
if (
observation_dec.shape != observation_ra.shape
or observation_time.shape != observation_ra.shape
or observation_location.shape != observation_ra.shape
or observation_fov.shape != observation_ra.shape
or observation_radius.shape != observation_ra.shape
or observation_identifier.shape != observation_ra.shape
):
raise ValueError(
"observation_ra, observation_dec, observation_time, observation_location, observation_fov and observation_identifier must have the same shape"
"observation_ra, observation_dec, observation_time, observation_location, observation_radius and observation_identifier must have the same shape"
)

def region_search(self, filter: Filter) -> np.ndarray:
"""
Returns a numpy.ndarray of observation identifiers that match the filter.
The filter must have attributes search_ra, search_dec, search_time, search_location, and search_fov.
The filter must have attributes search_ra, search_dec, search_time, search_location, and search_radius.
Parameters
----------
filter : Filter
The filter to use for the search.
The filter must have attributes search_ra, search_dec, search_time, search_location, and search_fov.
The filter must have attributes search_ra, search_dec, search_time, search_location, and search_radius.
Returns
-------
Expand All @@ -94,10 +94,10 @@ def region_search(self, filter: Filter) -> np.ndarray:
if not hasattr(self, "observations_to_indices"):
raise NotImplementedError("region_search requires an implementation of observations_to_indices")
pointing = coord.SkyCoord(filter.search_ra, filter.search_dec)
matching_index = self.observations_to_indices(pointing, None, filter.search_fov, None) # type: ignore
matching_index = self.observations_to_indices(pointing, None, filter.search_radius, None) # type: ignore
pointing = coord.SkyCoord(self.observation_ra, self.observation_dec)
self.observation_index = self.observations_to_indices( # type: ignore
pointing, self.observation_time, self.observation_fov, self.observation_location
pointing, self.observation_time, self.observation_radius, self.observation_location
)
index_list = np.nonzero(self.observation_index == matching_index)[0]
matching_observation_identifier = self.observation_identifier[index_list]
Expand Down
18 changes: 9 additions & 9 deletions src/kbmod/regionsearch/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
search_ra: coordinates.Longitude,
search_dec: coordinates.Latitude,
search_distance: coordinates.Distance,
search_fov: coordinates.Angle,
search_radius: coordinates.Angle,
is_in_index: int,
is_out_index: int,
**kwargs
Expand All @@ -45,7 +45,7 @@ def __init__(
The declination of the center of the sphere.
search_distance : astropy.coordinates.Distance
The distance from the barycenter to the center of the sphere.
search_fov : astropy.coordinates.Angle
search_radius : astropy.coordinates.Angle
The angle subtended by the sphere at the barycenter.
is_in_index : int
The index to assign to observations that intersect the sphere.
Expand All @@ -59,37 +59,37 @@ def __init__(
"""
super().__init__(**kwargs)
self.obssky = coordinates.SkyCoord(search_ra, search_dec, distance=search_distance, frame="icrs")
self.fov = search_fov
self.radius = search_radius
self.is_in_index = is_in_index
self.is_out_index = is_out_index

def observations_to_indices(
self, pointing: SkyCoord, time: Time, fov: coordinates.Angle, location: EarthLocation
self, pointing: SkyCoord, time: Time, radius: coordinates.Angle, location: EarthLocation
) -> numpy.ndarray:
"""
Returns a numpy array of indices for each observation specified by pointing, time, fov and location.
Returns a numpy array of indices for each observation specified by pointing, time, radius and location.
Parameters
----------
pointing : astropy.coordinates.SkyCoord
The pointing of the observations.
time : astropy.time.Time
The time of the observations.
fov : astropy.coordinates.Angle
radius : astropy.coordinates.Angle
The field of view of the observations.
location : astropy.coordinates.EarthLocation
The location of the observations. This should be the location of the telescope.
Returns
-------
numpy.ndarray
A numpy array of indices for each observation specified by pointing, time, fov and location.
A numpy array of indices for each observation specified by pointing, time, radius and location.
An index of is_in_index is assigned to observations with a cone that intersect the sphere.
An index of is_out_index is assigned to observations with a cone that do not intersect the sphere.
Notes
-----
The observation cone has an apex at the location of the telescope at the time of the observation with an axis that points in the direction of the pointing and an angle of fov.
The observation cone has an apex at the location of the telescope at the time of the observation with an axis that points in the direction of the pointing and an angle of radius.
"""
if time is None:
separation = self.obssky.separation(pointing)
Expand All @@ -102,5 +102,5 @@ def observations_to_indices(
# the next line is slow
observer_to_target = self.obssky.transform_to(obs_pos_itrs).gcrs
separation = observer_to_target.separation(pointing)
indices = numpy.where(separation < (self.fov + fov) * 0.5, self.is_in_index, self.is_out_index)
indices = numpy.where(separation < (self.radius + radius) * 0.5, self.is_in_index, self.is_out_index)
return indices
12 changes: 6 additions & 6 deletions src/kbmod/regionsearch/region_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class Filter:
search_ra: Angle = None
search_dec: Angle = None
search_distance: Distance = None
search_fov: Angle = None
search_radius: Angle = None

def __init__(
self,
search_ra: Angle = None,
search_dec: Angle = None,
search_distance: Distance = None,
search_fov: Angle = None,
search_radius: Angle = None,
):
self.with_ra(search_ra)
self.with_dec(search_dec)
self.with_distance(search_distance)
self.with_fov(search_fov)
self.with_radius(search_radius)

def __repr__(self):
return f"Filter(ra={self.search_ra}, dec={self.search_dec}, search_distance={self.search_distance})"
Expand All @@ -49,7 +49,7 @@ def with_distance(self, search_distance: Distance):
self.search_distance = Distance(search_distance, unit=u.au)
return self

def with_fov(self, search_fov: Angle):
if search_fov is not None:
self.search_fov = Angle(search_fov, unit=u.deg)
def with_radius(self, search_radius: Angle):
if search_radius is not None:
self.search_radius = Angle(search_radius, unit=u.deg)
return self
27 changes: 15 additions & 12 deletions tests/regionsearch/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def test_observationlist_init():
dec = data.observation_pointing.dec
time = data.observation_time
location = data.observation_geolocation
fov = np.ones([data.rowcnt]) * Angle(1, "deg")
radius = np.ones([data.rowcnt]) * Angle(1, "deg")
observation_identifier = data.cluster_id
b = backend.ObservationList(ra, dec, time, location, fov, observation_identifier)
b = backend.ObservationList(ra, dec, time, location, radius, observation_identifier)
assert all(b.observation_ra == ra)
assert all(b.observation_dec == dec)
assert all(b.observation_time == time)
assert all(b.observation_location == location)
assert all(b.observation_fov == fov)
assert all(b.observation_radius == radius)
assert all(b.observation_identifier == observation_identifier)


Expand All @@ -60,10 +60,10 @@ def test_observationlist_consistency():
dec = data.observation_pointing.dec
time = data.observation_time
location = data.observation_geolocation
fov = Angle(1, "deg")
radius = Angle(1, "deg")
observation_identifier = data.cluster_id
with pytest.raises(ValueError):
backend.ObservationList(ra, dec, time, location, fov, observation_identifier)
backend.ObservationList(ra, dec, time, location, radius, observation_identifier)


def test_observationlist_missing_observation_to_indices():
Expand All @@ -74,9 +74,9 @@ def test_observationlist_missing_observation_to_indices():
dec = data.observation_pointing.dec
time = data.observation_time
location = data.observation_geolocation
fov = np.ones([data.rowcnt]) * Angle(1, "deg")
radius = np.ones([data.rowcnt]) * Angle(1, "deg")
observation_identifier = data.cluster_id
b = backend.ObservationList(ra, dec, time, location, fov, observation_identifier)
b = backend.ObservationList(ra, dec, time, location, radius, observation_identifier)
with pytest.raises(NotImplementedError):
b.region_search(Filter())
assert (
Expand All @@ -100,31 +100,34 @@ def __init__(self, **kwargs) -> None:
dec = data.observation_pointing.dec
time = data.observation_time
location = data.observation_geolocation
fov = np.ones([data.rowcnt]) * Angle(2, "deg")
radius = np.ones([data.rowcnt]) * Angle(2, "deg")
observation_identifier = np.array([f"file:epyc/observations/{i:04d}" for i in range(data.rowcnt)])
clusteri = 0
search_ra = (data.clusters[clusteri][0]) * u.deg
search_dec = (data.clusters[clusteri][1]) * u.deg
search_distance = data.clusterdistances[clusteri] * u.au
search_fov = Angle(4.0, "deg")
search_radius = Angle(4.0, "deg")
regionsearch = TestRegionSearchList(
observation_ra=ra,
observation_dec=dec,
observation_time=time,
observation_location=location,
observation_fov=fov,
observation_radius=radius,
observation_identifier=observation_identifier,
search_ra=search_ra,
search_dec=search_dec,
search_distance=search_distance,
search_fov=search_fov,
search_radius=search_radius,
is_in_index=clusteri,
is_out_index=~clusteri,
)
assert regionsearch is not None
searchresults = regionsearch.region_search(
Filter(
search_ra=search_ra, search_dec=search_dec, search_distance=search_distance, search_fov=search_fov
search_ra=search_ra,
search_dec=search_dec,
search_distance=search_distance,
search_radius=search_radius,
)
)
assert searchresults is not None
Expand Down
6 changes: 3 additions & 3 deletions tests/regionsearch/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test the `Filter` class for region search"""
from astropy import units as u
from astropy import units as u # type: ignore

from kbmod.regionsearch.region_search import Filter

Expand All @@ -26,7 +26,7 @@ def test_filter_unitargs() -> None:
assert output.search_ra == 42 * u.deg
assert output.search_dec == -28 * u.deg
assert output.search_distance == 30 * u.au
assert output.search_fov == 1 * u.deg
assert output.search_radius == 1 * u.deg


def test_filter_none() -> None:
Expand All @@ -35,7 +35,7 @@ def test_filter_none() -> None:
assert output.search_ra is None
assert output.search_dec is None
assert output.search_distance is None
assert output.search_fov is None
assert output.search_radius is None


def test_filter_literate() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/regionsearch/test_indexer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for indexer classes."""

import astropy.units as u
import astropy.units as u # type: ignore
import numpy

from kbmod.regionsearch.indexers import PartitionIndexer
Expand All @@ -15,15 +15,15 @@ def test_partition_indexer():
search_ra=(data.clusters[clusteri][0]) * u.deg,
search_dec=(data.clusters[clusteri][1]) * u.deg,
search_distance=data.clusterdistances[clusteri] * u.au,
search_fov=2.0 * u.deg,
search_radius=2.0 * u.deg,
is_in_index=clusteri,
is_out_index=~clusteri,
)
assert indexer is not None
indices = indexer.observations_to_indices(
pointing=data.observation_pointing,
time=data.observation_time,
fov=2.0 * u.deg,
radius=2.0 * u.deg,
location=data.observation_geolocation,
)
assert indices is not None
Expand Down

0 comments on commit 7fd20ba

Please sign in to comment.