Exemplo n.º 1
0
def galactic_Sun_north_directions( recv_time, user_longlatdist=geographic_position):
  user_longlatdist = np.array(user_longlatdist)#46.07983746062874, 26.232615661106784, 659.5100082775696
  with load.open(hipparcos.URL) as f:
    df = hipparcos.load_dataframe(f)

  planets = load('de421.bsp')
  earth = planets['earth']
  user_position = earth + Topos('{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) #user_longlatdist      user_longlatdist[0],user_longlatdist[1]
  terrestrial_time = format_time(recv_time)
  ts = load.timescale()
  t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2], terrestrial_time[3], terrestrial_time[4], terrestrial_time[5])
  
  sun = planets['sun']
  astrometric_sun = user_position.at(t).observe(sun)
  alt_sun, az_sun, distance_sun = astrometric_sun.apparent().altaz()#astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
  print('Location: ', '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1]))
  print('Sun (alt/az):   ',alt_sun, az_sun)
  sun_position = pm.aer2ecef( az_sun.degrees, alt_sun.degrees, distance_sun.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2])
  
  # Északi Galaktikus Pólus (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0) 
  coma_berenices = Star(ra_hours=(12, 51, 25.2), dec_degrees=(27, 7, 48.0))
  astrometric_berenice = user_position.at(t).observe(coma_berenices)
  alt_b, az_b, distance_b = astrometric_berenice.apparent().altaz()
  print('Coma Berenice (alt/az):   ',alt_b, az_b)
  berenice_position = pm.aer2ecef( az_b.degrees, alt_b.degrees, distance_b.m, user_longlatdist[0], user_longlatdist[1], user_longlatdist[2])
  
  stars_pos=[sun_position, berenice_position]
  return stars_pos
Exemplo n.º 2
0
 def _stars(self) -> DataFrame:
     logging.info("Loading Hipparcos data")
     with self.load.open(hipparcos.URL) as f:
         df = hipparcos.load_dataframe(f)
         # Filter out the ones with no reliable position
         df = df[df["ra_degrees"].notnull()]
         return df
Exemplo n.º 3
0
def get_star_position( recv_time, star_name, star_name2, user_longlatdist=geographic_position):
  # if not star_name:  
  # 	star_name = 57632             #Denebola
  # if not star_name2: 
  #   star_name2 = 109074         #Sadalmelik
  
  user_longlatdist = np.array(user_longlatdist)#46.07983746062874, 26.232615661106784, 659.5100082775696
  with load.open(hipparcos.URL) as f:
    df = hipparcos.load_dataframe(f)

  planets = load('de421.bsp')
  earth = planets['earth']
  user_position = earth + Topos('{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])) #user_longlatdist      user_longlatdist[0],user_longlatdist[1]
  terrestrial_time = format_time(recv_time)
  ts = load.timescale()
  t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2], terrestrial_time[3], terrestrial_time[4], terrestrial_time[5])
  
  denebola = Star.from_dataframe(df.loc[star_name])
  astrometric_denebola = user_position.at(t).observe(denebola)
  alt_d, az_d, distance_d = astrometric_denebola.apparent().altaz()#astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
  print('Location: ', '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1]))
  print('S1 (alt/az):   ',alt_d, az_d)
  star_pos_d = pm.aer2ecef( az_d.degrees,alt_d.degrees, distance_d.m,user_longlatdist[0],user_longlatdist[1],user_longlatdist[2])
  
  sadalmelik = Star.from_dataframe(df.loc[star_name2])
  astrometric_sadalmelik = user_position.at(t).observe(sadalmelik)
  alt_s, az_s, distance_s = astrometric_sadalmelik.apparent().altaz()
  print('S2 (alt/az):   ',alt_s, az_s)
  star_pos_s = pm.aer2ecef( az_s.degrees,alt_s.degrees, distance_s.m,user_longlatdist[0],user_longlatdist[1],user_longlatdist[2])
  
  stars_pos=[star_pos_d,star_pos_s]
  return stars_pos
Exemplo n.º 4
0
def test_dataframe():
    with api.load.open('hip_main.dat.gz') as f:
        df = load_dataframe(f)
    star = api.Star.from_dataframe(df)
    assert repr(
        star
    ) == 'Star(ra shape=214, dec shape=214, ra_mas_per_year shape=214, dec_mas_per_year shape=214, parallax_mas shape=214, epoch shape=214)'
Exemplo n.º 5
0
    def __init__(self):
        with load.open(hipparcos.URL) as f:
            self.df = hipparcos.load_dataframe(f)

        self.planets = load('de421.bsp')
        self.earth = self.planets['earth']
        self.ts = load.timescale()
        self.position = self.earth
Exemplo n.º 6
0
def test_hipparcos():
    try:
        df = load_dataframe(BytesIO(gzip.compress(sample_hipparcos_line)))
    except ImportError:
        raise SkipTest('pandas not available')
    assert len(df) == 1
    row = df.iloc[0]
    assert abs(row.ra_degrees - 000.00091185) < 1e-30
    assert abs(row.ra_hours == 000.00091185 / 15.0) < 1e-30
Exemplo n.º 7
0
 def __init__(self, time_only=False):
     path = pathlib.Path(
         __file__).parent.parent.absolute() / 'skyfield-data'
     load = Loader(path.as_posix())
     self.timescale = load.timescale()
     self.timescale.julian_calendar_cutoff = GREGORIAN_START
     if not time_only:
         self.ephemeris = load('de431t.bsp')
         self.babylon_topos = Topos(*BABYLON_COORDS)
         with load.open(hipparcos.URL) as f:
             self.stars = hipparcos.load_dataframe(f)
Exemplo n.º 8
0
def get_probe_coords(hip_id, distance):
    # set timezone + load planet info
    utcTZ = timezone("UTC")
    local_tz = get_localzone()
    ts = load.timescale()
    planets = load('de421.bsp')

    # get time of observation and locations of observation
    t = ts.from_datetime(datetime(2020, 11, 9, 00, 00, tzinfo=utcTZ))
    sun = planets['sun']
    earth = planets['earth']

    # load in the hipparcos data
    with load.open(hipparcos.URL) as f:
        df = hipparcos.load_dataframe(f)

    # # match on star coords
    # ra_inds = []
    # for ind, cat_ra in enumerate(df['ra_degrees'].values):
    #     if isclose(cat_ra, ra_star, rel_tol=1e-2):
    #         ra_inds.append(ind)

    # dec_inds = []
    # for ind, cat_dec in enumerate(df['dec_degrees'].values):
    #     if isclose(cat_dec, dec_star, rel_tol=1e-2):
    #         dec_inds.append(ind)

    # # find where ra & dec match within tolerance
    # sets = set(ra_inds).intersection(set(dec_inds))
    # inds = [x for x in iter(sets)]
    # print(inds)

    # just take the first one for now
    the_star = Star.from_dataframe(df.loc[hip_id])

    # "observe" the star from Earth
    starPosObj = earth.at(t).observe(the_star)
    ra, dec, dist = starPosObj.radec()

    # get coords of opposite point on the sky
    ra = ((ra._degrees + 180.0) % 360) * (24.0 / 360.0)
    dec = -1.0 * dec._degrees

    # get coords of the probe and return ra dec in degree
    probe = position_of_radec(ra, dec, distance, t=t)
    sunPosObj = earth.at(t).observe(sun)
    inverseSunCoord = -1.0 * sunPosObj.position.au
    probeCoord = probe.position.au
    probeDir = ICRF(probeCoord + inverseSunCoord).radec()
    return probeDir[0]._degrees, probeDir[1]._degrees
def test_hipparcos():
    b = BytesIO()
    g = gzip.GzipFile(mode='wb', fileobj=b)
    g.write(sample_hipparcos_line)
    g.close()
    b.seek(0)
    try:
        df = load_dataframe(b)
    except ImportError:
        # raise SkipTest('pandas not available')
        # Assay doesn't understand skipping tests yet; just pass
        # for now if Pandas cannot be imported.
        return
    assert len(df) == 1
    row = df.iloc[0]
    assert abs(row.ra_degrees - 000.00091185) < 1e-30
    assert abs(row.dec_degrees - +01.08901332) < 1e-30
Exemplo n.º 10
0
def test_hipparcos():
    b = BytesIO()
    g = gzip.GzipFile(mode='wb', fileobj=b)
    g.write(sample_hipparcos_line)
    g.close()
    b.seek(0)
    try:
        df = load_dataframe(b)
    except ImportError:
        # raise SkipTest('pandas not available')
        # Assay doesn't understand skipping tests yet; just pass
        # for now if Pandas cannot be imported.
        return
    assert len(df) == 1
    row = df.iloc[0]
    assert abs(row.ra_degrees - 000.00091185) < 1e-30
    assert abs(row.dec_degrees - +01.08901332) < 1e-30
Exemplo n.º 11
0
def load_stars(max_magnitude, verbose=False):
    """Load the Hipparcos catalog data and find all applicable stars.  Returns a
    list of StarObs, one per star.
    """
    if verbose:
        print("[  CATALOG] Loading star catalog data.")
    with load.open(hipparcos.URL) as f:
        df = hipparcos.load_dataframe(f)

        df = df[df['magnitude'] <= max_magnitude]
        df = df[df['ra_degrees'].notnull()]

        if verbose:
            print(
                f'[  CATALOG] Found {len(df)} stars brighter than magnitude {max_magnitude:.4f}.'
            )
        return [
            StarObs(str(idx), Star.from_dataframe(df.loc[idx]),
                    df.loc[idx].magnitude) for idx in df.index
        ]
Exemplo n.º 12
0
def init_sf(spad):
    global ts, eph, earth, moon, sun, venus, mars, jupiter, saturn, df
    load = Loader(spad)  # spad = folder to store the downloaded files
    EOPdf = "finals2000A.all"  # Earth Orientation Parameters data file
    dfIERS = spad + EOPdf

    if config.useIERS:
        if compareVersion(VERSION, "1.31") >= 0:
            if path.isfile(dfIERS):
                if load.days_old(EOPdf) > float(config.ageIERS):
                    load.download(EOPdf)
                ts = load.timescale(builtin=False)  # timescale object
            else:
                load.download(EOPdf)
                ts = load.timescale(builtin=False)  # timescale object
        else:
            ts = load.timescale()  # timescale object with built-in UT1-tables
    else:
        ts = load.timescale()  # timescale object with built-in UT1-tables

    if config.ephndx in set([0, 1, 2, 3, 4]):

        eph = load(config.ephemeris[config.ephndx][0])  # load chosen ephemeris
        earth = eph['earth']
        moon = eph['moon']
        sun = eph['sun']
        venus = eph['venus']
        jupiter = eph['jupiter barycenter']
        saturn = eph['saturn barycenter']
        if config.ephndx >= 3:
            mars = eph['mars barycenter']
        else:
            mars = eph['mars']

    # load the Hipparcos catalog as a 118,218 row Pandas dataframe.
    with load.open(hipparcos.URL) as f:
        #hipparcos_epoch = ts.tt(1991.25)
        df = hipparcos.load_dataframe(f)

    return ts
Exemplo n.º 13
0
sun = eph['sun']
earth = eph['earth']

# The Minor Planet Center data file provides the comet orbit.

with load.open(mpc.COMET_URL) as f:
    comets = mpc.load_comets_dataframe(f)

comets = comets.set_index('designation', drop=False)
row = comets.loc['C/2020 F3 (NEOWISE)']
comet = sun + mpc.comet_orbit(row, ts, GM_SUN)

# The Hipparcos mission provides our star catalog.

with load.open(hipparcos.URL) as f:
    stars = hipparcos.load_dataframe(f)

# And the constellation outlines come from Stellarium.  We make a list
# of the stars at which each edge stars, and the star at which each edge
# ends.

url = ('https://raw.githubusercontent.com/Stellarium/stellarium/master'
       '/skycultures/western_SnT/constellationship.fab')

with load.open(url) as f:
    constellations = stellarium.parse_constellations(f)

edges = [edge for name, edges in constellations for edge in edges]
edges_star1 = [star1 for star1, star2 in edges]
edges_star2 = [star2 for star1, star2 in edges]
Exemplo n.º 14
0
def create_starmap(command, observation_id):

    # The comet is plotted on several dates `t_comet`.  But the stars only
    # need to be drawn once, so we take the middle comet date as the single
    # time `t` we use for everything else.

    ts = load.timescale()
    t_comet = ts.utc(2020, 8, range(1, 10))
    t = t_comet[len(t_comet) // 2]  # middle date

    # An ephemeris from the JPL provides Sun and Earth positions.

    eph = load('de421.bsp')
    sun = eph['sun']
    earth = eph['earth']

    # The Minor Planet Center data file provides the comet orbit.

    with load.open(mpc.COMET_URL) as f:
        comets = mpc.load_comets_dataframe(f)

    comets = (comets.sort_values('reference')
              .groupby('designation', as_index=False).last()
              .set_index('designation', drop=False))

    row = comets.loc['C/2020 F3 (NEOWISE)']
    comet = sun + mpc.comet_orbit(row, ts, GM_SUN)

    # The Hipparcos mission provides our star catalog.

    # with load.open(hipparcos.URL) as f:
    with load.open(settings.MY_HIPPARCOS_URL) as f:
        stars = hipparcos.load_dataframe(f)

    # And the constellation outlines come from Stellarium.  We make a list
    # of the stars at which each edge stars, and the star at which each edge
    # ends.

    url = ('https://raw.githubusercontent.com/Stellarium/stellarium/master'
           '/skycultures/western_SnT/constellationship.fab')

    with load.open(url) as f:
        constellations = stellarium.parse_constellations(f)

    edges = [edge for name, edges in constellations for edge in edges]
    edges_star1 = [star1 for star1, star2 in edges]
    edges_star2 = [star2 for star1, star2 in edges]

    # We will center the chart on the comet's middle position.

    center = earth.at(t).observe(comet)
    projection = build_stereographic_projection(center)
    field_of_view_degrees = 30.0
    limiting_magnitude = 8.0

    # Now that we have constructed our projection, compute the x and y
    # coordinates that each star and the comet will have on the plot.

    star_positions = earth.at(t).observe(Star.from_dataframe(stars))
    stars['x'], stars['y'] = projection(star_positions)

    comet_x, comet_y = projection(earth.at(t_comet).observe(comet))

    # Create a True/False mask marking the stars bright enough to be
    # included in our plot.  And go ahead and compute how large their
    # markers will be on the plot.

    bright_stars = (stars.magnitude <= limiting_magnitude)
    magnitude = stars['magnitude'][bright_stars]
    marker_size = (0.5 + limiting_magnitude - magnitude) ** 2.0

    # The constellation lines will each begin at the x,y of one star and end
    # at the x,y of another.  We have to "rollaxis" the resulting coordinate
    # array into the shape that matplotlib expects.

    xy1 = stars[['x', 'y']].loc[edges_star1].values
    xy2 = stars[['x', 'y']].loc[edges_star2].values
    lines_xy = np.rollaxis(np.array([xy1, xy2]), 1)

    # Time to build the figure!

    fig, ax = plt.subplots(figsize=[9, 9])

    # Draw the constellation lines.

    ax.add_collection(LineCollection(lines_xy, colors='#00f2'))

    # Draw the stars.

    ax.scatter(stars['x'][bright_stars], stars['y'][bright_stars],
               s=marker_size, color='k')

    # Draw the comet positions, and label them with dates.

    comet_color = '#f00'
    offset = 0.002

    ax.plot(comet_x, comet_y, '+', c=comet_color, zorder=3)

    for xi, yi, tstr in zip(comet_x, comet_y, t_comet.utc_strftime('%m/%d')):
        tstr = tstr.lstrip('0')
        text = ax.text(xi + offset, yi - offset, tstr, color=comet_color,
                       ha='left', va='top', fontsize=9, weight='bold', zorder=-1)
        text.set_alpha(0.5)

    # Finally, title the plot and set some final parameters.

    angle = np.pi - field_of_view_degrees / 360.0 * np.pi
    limit = np.sin(angle) / (1.0 - np.cos(angle))

    ax.set_xlim(-limit, limit)
    ax.set_ylim(-limit, limit)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.set_aspect(1.0)
    ax.set_title('Comet NEOWISE {} through {}'.format(
        t_comet[0].utc_strftime('%Y %B %d'),
        t_comet[-1].utc_strftime('%Y %B %d'),
    ))

    # Save.
    filename = 'starmap.png'
    path = os.path.join(settings.MEDIA_ROOT, filename)

    fig.savefig(path, bbox_inches='tight')

    image_url = os.path.join(settings.MEDIA_URL, filename)
    return image_url
Exemplo n.º 15
0
def index(request):
    stars = []

    if request.body:
        req = json.loads(request.body)

        if req['type'] == 'GET_VISIBLE_STARS':
            planets = load('de421.bsp')
            earth = planets['earth']
            ts = load.timescale()
            dt = datetime.strptime(req['date'], '%Y-%m-%dT%H:%M:%S.%fZ')
            dt = dt.replace(tzinfo=timezone.utc)
            t = ts.utc(dt)
            observerLocation = earth + \
                Topos(latitude_degrees=req['lat'],
                        longitude_degrees=req['long'])

            with load.open(hipparcos.URL) as f:
                df = hipparcos.load_dataframe(f)
            
            for key in navigationStarsHip:
                starname = key
                hipNo = navigationStarsHip[key]
                star = Star.from_dataframe(df.loc[hipNo])

                apparent = observerLocation.at(t).observe(star).apparent()
                alt, az, dist = apparent.altaz()
                eachStar = {
                    'name': key,
                    'hip': navigationStarsHip[key],
                    'alt': alt.degrees,
                    'az': az.degrees,
                    'dist': dist.km
                }
                if eachStar['alt'] > 0 :
                    stars.append(eachStar)


        if req['type'] == 'GET_TBRG_STAR':
            planets = load('de421.bsp')
            earth = planets['earth']
            ts = load.timescale()
            dt = datetime.strptime(req['date'], '%Y-%m-%dT%H:%M:%S.%fZ')
            dt = dt.replace(tzinfo=timezone.utc)
            t = ts.utc(dt)
            observerLocation = earth + \
                Topos(latitude_degrees=req['lat'],
                        longitude_degrees=req['long'])

            with load.open(hipparcos.URL) as f:
                df = hipparcos.load_dataframe(f)

                starname = req['selectedStar']
                hipNo = navigationStarsHip[starname]
                star = Star.from_dataframe(df.loc[hipNo])
                apparent = observerLocation.at(t).observe(star).apparent()
                alt, az, dist = apparent.altaz()

                return JsonResponse({
                    'name': starname,
                    'hipNo': navigationStarsHip[starname],
                    'alt': alt.degrees,
                    'az': az.degrees,
                    'dist': dist.km
                })


        if (req['type'] == 'GET_TBRG_PLANET'):
            planets = load('de421.bsp')
            earth = planets['earth']
            ts = load.timescale()
            dt = datetime.strptime(req['date'], '%Y-%m-%dT%H:%M:%S.%fZ')
            dt = dt.replace(tzinfo=timezone.utc)
            t = ts.utc(dt)
            observerLocation = earth + \
                Topos(latitude_degrees=req['lat'],
                        longitude_degrees=req['long'])

            planet = planets[req['body']]
            apparent = observerLocation.at(t).observe(planet).apparent()
            alt, az, dist = apparent.altaz()
            return JsonResponse({
                "alt": alt.degrees,
                "az": az.degrees,
                "dist": dist.km
            })
# Altitude and azimuth in the sky of a
# specific geographic location

boston = earth + Topos('42.3583 N', '71.0603 W')
astro = boston.at(ts.utc(1980, 3, 1)).observe(mars)
app = astro.apparent()

alt, az, distance = app.altaz()
print(alt.dstr())
print(az.dstr())
print(distance)

# Measure a star

with load.open(hipparcos.URL) as f:
    df = hipparcos.load_dataframe(f)

barnards_star = Star.from_dataframe(df.loc[87937])

planets = load('de421.bsp')
earth = planets['earth']

ts = load.timescale()
t = ts.now()
astrometric = boston.at(t).observe(barnards_star)
app_b = astrometric.apparent()

alt_b, az_b, distance_b = app_b.altaz()
print("Bernard star")
print(alt_b.dstr())
print(az_b.dstr())
Exemplo n.º 17
0
def create_starmap(name, timestamp, days_past, days_future, fov, magnitude):

    # The comet is plotted on several dates `t_transient`.  But the stars only
    # need to be drawn once, so we take the middle comet date as the single
    # time `t` we use for everything else.

    try:
        # first try comets
        d, transient = algorithms.get_comet(name, timestamp)
    except:
        # then try asteroids
        d, transient = algorithms.get_asteroid(name, timestamp)

    ts = load.timescale()
    t_timestamp = ts.utc(timestamp.year, timestamp.month, timestamp.day,
                         timestamp.hour, timestamp.minute)

    t_transient = ts.utc(
        timestamp.year, timestamp.month,
        range(timestamp.day - days_past, timestamp.day + days_future))
    t = t_transient[len(t_transient) // 2]  # middle date

    # An ephemeris from the JPL provides Sun and Earth positions.

    eph = load('de421.bsp')
    earth = eph['earth']

    # The Hipparcos mission provides our star catalog.

    # with load.open(hipparcos.URL) as f:
    with load.open(settings.MY_HIPPARCOS_URL) as f:
        stars = hipparcos.load_dataframe(f)

    # And the constellation outlines come from Stellarium.  We make a list
    # of the stars at which each edge stars, and the star at which each edge
    # ends.

    url = ('https://raw.githubusercontent.com/Stellarium/stellarium/master'
           '/skycultures/western_SnT/constellationship.fab')

    with load.open(url) as f:
        constellations = stellarium.parse_constellations(f)

    edges = [edge for name, edges in constellations for edge in edges]
    edges_star1 = [star1 for star1, star2 in edges]
    edges_star2 = [star2 for star1, star2 in edges]

    # We will center the chart on the comet's middle position.

    center = earth.at(t).observe(transient)
    #star = Star(ra_hours=(17, 57, 48.49803), dec_degrees=(4, 41, 36.2072))
    #center = earth.at(t).observe(star)

    projection = build_stereographic_projection(center)
    field_of_view_degrees = float(fov)
    limiting_magnitude = magnitude

    # Now that we have constructed our projection, compute the x and y
    # coordinates that each star and the comet will have on the plot.

    star_positions = earth.at(t).observe(Star.from_dataframe(stars))
    stars['x'], stars['y'] = projection(star_positions)

    transient_x, transient_y = projection(
        earth.at(t_transient).observe(transient))

    # Create a True/False mask marking the stars bright enough to be
    # included in our plot.  And go ahead and compute how large their
    # markers will be on the plot.

    bright_stars = (stars.magnitude <= limiting_magnitude)
    magnitude = stars['magnitude'][bright_stars]
    marker_size = (0.5 + limiting_magnitude - magnitude)**2.0

    # The constellation lines will each begin at the x,y of one star and end
    # at the x,y of another.  We have to "rollaxis" the resulting coordinate
    # array into the shape that matplotlib expects.

    xy1 = stars[['x', 'y']].loc[edges_star1].values
    xy2 = stars[['x', 'y']].loc[edges_star2].values
    lines_xy = np.rollaxis(np.array([xy1, xy2]), 1)

    # Time to build the figure!

    fig, ax = plt.subplots(figsize=[12, 12])

    # Draw the constellation lines.

    ax.add_collection(LineCollection(lines_xy, colors='#00f2'))

    # Draw the stars.

    ax.scatter(stars['x'][bright_stars],
               stars['y'][bright_stars],
               s=marker_size,
               color='k')

    # Draw the comet positions, and label them with dates.

    transient_color = '#f00'
    offset = 0.0005

    ax.plot(transient_x, transient_y, '+', c=transient_color, zorder=3)

    for xi, yi, tstr in zip(transient_x, transient_y,
                            t_transient.utc_strftime('%m/%d')):
        tstr = tstr.lstrip('0')
        text = ax.text(xi + offset,
                       yi - offset,
                       tstr,
                       color=transient_color,
                       ha='left',
                       va='top',
                       fontsize=9,
                       weight='bold',
                       zorder=-1)
        text.set_alpha(0.5)

    # Finally, title the plot and set some final parameters.

    angle = np.pi - field_of_view_degrees / 360.0 * np.pi
    limit = np.sin(angle) / (1.0 - np.cos(angle))

    ax.set_xlim(-limit, limit)
    ax.set_ylim(-limit, limit)
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.set_aspect(1.0)
    ax.set_title('{} {} through {}'.format(
        d['designation'],
        t_transient[0].utc_strftime('%d %B %Y'),
        t_transient[-1].utc_strftime('%d %B %Y'),
    ))

    # Save.
    filename = 'starmap.png'
    path = os.path.join(settings.MEDIA_ROOT, filename)

    fig.savefig(path, bbox_inches='tight')

    image_url = os.path.join(settings.MEDIA_URL, filename)
    return image_url
def galactic_Sun_north_center_SD_directions(
        measurement_date,
        recv_time,
        user_longlatdist=geographic_position,
        prints=False):
    user_longlatdist = np.array(user_longlatdist)
    with load.open(hipparcos.URL) as f:
        df = hipparcos.load_dataframe(f)

    planets = load('de421.bsp')
    earth = planets['earth']
    user_position = earth + Topos(
        '{} N'.format(user_longlatdist[0]), '{} E'.format(user_longlatdist[1])
    )  #user_longlatdist      user_longlatdist[0],user_longlatdist[1]
    terrestrial_time = format_time_auto(measurement_date, recv_time)
    ts = load.timescale()
    t = ts.tt(terrestrial_time[0], terrestrial_time[1], terrestrial_time[2],
              terrestrial_time[3], terrestrial_time[4], terrestrial_time[5])

    sun = planets['sun']
    astrometric_sun = user_position.at(t).observe(sun)
    alt_sun, az_sun, distance_sun = astrometric_sun.apparent().altaz(
    )  #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
    sun_position = pm.aer2ecef(az_sun.degrees, alt_sun.degrees, distance_sun.m,
                               user_longlatdist[0], user_longlatdist[1],
                               user_longlatdist[2])

    # Északi Galaktikus Pólus (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0)
    coma_berenices = Star(ra_hours=(12, 51, 25.2), dec_degrees=(27, 7, 48.0))
    astrometric_berenice = user_position.at(t).observe(coma_berenices)
    alt_b, az_b, distance_b = astrometric_berenice.apparent().altaz()
    berenice_position = pm.aer2ecef(az_b.degrees, alt_b.degrees, distance_b.m,
                                    user_longlatdist[0], user_longlatdist[1],
                                    user_longlatdist[2])

    # Galaktikus Center (RA: 12h 51.42m; D: 27° 07.8′, epocha J2000.0) 17h 45.6m  −28.94°
    galactic_center = Star(ra_hours=(17, 45, 36.0),
                           dec_degrees=(-28, 56, 24.0))
    astrometric_center = user_position.at(t).observe(galactic_center)
    alt_c, az_c, distance_c = astrometric_center.apparent().altaz()
    center_position = pm.aer2ecef(az_c.degrees, alt_c.degrees, distance_c.m,
                                  user_longlatdist[0], user_longlatdist[1],
                                  user_longlatdist[2])

    nunki = Star.from_dataframe(df.loc[92855])
    astrometric_nunki = user_position.at(t).observe(nunki)
    alt_n, az_n, distance_n = astrometric_nunki.apparent().altaz(
    )  #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
    star_pos_n = pm.aer2ecef(az_n.degrees, alt_n.degrees, distance_n.m,
                             user_longlatdist[0], user_longlatdist[1],
                             user_longlatdist[2])

    capella = Star.from_dataframe(df.loc[24608])
    astrometric_capella = user_position.at(t).observe(capella)
    alt_ca, az_ca, distance_ca = astrometric_capella.apparent().altaz(
    )  #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
    star_pos_ca = pm.aer2ecef(az_ca.degrees, alt_ca.degrees, distance_ca.m,
                              user_longlatdist[0], user_longlatdist[1],
                              user_longlatdist[2])

    denebola = Star.from_dataframe(df.loc[57632])
    astrometric_denebola = user_position.at(t).observe(denebola)
    alt_d, az_d, distance_d = astrometric_denebola.apparent().altaz(
    )  #astrometric.apparent().altaz() = astrometric_denebola.apparent().altaz()
    star_pos_d = pm.aer2ecef(az_d.degrees, alt_d.degrees, distance_d.m,
                             user_longlatdist[0], user_longlatdist[1],
                             user_longlatdist[2])

    sadalmelik = Star.from_dataframe(df.loc[109074])
    astrometric_sadalmelik = user_position.at(t).observe(sadalmelik)
    alt_s, az_s, distance_s = astrometric_sadalmelik.apparent().altaz()
    star_pos_s = pm.aer2ecef(az_s.degrees, alt_s.degrees, distance_s.m,
                             user_longlatdist[0], user_longlatdist[1],
                             user_longlatdist[2])
    if prints:
        print('Time:  ', terrestrial_time)
        print('Location: ', '{} N'.format(user_longlatdist[0]),
              '{} E'.format(user_longlatdist[1]))
        print('Sun (alt/az):   ', alt_sun, az_sun)
        print('Coma Berenice (alt/az):   ', alt_b, az_b)
        print('Galactic Center (alt/az):   ', alt_c, az_c)
        print('Nunki (alt/az):   ', alt_n, az_n)
        print('Capella (alt/az):   ', alt_ca, az_ca)
        print('Denebola (alt/az):   ', alt_d, az_d)
        print('Sadalmelik (alt/az):   ', alt_s, az_s)

    stars_pos = [
        sun_position, berenice_position, center_position, star_pos_n,
        star_pos_ca, star_pos_d, star_pos_s
    ]
    return stars_pos
def compute_all():
    yield compute('Sun', precision_radec=1)
    yield compute('Moon')
    yield compute('Jupiter barycenter', planet=599)
    yield compute('Io', kernel=jup365)

    # XXX: Those tests might fail when we update the planet.ini data since
    #      the orbits are not stable.
    t = [2021, 3, 22, 15, 0, 0]
    yield compute('Metis',
                  kernel=jup365,
                  t=t,
                  precision_radec=15,
                  precision_azalt=20)
    yield compute('Thebe',
                  kernel=jup365,
                  t=t,
                  precision_radec=15,
                  precision_azalt=20)
    yield compute('Phobos',
                  kernel=mar097,
                  t=t,
                  precision_radec=5,
                  precision_azalt=10)
    yield compute('Deimos',
                  kernel=mar097,
                  precision_radec=5,
                  t=t,
                  precision_azalt=10)
    yield compute('Pluto barycenter',
                  planet=999,
                  t=t,
                  precision_radec=10,
                  precision_azalt=15)
    yield compute('Pluto barycenter',
                  planet=999,
                  t=t,
                  precision_radec=10,
                  precision_azalt=15)

    # ISS, using TLE as of 2019-08-04.
    tle = [
        '1 25544U 98067A   19216.19673594 -.00000629  00000-0 -27822-5 0  9998',
        '2 25544  51.6446 123.0769 0006303 213.9941 302.5470 15.51020378182708',
    ]
    iss = sf.EarthSatellite(*tle, 'ISS (ZARYA)')
    iss = de421['earth'] + iss
    json = {
        'model_data': {
            'norad_number': 25544,
            'tle': tle,
        }
    }

    yield compute(iss,
                  name='ISS',
                  t=[2019, 8, 4, 17, 0],
                  json=json,
                  planet=0,
                  klass='tle_satellite',
                  precision_radec=15,
                  precision_azalt=15)

    yield compute(
        iss,
        name='ISS',
        t=[2019, 8, 3, 20, 51, 46],
        json=json,
        topo=['43.4822 N', '1.432 E'],  # Goyrans
        planet=0,
        klass='tle_satellite',
        precision_radec=100,
        precision_azalt=100)

    # Pallas, using MPC data as of 2019-08-06.
    data = {
        "Epoch": 2458600.5,
        "M": 59.69912,
        "Peri": 310.04884,
        "Node": 173.08006,
        "i": 34.83623,
        "e": 0.2303369,
        "n": 0.21350337,
        "a": 2.772466
    }
    yield compute_asteroid('Pallas',
                           data=data,
                           t='2019/08/10 17:00',
                           precision_radec=200,
                           precision_azalt=400)

    with sf.load.open(hipparcos.URL) as f:
        df = hipparcos.load_dataframe(f)
    polaris = sf.Star.from_dataframe(df.loc[11767])
    yield compute_star(polaris, name='Polaris')

    proxima = sf.Star.from_dataframe(df.loc[70890])
    yield compute_star(proxima, name='Proxima Centauri')

    barnard = sf.Star.from_dataframe(df.loc[87937])
    yield compute_star(barnard, name='Barnards Star')