Skip to content

Commit

Permalink
Search for existing skyregions with positions and radii within 10 arc…
Browse files Browse the repository at this point in the history
…sec of image.
  • Loading branch information
mauch committed Oct 4, 2024
1 parent dc4bf6d commit 5bf72be
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions vast_pipeline/pipeline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,38 @@
dask.config.set({"multiprocessing.context": "fork"})


def get_create_skyreg(image: Image) -> SkyRegion:
def get_create_skyreg(image: Image, radius: float = 10.) -> SkyRegion:
'''
This creates a Sky Region object in Django ORM given the related
image object.
This creates a SkyRegion object in Django ORM given the related
image object. If a SkyRegion already exists and has an image radius
within `radius` arcsec of the input image then use that SkyRegion.
Args:
image: The image Django ORM object.
radius: Search radius (in arcsec) for matching to existing SkyRegion
Returns:
The sky region Django ORM object.
'''
# In the calculations below, it is assumed the image has square
# NOTE: In the calculations below, it is assumed the image has square
# pixels (this pipeline has been designed for ASKAP images, so it
# should always be square). It will likely give wrong results if not
skyregions = SkyRegion.objects.filter(
centre_ra=image.ra,
centre_dec=image.dec,
xtr_radius=image.fov_bmin

# Get SkyRegions and image radii areas within `radius` arcsec
radius_deg = radius/3600.
skyregions = SkyRegion.objects.cone_search(
ra=image.ra,
dec=image.dec,
radius_deg=radius_deg
).filter(
xtr_radius__range=(
image.fov_bmin - radius_deg/2.,
image.fov_bmin + radius_deg/2.
)
)
if skyregions:
skyr = skyregions.get()
# Get the closest in case of multiple matches.
skyr = skyregions[0]
logger.info('Found sky region %s', skyr)
else:
x, y, z = eq_to_cart(image.ra, image.dec)
Expand Down

0 comments on commit 5bf72be

Please sign in to comment.