def test_star_vector(ts): t = ts.tt(api.T0) s = api.Star(ra_hours=[1.0, 2.0], dec_degrees=[+3.0, +4.0]) o = positionlib.Barycentric([0.0, 0.0, 0.0], t=t) p = o.observe(s) assert p.position.au.shape == (3, 2) assert p.velocity.au_per_d.shape == (3, 2)
def test_star_vector_from_earth(ts): t = ts.tt_jd(api.T0) eph = api.load('de421.bsp') e = eph['earth'].at(t) star = api.Star(ra_hours=[1.0, 2.0], dec_degrees=[+3.0, +4.0]) p = e.observe(star) assert p.position.au.shape == (3, 2) assert p.velocity.au_per_d.shape == (3, 2) assert p.t.shape == (2,) assert (p.t.tt == api.T0).all() a = p.apparent() a1 = e.observe(api.Star(ra_hours=1.0, dec_degrees=+3.0)).apparent() a2 = e.observe(api.Star(ra_hours=2.0, dec_degrees=+4.0)).apparent() assert (a1.position.au == a.position.au[:,0]).all() assert (a2.position.au == a.position.au[:,1]).all()
def add_sources(fig, ax1, ax2, obstime=None, az_grid=None, za_grid=None, beamsky=None): """Note that this function does nothing, apart from printing some coordinates. """ obstime = su.time2tai(obstime) lst = get_LST(obstime) print("------------------------------") print( "Adding sources for lst=%.2f [hours] , coordinates = (%.4f,%.4f) [deg]:" % (lst, su.MWA_TOPO.longitude.degrees, su.MWA_TOPO.latitude.degrees)) print("------------------------------") # add text for sources # lst=get_LST(gps) for source in SOURCES: # Using astropy.Angle purely to convert the sexagesimal strings, because it's hard in skyfield. RA = astropy.coordinates.Angle(SOURCES[source][1], unit=astropy.units.hour).deg Dec = astropy.coordinates.Angle(SOURCES[source][2], unit=astropy.units.deg).deg coords = si.Star(ra_hours=RA / 15.0, dec_degrees=Dec) observer = su.S_MWAPOS.at(obstime) coords_alt, coords_az, _ = observer.observe(coords).apparent().altaz() az, alt = coords_az.degrees, coords_alt.degrees za = 90.00 - alt x_best = -1 y_best = -1 if az_grid is not None and za_grid is not None and alt > 0 and show_source( source): min_diff = 1000000.00 max_beam = -100000 max_beam_x = -1 max_beam_y = -1 for x in range(0, az_grid.shape[0]): for y in range(0, az_grid.shape[1]): az_test = az_grid[x, y] za_test = za_grid[x, y] diff = ((az - az_test)**2 + (za - za_test)**2) if diff < min_diff: min_diff = diff x_best = x y_best = y if beamsky is not None: if beamsky[x, y] > max_beam: max_beam = beamsky[x, y] max_beam_x = x max_beam_y = y tmp = x_best x_best = y_best y_best = tmp tmp = max_beam_x max_beam_x = max_beam_y max_beam_y = tmp print("MAX(beam) = %.2f at (x,y) = (%d,%d)" % (max_beam, max_beam_x, max_beam_y)) fstring = "%s : (%s,%s) -> (%.4f,%.4f) [deg] -> (az,za) = (%.4f,%.4f) [deg] -> (x,y) = (%d,%d)" params = (source, SOURCES[source][1], SOURCES[source][2], RA, Dec, az, za, x_best, y_best) print(fstring % params) print("------------------------------")
def test_star_position_class(ts): e = api.load('de421.bsp') star = api.Star(ra_hours=0, dec_degrees=0) p = e['earth'].at(ts.utc(2014, 2, 9, 15, 1)).observe(star) assert isinstance(p, positionlib.Astrometric)
def test_star_position_class(): star = api.Star(ra_hours=0, dec_degrees=0) p = api.earth(utc=(2014, 2, 9, 15, 1)).observe(star) assert isinstance(p, positionlib.Astrometric)
def get_best_gridpoints(gps_start, obs_source_ra_deg, obs_source_dec_deg, avoid_source_ra_deg, avoid_source_dec_deg, model="analytic", min_gain=None, max_beam_distance_deg=360, channel=145, verb_level=1, logger=LOGGER, duration=3600, step=120, min_elevation=30.00): su.init_data() frequency = channel * 1.28 if model not in ['analytic', 'advanced', 'full_EE', 'full_EE_AAVS05']: logger.error("Model %s not found\n" % model) gp_numbers = list(mwa_sweet_spots.all_grid_points.keys()) gp_numbers.sort() gp_azes = numpy.array([mwa_sweet_spots.all_grid_points[i][1] for i in gp_numbers]) gp_alts = numpy.array([mwa_sweet_spots.all_grid_points[i][2] for i in gp_numbers]) gp_delays = [mwa_sweet_spots.all_grid_points[i][4] for i in gp_numbers] obs_source = si.Star(ra=si.Angle(degrees=obs_source_ra_deg), dec=si.Angle(degrees=obs_source_dec_deg)) avoid_source = si.Star(ra=si.Angle(degrees=avoid_source_ra_deg), dec=si.Angle(degrees=avoid_source_dec_deg)) freq = frequency * 1e6 tracklist = [] # List of (starttime, duration, az, el) tuples for starttime in range(int(gps_start), int(gps_start + duration), int(step)): t = su.time2tai(starttime) observer = su.S_MWAPOS.at(t) obs_source_apparent = observer.observe(obs_source).apparent() obs_source_alt, obs_source_az, _ = obs_source_apparent.altaz() if obs_source_alt.degrees < min_elevation: logger.debug("Source at %.2f [deg] below minimum elevation = %.2f [deg] at this time, skip this timestep." % (obs_source_alt.degrees, min_elevation)) continue # Source below pointing horizon at this time, skip this timestep. if min_gain is None: current_min_gain = 0.5 if obs_source_alt.degrees < 50: current_min_gain = 0.1 else: current_min_gain = min_gain avoid_source_apparent = observer.observe(avoid_source).apparent() avoid_source_alt, avoid_source_az, _ = avoid_source_apparent.altaz() if avoid_source_alt.degrees < 0.0: tracklist.append((starttime, step, obs_source_az.degrees, obs_source_alt.degrees)) logger.debug("Avoided source below TRUE horizon, just use actual target az/alt for this timestep.") continue # Avoided source below TRUE horizon, just use actual target az/alt for this timestep. dist_deg = obs_source_apparent.separation_from(avoid_source_apparent).degrees logger.debug("Observed source at (az,alt) = (%.4f,%.4f) [deg]" % (obs_source_az.degrees, obs_source_alt.degrees)) logger.debug("Avoided source at (az,alt) = (%.4f,%.4f) [deg]" % (avoid_source_az.degrees, avoid_source_alt.degrees)) logger.debug("Anglular distance = %.2f [deg]" % (dist_deg)) logger.debug("Gps time = %d" % su.tai2gps(t)) gp_positions = observer.from_altaz(alt_degrees=gp_alts, az_degrees=gp_azes, distance=si.Distance(au=9e90)) dist_obs_degs = obs_source_apparent.separation_from(gp_positions).degrees dist_avoid_degs = avoid_source_apparent.separation_from(gp_positions).degrees # select gridpoints within given angular distance : best_gridpoint = None r_max = -1000 best_gain_obs = 0 best_gain_avoid = 0 skipped_too_far = 0 skipped_gain_too_low = 0 for i in range(len(gp_numbers)): gpnum = gp_numbers[i] dist_obs = dist_obs_degs[i] dist_avoid = dist_avoid_degs[i] if verb_level > 1: outstring = "\n\t\ttesting gridpoint %d, dist_obs_deg = %.2f [deg], dist_avoid_deg = %.2f [deg]" logger.debug(outstring % (gpnum, dist_obs, dist_avoid)) # if dist_obs_deg < options.max_beam_distance_deg and dist_avoid_deg < options.max_beam_distance_deg : if dist_obs < max_beam_distance_deg: beam_obs = primarybeammap_tant.get_beam_power(gp_delays[i], freq, model=model, pointing_az_deg=obs_source_az.degrees, pointing_za_deg=90 - obs_source_alt.degrees, zenithnorm=True) beam_avoid = primarybeammap_tant.get_beam_power(gp_delays[i], freq, model=model, pointing_az_deg=avoid_source_az.degrees, pointing_za_deg=90 - avoid_source_alt.degrees, zenithnorm=True) gain_XX_obs = beam_obs['XX'] gain_XX_avoid = beam_avoid['XX'] r = gain_XX_obs / gain_XX_avoid if r > 1.00 and gain_XX_obs > current_min_gain: outstring = "\t\tSelected gridpoint = %d at (az,elev) = (%.4f,%.4f) [deg] at (distances %.4f and %.4f deg) " outstring += "-> gain_obs=%.4f and gain_avoid=%.4f -> gain_obs/gain_avoid = %.4f" logger.debug(outstring % (gpnum, gp_azes[i], gp_alts[i], dist_obs, dist_avoid, gain_XX_obs, gain_XX_avoid, r)) if r > r_max: best_gridpoint = i r_max = r best_gain_obs = gain_XX_obs best_gain_avoid = gain_XX_avoid else: skipped_gain_too_low = skipped_gain_too_low + 1 if verb_level > 1: outstring = "\t\tSKIPPED gridpoint = %d at (az,elev) = (%.4f,%.4f) [deg] at (distances %.4f and %.4f deg) " outstring += "-> gain_obs=%.4f (vs. min_gain=%.2f) and gain_avoid=%.4f -> gain_obs/gain_avoid = %.4f" logger.debug(outstring % (gpnum, gp_azes[i], gp_alts[i], dist_obs, dist_avoid, gain_XX_obs, current_min_gain, gain_XX_avoid, r)) else: skipped_too_far = skipped_too_far + 1 if verb_level > 1: outstring = "\t\t\tskipped as dist_obs_deg = %.2f [deg] and dist_avoid_deg = %.2f [deg] , one > " outstring += "max_beam_distance_deg = %.2f [deg]" logger.debug(outstring % (dist_obs, dist_avoid, max_beam_distance_deg)) logger.debug("Number of gridpoints skipped due to gain lower than minimum (=%.2f) = %d" % (current_min_gain, skipped_gain_too_low)) outstring = "Number of gridpoints skipped due to being further than limit ( max_beam_distance_deg = %.2f [deg] ) = %d" logger.debug(outstring % (max_beam_distance_deg, skipped_too_far)) if best_gridpoint is not None: outstring = "Best gridpoint %d at (az,alt)=(%.4f,%.4f) [deg] at %s UTC to observe has ratio = %.2f = %.8f / %.8f\n" logger.info(outstring % (gp_numbers[best_gridpoint], gp_azes[best_gridpoint], gp_alts[best_gridpoint], t.utc_iso(), r_max, best_gain_obs, best_gain_avoid)) tracklist.append((starttime, step, gp_azes[best_gridpoint], gp_alts[best_gridpoint])) return tracklist
def star_x(row): return api.Star(ra_hours=(row['RA Hour'], row['RA Min'], row['RA Sec']), dec_degrees=(row['DC Deg'], row['DC ArcM'], row['DC ArcS']))
'dec_deg': 38.7836917958 }, { 'name': 'Wei', 'ra_hour': 16.8360591595, 'dec_deg': -34.2932317131 }, { 'name': 'Wezen', 'ra_hour': 7.13985673788, 'dec_deg': -26.3931996662 }, ] STARS = [ skyapi.Star(ra_hours=s['ra_hour'], dec_degrees=s['dec_deg']) for s in STAR_DATA ] def star_data(stars, loc, time): altaz = [loc.at(time).observe(s).apparent().altaz() for s in stars] return [(altaz_[0].degrees, altaz_[1].degrees) for altaz_ in altaz] # data = [] # for star in stars: # obs = princeton.at(now).observe(s) # alt, az, d = obs.apparent().altaz() # data.append((alt.radians, az.radians)) # return data