Skip to content

Commit

Permalink
Prevent astropy downloading data in container
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 20, 2023
1 parent 8b16099 commit 4268b1f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/lvmguider/etc/lvm.sci.guider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pid:
max_correction: 3600
guide_tolerance: 3

site:
lon: -70.70166667
lat: -29.00333333
height: 2282.0

actor:
name: lvm.sci.guider
host: 10.8.38.21
Expand Down
5 changes: 5 additions & 0 deletions src/lvmguider/etc/lvm.skye.guider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pid:
max_correction: 3600
guide_tolerance: 3

site:
lon: -70.70166667
lat: -29.00333333
height: 2282.0

actor:
name: lvm.skye.guider
host: 10.8.38.21
Expand Down
5 changes: 5 additions & 0 deletions src/lvmguider/etc/lvm.skyw.guider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pid:
max_correction: 3600
guide_tolerance: 3

site:
lon: -70.70166667
lat: -29.00333333
height: 2282.0

actor:
name: lvm.skyw.guider
host: 10.8.38.21
Expand Down
5 changes: 5 additions & 0 deletions src/lvmguider/etc/lvm.spec.guider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pid:
max_correction: 7200
guide_tolerance: 3

site:
lon: -70.70166667
lat: -29.00333333
height: 2282.0

actor:
name: lvm.spec.guider
host: 10.8.38.21
Expand Down
19 changes: 17 additions & 2 deletions src/lvmguider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy
import pandas
from astropy.coordinates import EarthLocation
from astropy.io import fits
from astropy.table import Table
from astropy.wcs import WCS
Expand Down Expand Up @@ -98,6 +99,8 @@ def __init__(
self.reference_sources: pandas.DataFrame | None = None
self.reference_wcs: WCS | None = None

self.site = EarthLocation(**self.config["site"])

def set_reference_frames(
self,
frameno: int | None = None,
Expand Down Expand Up @@ -305,7 +308,13 @@ async def guide_one(
fra, fdec = self.field_centre

# Calculate offset in motor axes.
saz_diff_d, sel_diff_d = delta_radec2mot_axis(fra, fdec, ra_p, dec_p)
saz_diff_d, sel_diff_d = delta_radec2mot_axis(
fra,
fdec,
ra_p,
dec_p,
site=self.site,
)
offset_motax = (saz_diff_d, sel_diff_d)

self.command.info(
Expand Down Expand Up @@ -517,7 +526,13 @@ def calculate_telescope_offset(
dec_arcsec = numpy.round(dec_off * 3600, 3)
sep_arcsec = numpy.round(sep * 3600, 3)

saz_diff_d, sel_diff_d = delta_radec2mot_axis(fra, fdec, pra, pdec)
saz_diff_d, sel_diff_d = delta_radec2mot_axis(
fra,
fdec,
pra,
pdec,
site=self.site,
)

return ((ra_arcsec, dec_arcsec), (saz_diff_d, sel_diff_d), sep_arcsec)

Expand Down
41 changes: 34 additions & 7 deletions src/lvmguider/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from astropy.coordinates import EarthLocation, SkyCoord
from astropy.io import fits
from astropy.time import Time
from astropy.utils.iers import conf
from astropy.wcs import WCS
from astropy.wcs.utils import fit_wcs_from_points, pixel_to_skycoord
from scipy.spatial import KDTree
Expand All @@ -26,6 +27,11 @@
from lvmguider.tools import get_proc_path


# Prevent astropy from downloading data.
conf.auto_download = False
conf.iers_degraded_accuracy = "ignore"


# Middle of an AG frame or full frame
XZ_FULL_FRAME = (2500.0, 1000.0)
XZ_AG_FRAME = (800.0, 550.0)
Expand Down Expand Up @@ -300,7 +306,7 @@ def solve_from_files(
return solution, locs


def radec2azel(raD, decD, lstD):
def radec2azel(raD, decD, lstD, site: EarthLocation | None = None):
"""Returns the Azimuth and Elevation for the supplied RA, Dec, and sidereal time.
From Tom Herbst and Florian Briegel.
Expand All @@ -319,7 +325,14 @@ def radec2azel(raD, decD, lstD):
"""

site = EarthLocation.of_site("Las Campanas Observatory")
if site is None:
site = EarthLocation.from_geodetic(
lon=-70.70166667,
lat=-29.00333333,
height=2282.0,
)

assert isinstance(site, EarthLocation)

lat_r = numpy.radians(site.lat.deg)

Expand Down Expand Up @@ -383,19 +396,33 @@ def azel2sazsel(azD, elD):
return numpy.degrees(SAz), numpy.degrees(SEl) # Return values in degrees


def delta_radec2mot_axis(ra_ref, dec_ref, ra_new, dec_new):
def delta_radec2mot_axis(
ra_ref,
dec_ref,
ra_new,
dec_new,
site: EarthLocation | None = None,
):
"""RA/Dec offset to motor axes.
From Tom Herbst and Florian Briegel.
"""

observing_location = EarthLocation.of_site("Las Campanas Observatory")
observing_time = Time(datetime.utcnow(), scale="utc", location=observing_location)
if site is None:
site = EarthLocation.from_geodetic(
lon=-70.70166667,
lat=-29.00333333,
height=2282.0,
)

assert isinstance(site, EarthLocation)

observing_time = Time(datetime.utcnow(), scale="utc", location=site)
lst = observing_time.sidereal_time("mean")

ref_az_d, ref_el_d = radec2azel(ra_ref, dec_ref, lst.deg)
new_az_d, new_el_d = radec2azel(ra_new, dec_new, lst.deg)
ref_az_d, ref_el_d = radec2azel(ra_ref, dec_ref, lst.deg, site=site)
new_az_d, new_el_d = radec2azel(ra_new, dec_new, lst.deg, site=site)

ref_saz_d, ref_sel_d = azel2sazsel(ref_az_d, ref_el_d)
new_saz_d, new_sel_d = azel2sazsel(new_az_d, new_el_d)
Expand Down

0 comments on commit 4268b1f

Please sign in to comment.