Beispiel #1
0
def test_radec2azel():
    azapy, elapy = pm.radec2azel(ra, dec, lat, lon, t0)
    assert azapy == approx(azi, rel=0.01, abs=0.1)
    assert elapy == approx(eli, rel=0.01, abs=0.1)

    azvallado, elvallado = pm.radec2azel(ra,
                                         dec,
                                         lat,
                                         lon,
                                         t0,
                                         usevallado=True)
    assert azvallado == approx(azi, rel=1e-2)
    assert elvallado == approx(eli, rel=1e-2)
Beispiel #2
0
def test_radec2azel():
    aztest, eltest = pm.radec2azel(166.5032081149338, 55.000011165405752, 65,
                                   -148, parse('2014-04-06T08:00:00'))
    assert_allclose(aztest, 179.40287898,
                    rtol=1e-2)  #180.1 from vallado, but his is less precise
    assert_allclose(eltest, 79.92186504,
                    rtol=1e-2)  #80.0 from vallado, but  his is less precise
Beispiel #3
0
def radec2azel(scale: xarray.Dataset,
               latlon: Tuple[float, float], time: datetime=None) -> xarray.Dataset:

    if latlon is None or not isinstance(scale, xarray.Dataset):
        return None

    if time is None:
        with fits.open(scale.filename, mode='readonly') as f:
            try:
                t = f[0].header['FRAME']  # TODO this only works from Solis?
            except KeyError:
                logging.error('no time given in file or manually, cannot compute az/el')
                return None
        time = parse(t)
        logging.info('using FITS header for time')
    elif isinstance(time, datetime):
        pass
    elif isinstance(time, (float, int)):  # assume UT1_Unix
        time = datetime.utcfromtimestamp(time)
    else:  # user override of frame time
        time = parse(time)

    print('image time:', time)
# %% knowing camera location, time, and sky coordinates observed, convert to az/el for each pixel
    az, el = pymap3d.radec2azel(scale['ra'], scale['dec'], latlon[0], latlon[1], time)
# %% collect output
    scale['az'] = (('y', 'x'), az)
    scale['el'] = (('y', 'x'), el)
    scale.attrs['lat'] = latlon[0]
    scale.attrs['lon'] = latlon[1]
    scale.attrs['time'] = time

    return scale
Beispiel #4
0
def test_radec2azel():
    azapy, elapy = pm.radec2azel(ra, dec, rdlat, rdlon, t)
    assert_allclose(azapy, azi, rtol=1e-2)
    assert_allclose(elapy, eli, rtol=1e-2)

    azvallado, elvallado = vradec2azel(ra, dec, rdlat, rdlon, t)
    assert_allclose(azvallado, azi, rtol=1e-2)
    assert_allclose(elvallado, eli, rtol=1e-2)
Beispiel #5
0
def test_numpy_radec2azel(use_astropy):
    pytest.importorskip("numpy")
    azel1 = pm.radec2azel([166.503208, 166.503208], [55, 55],
                          lat,
                          lon,
                          t0,
                          use_astropy=use_astropy)
    assert azel1 == approx(azel, rel=0.01)
Beispiel #6
0
    def test_radec2azel(self):
        if numpy is None:
            logging.warning('RA DEC not tested')
            return
        azapy, elapy = pm.radec2azel(ra, dec, lat, lon, t0)
        assert_allclose(azapy, azi, rtol=1e-2)
        assert_allclose(elapy, eli, rtol=1e-2)

        azvallado, elvallado = vradec2azel(ra, dec, lat, lon, t0)
        assert_allclose(azvallado, azi, rtol=1e-2)
        assert_allclose(elvallado, eli, rtol=1e-2)
Beispiel #7
0
def main():
    p = ArgumentParser(description="RightAscension,Declination =>"
                       "Azimuth,Elevation")
    p.add_argument("ra", help="right ascension [degrees]", type=float)
    p.add_argument("dec", help="declination [degrees]", type=float)
    p.add_argument("lat",
                   help="WGS84 latitude of observer [degrees]",
                   type=float)
    p.add_argument("lon",
                   help="WGS84 latitude of observer [degrees]",
                   type=float)
    p.add_argument("time", help="UTC time of observation YYYY-mm-ddTHH:MM:SSZ")
    P = p.parse_args()

    az_deg, el_deg = radec2azel(P.ra, P.dec, P.lat, P.lon, P.time)
    print("azimuth: [deg]", az_deg)
    print("elevation [deg]:", el_deg)
Beispiel #8
0
def radec2azel(scale: xarray.Dataset, latlon: Tuple[float, float],
               time: datetime) -> xarray.Dataset:

    if pymap3d is None:
        logging.error(
            "azimuth, elevation computations require: pip install pymap3d")
        return None
    if latlon is None:
        return None
    if not isinstance(scale, xarray.Dataset):
        return None

    if time is None:
        with fits.open(scale.filename, mode="readonly") as f:
            try:
                t = f[0].header["FRAME"]  # TODO this only works from Solis?
            except KeyError:
                return None
        time = parse(t)
        logging.info("using FITS header for time")
    elif isinstance(time, datetime):
        pass
    elif isinstance(time, (float, int)):  # assume UT1_Unix
        time = datetime.utcfromtimestamp(time)
    else:  # user override of frame time
        time = parse(time)

    print("image time:", time)
    # %% knowing camera location, time, and sky coordinates observed, convert to az/el for each pixel
    # .values is to avoid silently freezing AstroPy
    az, el = pymap3d.radec2azel(scale["ra"].values, scale["dec"].values,
                                *latlon, time)
    if (el < 0).any():
        Nbelow = (el < 0).nonzero()
        logging.error(
            f"{Nbelow} points were below the horizon."
            "Currently this program assumed observer ~ ground level."
            "Please file a bug report if you need observer off of Earth surface"
        )
    # %% collect output
    scale["az"] = (("y", "x"), az)
    scale["el"] = (("y", "x"), el)
    scale.attrs["lat"] = latlon[0]
    scale.attrs["lon"] = latlon[1]
    scale.attrs["time"] = time
    return scale
Beispiel #9
0
def main():
    p = ArgumentParser(description="RightAscension,Declination =>"
                       "Azimuth,Elevation")
    p.add_argument('ra', help='right ascension [degrees]', type=float)
    p.add_argument('dec', help='declination [degrees]', type=float)
    p.add_argument('lat',
                   help='WGS84 latitude of observer [degrees]',
                   type=float)
    p.add_argument('lon',
                   help='WGS84 latitude of observer [degrees]',
                   type=float)
    p.add_argument('time', help='UTC time of observation YYYY-mm-ddTHH:MM:SSZ')
    P = p.parse_args()

    az_deg, el_deg = radec2azel(P.ra, P.dec, P.lat, P.lon, P.time)
    print('azimuth: [deg]', az_deg)
    print('elevation [deg]:', el_deg)
Beispiel #10
0
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Example Kitt Peak

./radec2azel.py 257.96295344 15.43785495 31.9583 -111.5967 2014-12-25T22:00:00MST
"""
from pymap3d import radec2azel

if __name__ == '__main__':
    from argparse import ArgumentParser
    p = ArgumentParser(
        description="convert RightAscension,Declination to Azimuth,Elevation")
    p.add_argument('ra', help='right ascension [degrees]', type=float)
    p.add_argument('dec', help='declination [degrees]', type=float)
    p.add_argument('lat',
                   help='WGS84 latitude of observer [degrees]',
                   type=float)
    p.add_argument('lon',
                   help='WGS84 latitude of observer [degrees]',
                   type=float)
    p.add_argument('time', help='UTC time of observation YYYY-mm-ddTHH:MM:SSZ')
    p = p.parse_args()

    az_deg, el_deg = radec2azel(p.ra, p.dec, p.lat, p.lon, p.time)
    print('azimuth: [deg]', az_deg)
    print('elevation [deg]:', el_deg)
Beispiel #11
0
def test_radec2azel(use_astropy):
    azel1 = pm.radec2azel(*radec, lat, lon, t0, use_astropy=use_astropy)
    assert azel1 == approx(azel, rel=0.01)
Beispiel #12
0
def test_radec2azel(usevallado):
    azel1 = pm.radec2azel(*radec, lat, lon, t0, usevallado=usevallado)
    assert azel1 == approx(azel, rel=0.01)