def calcAirmass(self, ra, dec, obsDate): co = SkyCoord(ra, dec, frame = ICRS, unit = (u.hourangle, u.deg)) t = Time(obsDate.replace('T', ' ')) # TODO: store observer's location in config loc = EarthLocation.of_address('Budapest') hc = co.transform_to(AltAz(obstime = t, location = loc)) return float(hc.secz)
def moon_distance(loc, t2, t3): # Get the distance to the moon via the umbra diameter estimate if isinstance(loc, type(u'')) or isinstance(loc, type('')): loc = EarthLocation.of_address(loc) # Location of Sun & Moon sun = get_sun(t2) moon = get_moon(t2, loc) # Umbra size, from time and location su = estimate_umbra(loc, t2, t3) # Constants in km re = R_earth.to(u.km).value ds = sun.distance.to(u.km).value rs = R_sun.to(u.km).value rm = 1738.1 dm = (2 * rm - su) * ds / (2 * (rs - rm)) + re print( 'Distance estimate: {:.7} km (Actual: {:.7}). Ratio: {:.2}. Difference: {:.7}' .format(dm, moon.distance, moon.distance / (dm * u.km), dm * u.km - moon.distance)) # moon.distance is from surface, not center return dm, moon.distance.to(u.km).value + re
def print_loc(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint. t = Time(datetime.datetime.now()) loc = EarthLocation.of_address(address="") print(loc.lat, loc.lon) mm = Horizons(id="Mars") print(mm.__str__()) with solar_system_ephemeris.set("builtin"): mars = get_body('mars', t, loc) print(mars)
def zenith_at_birth(address, time): # If the query returns more than one location (e.g., searching on # address='springfield'), this function will use the first returned # location. 'address' can be a full specified address though. location = EarthLocation.of_address(address) birth_time = Time(time) age = (Time.now() - birth_time).to(u.year) zenith = AltAz(obstime=birth_time, location=location, alt=90*u.deg, az=0*u.deg) zenith_icrs = zenith.transform_to(ICRS) return zenith_icrs, age
def bdnyc_runquery(): app.vars['location'] = request.form['location'] app.vars['c2time'] = request.form['c2time'] app.vars['c3time'] = request.form['c3time'] loc = EarthLocation.of_address(app.vars['location']) t2 = Time('2017-08-21 ' + app.vars['c2time']) t3 = Time('2017-08-21 ' + app.vars['c3time']) dm, reald = moon_distance(loc, t2, t3) sun = get_sun(t2) sun_altaz = sun.transform_to(AltAz(obstime=t2, location=loc)) su_est = estimate_umbra(loc, t2, t3) su_real = get_umbra(loc, t2) app.vars['d_est'] = '{:.7}'.format(dm) app.vars['d_real'] = '{:.7}'.format(reald) app.vars['su_est'] = '{:.4}'.format(su_est) app.vars['su_real'] = '{:.4}'.format(su_real) app.vars['lat'] = '{:.4}'.format(loc.latitude.value) app.vars['long'] = '{:.4}'.format(loc.longitude.value) sun_alt = '{:.4}'.format(sun_altaz.alt.value) percent_diff = '{:.2}'.format((dm - reald) / reald * 100.) print(loc, t2, t3) print(app.vars['c2time'], app.vars['c3time']) print(request.form['c2time'], request.form['c3time']) print(su_est, app.vars['su_est']) return render_template('view.html', location=app.vars['location'], c2time=app.vars['c2time'], d_est=app.vars['d_est'], d_real=app.vars['d_real'], su_real=app.vars['su_real'], lat=app.vars['lat'], su_est=app.vars['su_est'], long=app.vars['long'], sun_alt=sun_alt, percent_diff=percent_diff)
# check for proper alt-az values if args.altitude: assert(0 <= args.altitude <= 90) if args.azimuth: assert(0 <= args.azimuth <= 360) # check for proper lat-lon values if args.lat: assert(-90 <= args.lat <= 90) if args.lon: assert(-180 <= args.lon <= 180) # double check this '''set location if location is toggled''' if args.location: try: location = EarthLocation.of_address(args.location) print(f"Location set to lat[{location.lat}] lon[{location.lon}]") except: print("[[LOCATION LOOKUP ERROR]]") sys.exit(1) else: location = None '''capture data if toggled''' if args.capture: try: if args.iterations: for i in range(iterations): capture(vrange, div, dual, nsamp, nblock) else: capture(vrange, div, dual, nsamp, nblock)
# Distance c = SkyCoord(ra=10.68458 * u.degree, dec=41.26917 * u.degree, distance=770 * u.kpc) print(c.cartesian.x) print(c.cartesian.y) print(c.cartesian.z) # making use of 3D information c1 = SkyCoord(ra=10 * u.degree, dec=9 * u.degree, distance=10 * u.pc, frame='icrs') c2 = SkyCoord(ra=11 * u.degree, dec=10 * u.degree, distance=11.5 * u.pc, frame='icrs') print(c1.separation_3d(c2)) # convenience methods c1 = SkyCoord(ra=10 * u.degree, dec=9 * u.degree, frame='icrs') c2 = SkyCoord(ra=11 * u.degree, dec=10 * u.degree, frame='fk5') print(c1.separation(c2)) # Differing frames handled correctly print(SkyCoord.from_name("M42")) from astropy.coordinates import EarthLocation print(EarthLocation.of_site('Apache Point Observatory')) # these method query Google Maps to retreive information print(EarthLocation.of_address('1002 Holy Grail Court, St. Louis, MO')) print(EarthLocation.of_address( '1002 Holy Grail Court, St. Louis, MO', get_height=True)) print(EarthLocation.of_address('Danbury, CT'))
from astropy.time import Time from astropy.coordinates import solar_system_ephemeris, EarthLocation from astropy.coordinates import get_body_barycentric, get_body, get_moon #t = Time("2017-09-25 20:26") loc = EarthLocation.of_address('louisville, ky') with solar_system_ephemeris.set('builtin'): sat = get_body('saturn', Time.now(), loc) moon = get_body('moon', Time.now(), loc) print(sat.ra.hms) print(moon.ra.hms)
asp_txt = '\n'.join(sorted(all_aspects)) plt.text(60, -70, asp_txt, zorder=999, fontname='DejaVu Sans Mono') plt.tight_layout() plt.show() if __name__ == '__main__': loc_name = None while loc_name is None: in_name = 'Manchester' #input('Enter name of city on Earth: ').capitalize() try: raise Exception loc_coord = EarthLocation.of_address(in_name) loc_name = in_name except: print('Can not find location: "{}"'.format(in_name)) print('Defaulting to Manchester...') loc_name = 'Manchester' loc_coord = EarthLocation(lat=53.4807593 * u.deg, lon=-2.2426305 * u.deg, height=0) print(loc_coord.lat, loc_coord.lon) obs = Observer(location=loc_coord) tt = Time('2018-04-28 04:00:00') print(tt)
def get_requests_given_ephem( savstr, targetname, ra, dec, pmra, pmdec, Gmag, period, period_unc, epoch, epoch_unc, depth, depth_unc, duration, duration_unc, min_search_time=Time(dt.datetime.today().isoformat()), max_search_time=None, max_airmass_sched=2.0, max_airmass_submit=2.5, min_lunar_distance=20, oot_duration=45*u.minute, eventclass='OIBEO', sites=None, schedule_oot_duration=60*u.minute, semesterstr='20B', filtermode='ip', telescope_class='1m0', ipp_value=1.0, force_acceptability=None): """ Given an ephemeris, and the basic details of a target, generate LCOGT requests for any available transits at the given sites, between min_search_time and max_search_time. Args: get_oibeo: gets the request for which "OIBEO" transits visible (given oot_duration). get_ibe: just "IBE" transit required (easier to schedule). schedule_oot_duration: used for the LCOGT-side REQUESTS, rather than the astroplan scheduling. Can be longer than oot_duration (used for astroplan scheduling) in order to try and get a bit more data. force_acceptability: int or None. If int (e.g., 50) it'll queue an acceptability fraction of 50%. Else it'll go to the ACCEPTABILITY_DICT defaults. Note: LCO Semester A is Dec 1 thru May 31. LCO Semester B is June 1 thru Nov 30. """ if max_search_time is None: max_search_time = MAXTIMEDICT[semesterstr] if eventclass not in [ 'OIBEO', 'OIBE', 'IBEO', 'IBE', 'BEO', 'OIB', 'OI', 'EO' ]: raise AssertionError if 'ephemupdate' in savstr: outdir = ( os.path.join(RESULTSDIR, "LCOGT_{}_updated_requests/{}". format(semesterstr, savstr)) ) else: outdir = ( os.path.join(RESULTSDIR, "LCOGT_{}_observability/{}". format(semesterstr, savstr)) ) if not os.path.exists(outdir): os.mkdir(outdir) outdir = os.path.join(outdir, '{}'.format(targetname)) if not os.path.exists(outdir): os.mkdir(outdir) if max_airmass_sched>3: raise NotImplementedError('approx breaks') groups, sel_sites = [], [] for site in sites: if site in SITEDICT['at_site']: _site = Observer.at_site(site) elif site in SITEDICT['of_address']: _loc = EarthLocation.of_address(site) _site = Observer(location=_loc, name=site) else: msg = f'Did not find site {site} in SITEDICT' raise NotImplementedError(msg) (event_ind, oibeo, ing_tmid_egr, target_window, moon_separation, moon_illumination ) = ( get_event_observability( eventclass, _site, ra*u.deg, dec*u.deg, targetname, epoch, period*u.day, duration*u.hour, n_transits=200, obs_start_time=min_search_time, oot_duration=oot_duration, minokmoonsep=min_lunar_distance*u.deg, max_airmass=max_airmass_sched ) ) lt_maxtime = ing_tmid_egr < np.array(max_search_time) sel = event_ind.flatten() & np.all(lt_maxtime, axis=1) sel_times = target_window[sel, :] if len(sel_times)>=1: ############################################## # save observability output as text file too # print_sel = ( event_ind.flatten() & np.all(lt_maxtime, axis=1) ) print_event_observability(eventclass, event_ind[:,print_sel], oibeo[:,print_sel], ing_tmid_egr[print_sel,:], _site, ra*u.deg, dec*u.deg, targetname, epoch, period*u.day, duration*u.hour, max_airmass_sched, oot_duration, moon_separation[print_sel], moon_illumination[print_sel], minokmoonsep=min_lunar_distance*u.deg, outdir=outdir) ############################################## for sel_time in sel_times: assert len(sel_time) == 2 starttime = sel_time[0] endtime = sel_time[1] if force_acceptability is None: acceptability_threshold = ACCEPTABILITY_DICT[eventclass] else: assert isinstance(force_acceptability, int) assert force_acceptability <= 100 assert force_acceptability >= 1 acceptability_threshold = force_acceptability g = make_request_group( targetname, ra, dec, pmra, pmdec, Gmag, starttime, endtime, eventclass=eventclass, filtermode=filtermode, telescope_class=telescope_class, max_airmass=max_airmass_submit, min_lunar_distance=min_lunar_distance, acceptability_threshold=acceptability_threshold, ipp_value=ipp_value ) if g == -1: continue else: groups.append(g) return groups