def get_info_of_target(target, *args, **kwargs): ra = target.ra dec = target.dec coords = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree)) hanle = EarthLocation(lat=32.77889 * u.degree, lon=78.96472 * u.degree, height=4500 * u.m) iao = Observer(location=hanle, name="GIT", timezone="Asia/Kolkata") twilight_prime = iao.sun_rise_time( Time(datetime.utcnow()), which="next", horizon=sunrise_horizon * u.degree) - 12 * u.hour targets_rise_time = iao.target_rise_time(twilight_prime, coords, which="nearest", horizon=horizon * u.degree) targets_set_time = iao.target_set_time(targets_rise_time, coords, which="next", horizon=horizon * u.degree) rise_time_IST = (targets_rise_time + 5.5 * u.hour).isot set_time_IST = (targets_set_time + 5.5 * u.hour).isot tend = targets_set_time mooncoords = get_moon(tend, hanle) sep = mooncoords.separation(coords) print(target.name, rise_time_IST, set_time_IST, sep)
def rise_time(obsnight, coords, tel=None): import time tstart = time.time() tme = Time(str(obsnight.obs_date).split()[0]) sc = SkyCoord('%s %s' % (coords[0], coords[1]), unit=(u.hourangle, u.deg)) location = EarthLocation.from_geodetic( obsnight.resource.telescope.longitude * u.deg, obsnight.resource.telescope.latitude * u.deg, obsnight.resource.telescope.elevation * u.m) tel = Observer(location=location, timezone="UTC") target_rise_time = tel.target_rise_time(tme, sc, horizon=18 * u.deg, which="previous") if target_rise_time: returnstarttime = target_rise_time.isot.split('T')[-1] else: returnstarttime = None print(time.time() - tstart) return (returnstarttime)
def tonight_rise_time(obsnight,coords): time = Time(datetime.datetime.now()) sc = SkyCoord('%s %s'%(coords[0],coords[1]),unit=(u.hourangle,u.deg)) location = EarthLocation.from_geodetic( obsnight.telescope.longitude*u.deg,obsnight.telescope.latitude*u.deg, obsnight.telescope.elevation*u.m) tel = Observer(location=location, timezone="UTC") target_rise_time = tel.target_rise_time(time,sc,horizon=18*u.deg,which="previous") if target_rise_time: returnstarttime = target_rise_time.isot.split('T')[-1] else: returnstarttime = None return(returnstarttime)
def get_info_of_target(target, created): ra=target.ra dec=target.dec sunrise_horizon=-12 horizon=20 coords = SkyCoord(ra=ra,dec=dec,unit=(u.degree,u.degree)) hanle = EarthLocation(lat=32.77889*u.degree,lon=78.96472*u.degree,height=4500*u.m) iao = Observer(location=hanle, name="GIT", timezone="Asia/Kolkata") twilight_prime = iao.sun_rise_time(Time(datetime.utcnow()),which="next",horizon = sunrise_horizon*u.degree) - 12*u.hour targets_rise_time = iao.target_rise_time(twilight_prime,coords,which="nearest",horizon=horizon*u.degree) targets_set_time = iao.target_set_time(targets_rise_time,coords,which="next",horizon=horizon*u.degree) rise_time_IST = (targets_rise_time + 5.5*u.hour).isot set_time_IST = (targets_set_time + 5.5*u.hour).isot tend = targets_set_time mooncoords = get_moon(tend,hanle) sep = mooncoords.separation(coords) slackmessage="A new target is created target={}: It will rise at {} and set at {} and has moon seperation {}".format(target.name, rise_time_IST ,set_time_IST, sep) message_grbs(slackmessage) print('Target info has been sent') print(target.name, rise_time_IST ,set_time_IST, sep)
class tnsVis(): """ Object visability methods for calculating airmass, lengths of observable time for transient name server objects for different observing locations and dates """ def __init__(self, lat, lon, elevation, ra, dec, discDate, airmassConstraint=2): self.airmassConstraint = airmassConstraint self.altConstraint = math.degrees(math.asin(1 / self.airmassConstraint)) self.location = EarthLocation(lat=lat, lon=lon, height=elevation * u.m) self.discDate = discDate self.observer = Observer(location=self.location, name="LT") self.target = SkyCoord(ra=ra, dec=dec, unit=(u.hourangle, u.deg)) self.constraints = [ AirmassConstraint(self.airmassConstraint), AtNightConstraint.twilight_astronomical() ] print("Discovery Date :", discDate.value) def time_since_discovery(self): """ Returns astropy Time delta object of time since Discovery to time now """ return Time.now() - self.discDate def visible_time(self, date): """ For the evening after the date, specify the visible time within the constraintsself. Not really working at present """ # Find astronomical times for next night darkStart = self.observer.twilight_evening_astronomical(date, which=u'next') darkEnd = self.observer.twilight_morning_astronomical(darkStart, which=u'next') # Find rise and set times riseTime = self.observer.target_rise_time(date, self.target, which=u'next', horizon=self.altConstraint * u.deg) setTime = self.observer.target_set_time(date, self.target, which=u'next', horizon=self.altConstraint * u.deg) if (darkStart.value < riseTime.value) and (darkEnd.value > setTime.value): print("During night") return setTime - riseTime elif (darkStart.value > riseTime.value) and (darkEnd.value > setTime.value): print("Darkstart") elif (darkStart.value < riseTime.value) and (darkEnd.value < setTime.value): print("Darkend") elif (darkStart.value > riseTime.value) and (darkEnd.value < setTime.value): print("DarkstartandEnd") else: print("No Constraints matched!!") def reportDate(self, name): """ Input ATel name and scrape TNS web page for value using regex report the in astropy datetime format?? """ # Find AT or SN name. Seems best to take off 1st 3 characters objectAT = name[3:] print(objectAT) # Pull html down try: page = urllib.request.urlopen( ('https://wis-tns.weizmann.ac.il/object/' + objectAT)) bytes = page.read() text = bytes.decode("utf8") except urllib.error.HTTPError: return ('notFound') # Find the time_received value pattern = re.compile( r'class=\"cell-time_received\">\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d') match = re.findall(pattern, text) if match: # get down to YYYY-MM-DD HH:MM:SS value pattern = re.compile(r'\d\d\d\d\-\d\d-\d\d \d\d:\d\d:\d\d') reportDate = re.findall(pattern, match[0])[0] return reportDate else: return 'notFound' def reportDelay(self, date): """ Input the report date as an astropy Time object return the difference between the discovery and report in units of days """ reportDelay = date - self.discDate print("report : ", date) print("discdate : ", self.discDate) print("report.Delay : ", reportDelay) return reportDelay def plot(self, date): """ Produce plot of the object visability for date Modified from https://docs.astropy.org/en/stable/generated/examples/coordinates/plot_obs-planning.html """ import matplotlib.pyplot as plt from astropy.visualization import astropy_mpl_style plt.style.use(astropy_mpl_style) midnight = self.observer.midnight(date, which='next') delta_midnight = np.linspace(-2, 10, 100) * u.hour frame_night = AltAz(obstime=midnight + delta_midnight, location=self.location) targetaltazs_night = self.target.transform_to(frame_night) # Use `~astropy.coordinates.get_sun` to find the location of the Sun at 1000 from astropy.coordinates import get_sun delta_midnight = np.linspace(-12, 12, 1000) * u.hour times = midnight + delta_midnight frame = AltAz(obstime=times, location=self.location) sunaltazs = get_sun(times).transform_to(frame) # Do the same with `~astropy.coordinates.get_moon` to find when the moon is # up. Be aware that this will need to download a 10MB file from the internet # to get a precise location of the moon. from astropy.coordinates import get_moon moon = get_moon(times) moonaltazs = moon.transform_to(frame) ############################################################################## # Find the alt,az coordinates of M33 at those same times: targetaltazs = self.target.transform_to(frame) ############################################################################## # Make a beautiful figure illustrating nighttime and the altitudes of M33 and # the Sun over that time: plt.plot(delta_midnight, sunaltazs.alt, color='r', label='Sun') plt.plot(delta_midnight, moonaltazs.alt, color=[0.75] * 3, ls='--', label='Moon') plt.scatter(delta_midnight, targetaltazs.alt, c=targetaltazs.az, label='Target', lw=0, s=8, cmap='viridis') plt.fill_between(delta_midnight.to('hr').value, 0, 90, sunaltazs.alt < -0 * u.deg, color='0.5', zorder=0) plt.fill_between(delta_midnight.to('hr').value, 0, 90, sunaltazs.alt < -18 * u.deg, color='k', zorder=0) plt.hlines(self.altConstraint, -12, 12, colors='red', linestyles='dotted', lw=1) plt.colorbar().set_label('Azimuth [deg]') plt.legend(loc='upper left') plt.xlim(-12, 12) plt.xticks(np.arange(13) * 2 - 12) plt.ylim(0, 90) plt.xlabel('Hours from Local Midnight') plt.ylabel('Altitude [deg]') plt.show() def get_info(self, date): """ Prints useful info for a given time, for debugging mainly Alt - Az of target Alt - Az of sun Alt - Az of moon ..... """ return def objVis(self): """ Checks if transit is in between twilight hours. If not return error Returns the amount of time the object is above given airmass """ objVis = is_observable(self.constraints, self.observer, self.target, time_range=(self.discDate, self.discDate + 1 * u.day))[0] return objVis
def get_growthindia_table(json_data, sunrise_hor=-12, horizon=20, priority=10000, domesleep=100): """Make .csv file in GIT toO format for a given .json file""" t = Table(rows=json_data['targets']) coords = SkyCoord(ra=t['ra'], dec=t['dec'], unit=(u.degree, u.degree)) hanle = EarthLocation(lat=32.77889*u.degree, lon=78.96472*u.degree, height=4500*u.m) iao = Observer(location=hanle, name="GIT", timezone="Asia/Kolkata") twilight_prime = iao.sun_rise_time(Time.now(), which="next", horizon=sunrise_hor*u.deg) - 12*u.hour targets_rise_time = iao.target_rise_time(twilight_prime, coords, which="nearest", horizon=horizon*u.degree) targets_set_time = iao.target_set_time(targets_rise_time, coords, which="next", horizon=horizon*u.degree) rise_time_IST = np.array([(targets_rise_time + 5.5*u.hour).isot]) set_time_IST = np.array([(targets_set_time + 5.5*u.hour).isot]) tend = targets_set_time mooncoords = get_moon(tend, hanle) sep = mooncoords.separation(coords) dic = {} dic['x'] = ['']*len(t) dic['u'] = ['']*len(t) dic['g'] = ['']*len(t) dic['r'] = ['']*len(t) dic['i'] = ['']*len(t) dic['z'] = ['']*len(t) target = ['EMGW']*len(t) bands = {1: 'g', 2: 'r', 3: 'i', 4: 'z', 5: 'u'} for i in range(len(t)): filt = bands[t[i]['filter_id']] dic[filt][i] = '1X%i' % (t[i]['exposure_time']) del t['request_id', 'filter_id', 'program_pi', 'program_id', 'subprogram_name', 'exposure_time'] t['field_id'].name = 'tile_id' t['dec'].name = 'Dec' domesleeparr = np.zeros(len(t)) + domesleep priority = np.zeros(len(t)) + priority minalt = AltitudeConstraint(min=horizon*u.degree) always_up = is_always_observable(minalt, iao, coords, Time(twilight_prime, twilight_prime+12*u.hour)) rise_time_IST[np.where(always_up)] = (twilight_prime + 5.5*u.hour).isot set_time_IST[np.where(always_up)] = (twilight_prime + 24*u.hour + 5.5*u.hour).isot ras_format = [] decs_format = [] ras_format = coords.ra.to_string(u.hour, sep=':') decs_format = coords.dec.to_string(u.degree, sep=':') # Add columns t['domesleep'] = domesleeparr t['Priority'] = priority t['dec'] = decs_format t['rise_time_IST'] = rise_time_IST t['set_time_IST'] = set_time_IST t['moon_angle'] = sep t['RA'] = ras_format t['Target'] = target t['x'] = dic['x'] t['u'] = dic['u'] t['g'] = dic['g'] t['r'] = dic['r'] t['i'] = dic['i'] t['z'] = dic['z'] return t
def astroplan_test(): ''' ''' currentDate = time.strftime("%Y-%m-%d") currentTime = time.strftime("%H:%M:%S") print('\n Today is ', currentDate, ' time is ', currentTime, '\n') longitude = '36d56m29.000s' latitude = '+49d38m10.000s' elevation = 156 * u.m location = EarthLocation.from_geodetic(longitude, latitude, elevation) observer = Observer( name='UTR-2 radio telescope', location=location, pressure=0.615 * u.bar, relative_humidity=0.11, temperature=0 * u.deg_C, timezone=timezone('Europe/Kiev'), description= "UTR-2 radio telescope, Volokhiv Yar village Kharkiv region Ukraine") print(' Observer:', observer.name) coordinates = SkyCoord('20h41m25.9s', '+45d16m49.3s', frame='icrs') deneb = FixedTarget(name='Deneb', coord=coordinates) obs_time = Time('2019-08-06 23:00:00') #utr2 = Observer.at_site(observer) #obs_time = Time(currentDate +' '+ currentTime) # Pay attention, not UTC, local time! print(' At', obs_time, ' Night is: ', observer.is_night(obs_time)) print(' Is Deneb on the sky: ', observer.target_is_up(obs_time, deneb)) sunset_tonight = observer.sun_set_time(obs_time, which='nearest') sunrise_tonight = observer.sun_rise_time(obs_time, which='nearest') print(' Sunset:', sunset_tonight.iso, ' Sunrise: ', sunrise_tonight.iso) # Plotting deneb_rise = observer.target_rise_time(obs_time, deneb) + 5 * u.minute deneb_set = observer.target_set_time(obs_time, deneb) - 5 * u.minute print(' Deneb is up from ', deneb_rise, 'till', deneb_set) deneb_style = {'color': 'r'} ''' start = Time('2019-08-06 12:00:00') end = Time('2019-08-07 12:00:00') time_window = start + (end - start) * np.linspace(0, 1, 20) plot_sky(deneb, observer, time_window, style_kwargs=deneb_style) plt.legend(loc='center left', bbox_to_anchor=(1.25, 0.5)) plt.show() ''' start_time = Time('2019-08-06 18:00:00') end_time = Time('2019-08-07 09:00:00') delta_t = end_time - start_time observe_time = start_time + delta_t * np.linspace(0, 1, 75) plot_altitude(deneb, observer, observe_time) plt.grid(b=True, which='both', color='silver', linestyle='-') plt.show() return