Esempio n. 1
0
def main(argv):

	'''
	Main function. Reads input parameters, run scheduler and stores results.
	'''

	from optparse import OptionParser
	
	parser = OptionParser()

	parser.add_option("-s",'--south_pt',
                      help='''
Input file. This file contains the ra dec for all the tiles. The format is the 
same as the output of tiler.'''
					  ,type="string")
	parser.add_option("-n",'--north_pt',
                      help='''
Input file. This file contains the ra dec for all the tiles. The format is the 
same as the output of tiler.'''
					  ,type="string")

	parser.add_option("-m",'--meteorology',
                      help='''
Input file. This file contains weather information. Only clouded nights need be 
specified. Format is MJD FLAG, where FLAG is 
0 - Good night. Less than 0.5 mag extinction (may be skipped)
1 - Thin Cirrus. Between 0.5 and 2 mag extinction.
2 - Cloudy. Between 2 and 4 mag extinction.
3 - Closed.'''
					  ,type="string")
	parser.add_option("-v", '--verbose',action="store_true", dest="verbose", default=False,
                      help="Don't print status messages to stdout")
    
	opt,arg = parser.parse_args(argv)
			
	#
	# Reading input files
	#

	iis,jjs,ras,decs,rots = np.loadtxt(opt.south_pt,unpack=True,usecols=(0,1,4,5,6))
	
	iin,jjn,ran,decn,rotn = np.loadtxt(opt.north_pt,unpack=True,usecols=(0,1,4,5,6))
	
	ii = np.array(np.append(iis,iin+iis.max()+10),dtype=int)
	jj = np.array(np.append(jjs,jjn),dtype=int)
	ra = np.append(ras,ran)
	dec = np.append(decs,decn)
	
	iciclo = 0
	ncycle = 3
	xcycle = 0
	ntryes = 400
	tryes = 0
	obs = np.array([np.zeros(len(ii))==0,np.zeros(len(ii))==0,np.zeros(len(ii))==0,np.zeros(len(ii))==0])
		
	MJD_dstart = 56294.5
	exptime = 0.01
	
	xx = ii.max()+1
	yy = jj.max()+1
	
	map = np.zeros(xx*yy).reshape(yy,xx)
	for i in range(len(ii)):
		map[jj[i]][ii[i]] = 1.0
	xmap = np.array([map,map,map])

	cmap = colors.ListedColormap(['black', 'gray', 'red', 'blue', 'blue', 'white'])
	bounds=[0,1,2,3,4,5]
	norm = colors.BoundaryNorm(bounds, cmap.N)
	
	#plt.plot(ii,jj,'.')
	fig = plt.figure()
	ax = fig.add_subplot(1,1,1) #[fig.add_subplot(2,2,0),fig.add_subplot(2,2,1),fig.add_subplot(2,2,2),fig.add_subplot(2,2,3)]
	ax = fig.add_axes([0,0,1,1])
	ax.axis("off")

	#for i in range(len(obs)):
	ax.imshow(map,aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
	fig.savefig('map_%04i.png'%0)

	nmap = 1

	no_obsTray = np.zeros(len(obs)) == 1

	for MJD in np.arange(MJD_dstart,MJD_dstart+365.*6):
		nightStart = _skysub.jd_sun_alt(sunMaxAlt, MJD, sitelat, sitelong)
		nightEnd   = _skysub.jd_sun_alt(sunMaxAlt, MJD+0.5, sitelat, sitelong)
	
	
		ramoon = 0.
		decmoon = 0.
		distmoon = 0.
		rasun = 0.
		decsun = 0.
		
		ramoon,decmoon,distmoon = _skysub.lpmoon(nightStart,sitelat,_skysub.lst(nightStart,sitelong))
		
		ill_frac=0.5*(1.-np.cos(_skysub.subtend(ramoon,decmoon,rasun,decsun)))
		
		stdscr.addstr(7, 0, 'Moon illum: %.3f '%(ill_frac))
		stdscr.clrtoeol()
		
		if ill_frac < 0.25:
			iciclo = 0
		elif ill_frac < 0.75:
			iciclo = 1
		elif ill_frac < 0.95:
			iciclo = 2
		else:
			iciclo = -1
		
		stdscr.addstr(0,0,'Observations start at JD = %12.2f'%nightStart)
		stdscr.addstr(1,0,'Observations end at JD   = %12.2f'%nightEnd)

		if iciclo >= 0:

			nobs = len(obs[iciclo][obs[iciclo]])
		
			if len(obs[iciclo][obs[iciclo]]) > 1:
				try:
					obs[iciclo] = make_obs(nightStart,nightEnd,ra,dec,obs[iciclo],exptime)
				except:
					pass
			elif (len(obs[0][obs[0]]) == 0 and len(obs[1][obs[1]]) == 0 and len(obs[2][obs[2]]) == 0 and len(obs[3][obs[3]]) == 0):
				break

			if nobs == len(obs[iciclo][obs[iciclo]]):
				no_obsTray[iciclo] = True
			else:
				no_obsTray[iciclo] = False


			if no_obsTray.all():
				if  tryes > ntryes:
					break
				else:
					tryes+=1
		else:
			stdscr.addstr(7, 20, ' - No observations this night')

		xjj = jj[np.bitwise_not(obs[iciclo])]
		xii = ii[np.bitwise_not(obs[iciclo])]
		for i in range(len(xii)):
			xmap[iciclo][xjj[i]][xii[i]] = 2.0

		xcycle+=1

		#stdscr.addstr(0, 0, "Moving file: {0}".format(filename))
		#stdscr.addstr(1, 0, "Total progress: [{1:10}] {0}%".format(progress * 10, "#" * progress))

		for i in range(ncycle):
			if i == iciclo:
				start = '--> '
			else:
				start = '--- '
			stdscr.addstr(i+3, 0, start+'[Tray: %i] - %4i/%i areas observed'%(i,len(obs[i])-len(obs[i][obs[i]]),len(obs[i])))
		stdscr.refresh()
			#print '[Ciclo: %i] - %i/%i areas observed'%(i,len(obs[i])-len(obs[i][obs[i]]),len(obs[i]))

		#for i in range(len(obs)):
		#	ax[i].cla()
		#	ax[i].imshow(xmap[i],aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
		ax.cla()
		ax.imshow(xmap[0]+xmap[1]+xmap[2]-2,aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
		fig.canvas.draw()
		if not no_obsTray.all():
			fig.savefig('map_%04i.png'%nmap)
		nmap += 1
		#plt.plot(ii,jj,'.')

	print 'Observations started in ',MJD_dstart
	print 'Observations ended in ',MJD
	print 'Survey took %i days'%(MJD-MJD_dstart)
	
	return 0
Esempio n. 2
0
def main(argv):

	'''
	Main function. Reads input parameters, run scheduler and stores results.
	'''

	from optparse import OptionParser
	
	parser = OptionParser()

	parser.add_option("-s",'--south_pt',
                      help='''
Input file. This file contains the ra dec for all the tiles. The format is the 
same as the output of tiler.'''
					  ,type="string")
	parser.add_option("-n",'--north_pt',
                      help='''
Input file. This file contains the ra dec for all the tiles. The format is the 
same as the output of tiler.'''
					  ,type="string")

	parser.add_option("-m",'--meteorology',
                      help='''
Input file. This file contains weather information. Only clouded nights need be 
specified. Format is MJD FLAG, where FLAG is 
0 - Good night. Less than 0.5 mag extinction (may be skipped)
1 - Thin Cirrus. Between 0.5 and 2 mag extinction.
2 - Cloudy. Between 2 and 4 mag extinction.
3 - Closed.'''
					  ,type="string")
	parser.add_option("-v", '--verbose',action="store_true", dest="verbose", default=False,
                      help="Don't print status messages to stdout")
    
	opt,arg = parser.parse_args(argv)
			
	#
	# Reading input files
	#

	_path = os.path.expanduser('~/Develop/SMAPs/coordinatesystemandtiling/')

	sna_file = os.path.join(_path,'smaps_pointT80norte.dat')
	ssa_file = os.path.join(_path,'smaps_pointsulT80.dat')

	iis,jjs,ras,decs,rots = np.loadtxt(sna_file,unpack=True,usecols=(0,1,4,5,6))
	
	iin,jjn,ran,decn,rotn = np.loadtxt(ssa_file,unpack=True,usecols=(0,1,4,5,6))
	
	ii = np.array(np.append(iis,iin+iis.max()+10),dtype=int)
	jj = np.array(np.append(jjs,jjn),dtype=int)
	ra = np.append(ras,ran)
	dec = np.append(decs,decn)
	
	# Store maximum altitude of tiles
	maxAltit = np.array([_skysub.altit(dec[j],0.,sitelat)[0] for j in range(len(ra))])
	
	iciclo = 0
	ncycle = 2
	xcycle = 0
	ntryes = 400
	tryes = 0
	obs = np.array([np.zeros(len(ii))==0,np.zeros(len(ii))==0,np.zeros(len(ii))==0,np.zeros(len(ii))==0])
		
	MJD_dstart = aux.mjd(2014,01,01) # 01/jan/2014

	exptime = [0.003,0.024]
	
	xx = ii.max()+1
	yy = jj.max()+1
	
	map = np.zeros(xx*yy).reshape(yy,xx)
	for i in range(len(ii)):
		map[jj[i]][ii[i]] = 1.0
	xmap = np.array([map,map,map])

	cmap = colors.ListedColormap(['black', 'gray', 'red','white','white'])
	bounds=[0,1,2,3,4]
	norm = colors.BoundaryNorm(bounds, cmap.N)
	
	#plt.plot(ii,jj,'.')
	fig = plt.figure()
	ax = fig.add_subplot(1,1,1) #[fig.add_subplot(2,2,0),fig.add_subplot(2,2,1),fig.add_subplot(2,2,2),fig.add_subplot(2,2,3)]
	ax = fig.add_axes([0,0,1,1])
	ax.axis("off")

	#for i in range(len(obs)):
	ax.imshow(map,aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
	fig.savefig('xmap_%04i.png'%0)

	nmap = 1

	no_obsTray = np.zeros(len(obs)) == 1
	
	fp = open('surveysim_02.dat','w')

	for MJD in np.arange(MJD_dstart,MJD_dstart+365.*2):
		nightStart = _skysub.jd_sun_alt(sunMaxAlt,2400000.5+MJD+1.0, sitelat, sitelong)
		nightEnd   = _skysub.jd_sun_alt(sunMaxAlt,2400000.5+MJD+1.5, sitelat, sitelong)
	
		ramoon = 0.
		decmoon = 0.
		distmoon = 0.
		rasun = 0.
		decsun = 0.
		
		ramoon,decmoon,distmoon = _skysub.lpmoon(nightStart,sitelat,_skysub.lst(nightStart,sitelong))
		
		ill_frac=0.5*(1.-np.cos(_skysub.subtend(ramoon,decmoon,rasun,decsun)))
		
		stdscr.addstr(7, 0, 'Moon illum: %.3f '%(ill_frac))
		stdscr.clrtoeol()
		
		if ill_frac < 0.95:
			iciclo = 0
		else:
			iciclo = -1
		
		stdscr.addstr(0,0,'Observations start at JD = %12.2f'%nightStart)
		stdscr.addstr(1,0,'Observations end at JD   = %12.2f'%nightEnd)
		xnobs=0
		if iciclo >= 0:

			nobs = len(obs[iciclo][obs[iciclo]])

			try:
				obs[iciclo],xnobs,tnobs,emptyObsSlots = make_obs(nightStart,nightEnd,ra,dec,obs[iciclo],exptime[iciclo],maxAltit)
				
				fp.write('%10.2f %6.3f %4i %4i '%(nightStart,nightEnd-nightStart,xnobs,tnobs))
				xnobs = 0
				tnobs = len(emptyObsSlots)
				
				if len(emptyObsSlots) > 0:
					obs[iciclo+1],xnobs,tnobs,emptyObsSlots = make_obs(nightStart,nightEnd,ra,dec,obs[iciclo+1],exptime[iciclo+1],maxAltit)
				fp.write('%4i %4i\n'%(xnobs,tnobs))
				
			except:
				#stdscr.addstr(8,0,sys.exc_info()[0])
				errinfo = traceback.format_exc(sys.exc_info()[2]).split('\n')
				for ierr in range(len(errinfo)):
					stdscr.addstr(11+ierr,0,errinfo[ierr])
				pass

			if nobs == len(obs[iciclo][obs[iciclo]]):
				no_obsTray[iciclo] = True
			else:
				no_obsTray[iciclo] = False


			if no_obsTray.all():
				if  tryes > ntryes:
					break
				else:
					tryes+=1

		else:
			fp.write('%10.2f %6.3f %4i %4i 0 0\n'%(nightStart,nightEnd-nightStart,0.,len(np.arange(nightStart,nightEnd,exptime[iciclo]))))
			stdscr.addstr(7, 20, ' - No observations this night')
		stdscr.addstr(2, 0, ' Observed %i '%(xnobs))
		xjj = jj[np.bitwise_not(obs[iciclo])]
		xii = ii[np.bitwise_not(obs[iciclo])]
		for i in range(len(xii)):
			xmap[iciclo][xjj[i]][xii[i]] = 2.0
		xjj = jj[np.bitwise_not(obs[iciclo+1])]
		xii = ii[np.bitwise_not(obs[iciclo+1])]
		for i in range(len(xii)):
			xmap[iciclo+1][xjj[i]][xii[i]] = 2.0

		xcycle+=1

		#stdscr.addstr(0, 0, "Moving file: {0}".format(filename))
		#stdscr.addstr(1, 0, "Total progress: [{1:10}] {0}%".format(progress * 10, "#" * progress))

		alldone = np.zeros(ncycle) == 1
		for i in range(ncycle):
			if i == iciclo:
				start = '--> '
			else:
				start = '--- '
			stdscr.addstr(i+3, 0, start+'[Tray: %i] - %4i/%i areas observed'%(i,len(obs[i])-len(obs[i][obs[i]]),len(obs[i])))
			alldone[i] = len(obs[i][obs[i]]) == 0
		stdscr.refresh()

			#print '[Ciclo: %i] - %i/%i areas observed'%(i,len(obs[i])-len(obs[i][obs[i]]),len(obs[i]))
		#for i in range(len(obs)):
		#	ax[i].cla()
		#	ax[i].imshow(xmap[i],aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
		ax.cla()
		ax.imshow(xmap[0]+xmap[1]-1,aspect='auto',interpolation='nearest',cmap=cmap, norm=norm)
		fig.canvas.draw()
		if not no_obsTray.all():
			fig.savefig('ymap_%04i.png'%nmap)
		nmap += 1
		#plt.plot(ii,jj,'.')
		if alldone.all():
			break

	fp.close()
	print 'Observations started in ',MJD_dstart
	print 'Observations ended in ',MJD
	print 'Survey took %i days'%(MJD-MJD_dstart)
	
	return 0
Esempio n. 3
0
	def makeObs(self,T0,T1):
			
		time = T0
		hd = 1./24
		maskRep = []
		if self._nrepeat > 0:
			maskRep = np.bitwise_and(self.repeatInfo['day'] > 0,self.repeatInfo['nobs'] < self._nrepeat)
		else:
			maskRep = self.repeatInfo['day'] > 0

		info = ['Observations start @ JD = %12.2f'%T0,
				'Observations end   @ JD = %12.2f'%T1,
				'Total number of tiles: %5i'%self.nTiles(),
				'Tiles to observe: %5i'%(self.obsTiles()),
				'Tiles to repeate: %5i'%(len(maskRep[maskRep])) ]
		
		# count time spent observing each tray
		obsTime = np.zeros(self.ntrays+1)

		# Calculate moon for this night
		queue = []
		ramoon = 0.
		decmoon = 0.
		distmoon = 0.
		rasun = 0.
		decsun = 0.
		
		ramoon,decmoon,distmoon = _skysub.lpmoon(T0,self.sitelat,_skysub.lst(T0,self.sitelong))
		
		ill_frac=0.5*(1.-np.cos(_skysub.subtend(ramoon,decmoon,rasun,decsun)))
		
		fullmoon = False
		if ill_frac >= self.fullmoon:
			fullmoon = True
			info.append('Full moon (%5.1f)'%(ill_frac*100))
			obsTime[-1] = (T1-T0)
		else:
			info.append('Moon %5.1f       '%(ill_frac*100.))
		
		cra = -99
		cdec = -99
		
		while time < T1 and not fullmoon:
		
			obsDone = False
			tray = 0
			obsTile = -1
			# Trying the first tray

			while ( (not obsDone) and (0 <= tray < self.ntrays) ):
			
				# Local Sidereal time at start -2hours and end +2hours
				lst_start = _skysub.lst(time-2.*hd,self.sitelong)
				lst_end = _skysub.lst(time+self.exptime[tray]+2.*hd,self.sitelong)
				
				# Check if there is observation to be repeated this night.
				if self._nrepeat > 0:
					maskRep = np.bitwise_and(np.bitwise_and(self.repeatInfo['day'] > 0, self.repeatInfo['day'] <= time),self.repeatInfo['nobs'] < self._nrepeat)
				else:
					maskRep = np.bitwise_and(self.repeatInfo['day'] > 0, self.repeatInfo['day'] <= time)
				
				ra_mask = self.raMask(self._repeatTray,lst_start,lst_end)
				repeated = False
				
				if len(maskRep[maskRep]) > 0:
					ra_tmpmask = np.bitwise_and(ra_mask,maskRep)
					if ra_tmpmask.any():
						# make repeate observation
						index = np.arange(len(self._ra[self._repeatTray]))[ra_tmpmask]
						# Selecting highest in the sky at the center of the observation
						lst = _skysub.lst(time+self.exptime[self._repeatTray]/2.,self.sitelong)*360./24.
					
						ha = (lst - self._ra[self._repeatTray][ra_tmpmask])*24./360.
						alt = np.array([_skysub.altit(self._dec[self._repeatTray][j],ha[i],self.sitelat)[0] for i,j in enumerate(index)])
						if len(alt) == 0:
							info.append('[R] No observable tiles available...')
						else:
							stg = alt.argmax()
							if alt[stg] > self.maxAltit[self._repeatTray][index[stg]]*self.rvfac:
								info.append('[R] Observation complete...     ')
								self.repeatInfo['nobs'][index[stg]] += 1
								self.repeatInfo['day'][index[stg]] += self._dTime
								obsDone = True
								repeated = True
								tray = self._repeatTray
							else:
								info.append('[R] Object too low. Alt = %7.2f, Max Alt = %7.2f...                   '%(alt[stg],self.maxAltit[self._repeatTray][index[stg]]))

				ra_mask = self.raMask(tray,lst_start,lst_end)
				# Check if makes sense to continue
				if ra_mask.any() and not obsDone:

					info.append('Number of observable tiles %4i'%len(ra_mask[ra_mask]))
					
					index = np.arange(len(self._ra[tray]))[np.bitwise_and(ra_mask,self.obs[tray])]
					# Selecting highest in the sky at the center of the observation
					lst = _skysub.lst(time+self.exptime[tray]/2.,self.sitelong)*360./24.
				
					#lst = _skysub.lst(time,sitelong) #*360./24.
					ha = (lst - self._ra[tray][ra_mask])*24./360.
					alt = np.array([_skysub.altit(self._dec[tray][j],ha[i],self.sitelat)[0] for i,j in enumerate(index)])
					
					if len(alt) == 0:
						info.append('No observable tiles available...')
						# Go to next tray
						tray+=1
					else:
						#info.append(['Suitable tile available...'])
						stg = alt.argmax()
						if alt[stg] > self.maxAltit[tray][index[stg]]*self.vfac:
							info.append('Observation complete...     ')
							obsTile = index[stg]
							obsDone = True
							# check if needs to be repeated
							if tray == self._repeatTray and self.repeatInfo['nobs'][index[stg]] < self._nrepeat and self.repeatInfo['day'][index[stg]] < time:
								self.repeatInfo['day'][index[stg]] = time+self._dTime
							elif tray == self._repeatTray and self.repeatInfo['day'][index[stg]] < time and  self._nrepeat < 0:
								self.repeatInfo['day'][index[stg]] = time+self._dTime
						else:
							obsDone = False
							info.append('Object too low. Alt = %7.2f, Max Alt = %7.2f...                   '%(alt[stg],self.maxAltit[tray][index[stg]]*self.vfac))

							# Go to next tray
							tray+=1
				elif repeated:
					tray = -self._repeatTray
				else:
					tray = -1
					info.append('No tiles available...')

			tray = np.abs(tray)
			# Check if observation was performed and in which tray
			if obsDone:
				if repeated:
					obsTime[tray]+=self.rexptime
					time+=self.rexptime
				else:
					obsTime[tray]+=self.exptime[tray]
					time+=self.exptime[tray]
				self.obs[tray][obsTile] = False
				queue.append('TILE%05i %6.2f %+7.2f %16.6f %2i %8.3f'%(obsTile,self._ra[tray][obsTile],self._dec[tray][obsTile],time,tray,self.exptime[tray]))

			else:
				# Try one more time
				# See if there is any field to be repeated in the sky
				maskRep = self.repeatInfo['day'] > 0
				lst_start = _skysub.lst(time-3.*hd,self.sitelong)
				lst_end = _skysub.lst(time+self.rexptime+3.*hd,self.sitelong)
				ra_mask = self.raMask(self._repeatTray,lst_start,lst_end)
				repeated = False
				idx = 0
				if len(maskRep[maskRep]) > 0:
					ra_tmpmask = np.bitwise_and(ra_mask,maskRep)
					
					if ra_tmpmask.any():
						# make repeate observation
						index = np.arange(len(self._ra[self._repeatTray]))[ra_tmpmask]
						# Selecting highest in the sky at the center of the observation
						lst = _skysub.lst(time+self.exptime[self._repeatTray]/2.,self.sitelong)*360./24.
					
						ha = (lst - self._ra[self._repeatTray][ra_tmpmask])*24./360.
						alt = np.array([_skysub.altit(self._dec[self._repeatTray][j],ha[i],self.sitelat)[0] for i,j in enumerate(index)])
						if len(alt) == 0:
							info.append('[R] No observable tiles available...')
						else:
							stg = alt.argmax()
							if alt[stg] > self.maxAltit[self._repeatTray][index[stg]]*self.rvfac:
								info.append('[R] Observation complete...     ')
								self.repeatInfo['nobs'][index[stg]] += 1
								self.repeatInfo['day'][index[stg]] += self._dTime
								obsDone = True
								repeated = True
								tray = -self._repeatTray
								idx = index[stg]
							else:
								obsDone = False
								info.append('[R] Object too low. Alt = %7.2f, Max Alt = %7.2f [RR]...                   '%(alt[stg],self.maxAltit[self._repeatTray][index[stg]]*self.rvfac))
				if obsDone:
					obsTime[self._repeatTray] += self.rexptime
					time+=self.rexptime
				else:
					obsTime[-1] += self.exptime.max()
					time+=self.exptime.max()
		
		queueInfo = '%16.6f %6.3f '%(T0,(T1-T0)*24.)
		for tray in range(len(obsTime)):
			queueInfo += '%10.7f '%(obsTime[tray]*24.)
		return info,queue,queueInfo
Esempio n. 4
0
def subtendang(ra1, dec1, ra2, dec2) :
 # simple wrapper for _skysub.subtend.  To hide dependence on skysub
 # from pyskycal.

	return _skysub.subtend(ra1,dec1,ra2,dec2)
Esempio n. 5
0
	def computesunmoon(self) :
		[ras,decs,dists,toporas,topodecs,xs,ys,zs] = \
			_skysub.accusun(self.jd, self.sidereal.val,self.lat) 
		self.SunCoords = celest([ras,decs,self.julian_epoch()])
		self.hasun = ha(self.sidereal.val - self.SunCoords.ra.val)
		[self.altsun,self.azsun,parangsun] = \
			_skysub.altit(self.SunCoords.dec.val,self.hasun.val,\
				self.lat)
		self.ztwilight = _skysub.ztwilight(self.altsun)

		[georam,geodm,geodism,toporam,topodecm,topodistm] = \
			_skysub.accumoon(self.jd,self.lat,self.sidereal.val,
			   self.elevsea)
		self.MoonCoords = celest([toporam,topodecm,self.julian_epoch()])
		self.hamoon = ha(self.sidereal.val - self.MoonCoords.ra.val)
		[self.altmoon,self.azmoon,parangmoon] = \
			_skysub.altit(self.MoonCoords.dec.val,self.hamoon.val,\
				self.lat)
		self.sun_moon = _skysub.subtend(self.MoonCoords.ra.val,  
			self.MoonCoords.dec.val,self.SunCoords.ra.val,
			self.SunCoords.dec.val) # radians
		self.moonillfrac = 0.5 * (1. - math.cos(self.sun_moon))
		self.sun_moon = self.sun_moon * _skysub.DEG_IN_RADIAN
		self.obj_moon = _skysub.subtend(self.MoonCoords.ra.val,
			self.MoonCoords.dec.val,self.CoordsOfDate.ra.val,
			self.CoordsOfDate.dec.val) * _skysub.DEG_IN_RADIAN
		self.lunsky = _skysub.lunskybright(self.sun_moon,
			self.obj_moon,0.17,self.altmoon,self.altit,topodistm)
		[self.barytcor, self.baryvcor] = _skysub.helcor(self.jd,self.CoordsOfDate.ra.val,
		   self.CoordsOfDate.dec.val,self.hanow.val,self.lat,self.elevsea)
		self.baryjd = self.jd + self.barytcor / _skysub.SEC_IN_DAY

		# find the jd at the nearest clock-time midnight ... 
		localtimestr = self.calstring(stdz = self.stdz, use_dst = self.use_dst)
		x = string.split(localtimestr)
		ymd = x[0] + " " + x[1] + " " + x[2]
		if float(x[3]) >= 12. :
			midnstring = ymd + " 23 59 59.99"
		else :
			midnstring = ymd + " 0 0 0 "
		self.jdmid = time_to_jd(midnstring, stdz = self.stdz, \
			use_dst = self.use_dst)
		self.stmid = ra( _skysub.lst(self.jdmid,self.longit))

		# elevation correction (in degrees) for horizon depression
		horiz = math.sqrt(2. * self.elevhoriz / _skysub.EQUAT_RAD) \
			 * _skysub.DEG_IN_RADIAN
		setelev = -1. * (0.83 + horiz)

		hasunset = _skysub.ha_alt(self.SunCoords.dec.val,self.lat,setelev)
	
		if hasunset > 900.  : 
			self.jdsunset = 1000.  # never sets
			self.jdsunrise = 1000.
			self.jdcent = 1000.
		elif hasunset < -900.  : 
			self.jdsunset = -1000.  # never rises
			self.jdsunrise = -1000.
			self.jdcent = -1000.
		else :
		    self.jdsunset = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
			+ hasunset - self.stmid.val)/24.  # initial guess
		    # print "entering jdsunset - self.jdsunset = ",self.jdsunset,
		    self.jdsunset = _skysub.jd_sun_alt(setelev,self.jdsunset,self.lat, \
			self.longit)
		    self.jdsunrise = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
			- hasunset - self.stmid.val)/24.  # initial guess
		    self.jdsunrise = _skysub.jd_sun_alt(setelev,self.jdsunrise,self.lat, \
			self.longit)

		    self.jdcent = (self.jdsunset + self.jdsunrise) / 2.

		hatwilight = _skysub.ha_alt(self.SunCoords.dec.val, self.lat, -18.)

		if hatwilight > 900. : 
			self.jdevetwi = 1000.   # never gets dark
			self.jdmorntwi = 1000. 
		elif hatwilight < -900. :  
			self.jdevetwi = -1000.  # never gets light
			self.jdmorntwi = -1000.  
		
		else :
		    self.jdevetwi = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
			+ hatwilight - self.stmid.val)/24.  # initial guess
		    self.jdevetwi = _skysub.jd_sun_alt(-18.,self.jdevetwi,self.lat, \
			self.longit)
		    self.jdmorntwi = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
			- hatwilight - self.stmid.val)/24.  # initial guess
		    self.jdmorntwi = _skysub.jd_sun_alt(-18.,self.jdmorntwi,self.lat, \
			self.longit)

		[ramoonmid,decmoonmid,distmoonmid] = \
		   _skysub.lpmoon(self.jdmid,self.lat,self.sidereal.val)
		[minmoonalt,maxmoonalt] = _skysub.min_max_alt(self.lat,decmoonmid)
		# rough (close enough) check to see if moonrise or moonset occur ... 
		if maxmoonalt < setelev :
			self.jdmoonrise = -100.  # never rises
			# -1000. is used later to signal non-convergence
			self.jdmoonset = -100.
		if minmoonalt > setelev :
			self.jdmoonrise = 100. # never sets
			self.jdmoonset = 100.
		else :
		    hamoonset = _skysub.ha_alt(decmoonmid,self.lat,setelev)
		    tmoonrise = _skysub.adj_time(ramoonmid - hamoonset - self.stmid.val)
		    tmoonset = _skysub.adj_time(ramoonmid + hamoonset - self.stmid.val)
		    self.jdmoonrise = self.jdmid + tmoonrise / 24.
		    self.jdmoonrise = _skysub.jd_moon_alt(setelev,self.jdmoonrise, \
			self.lat,self.longit,self.elevsea)
		    self.jdmoonset = self.jdmid + tmoonset / 24.
		    self.jdmoonset = _skysub.jd_moon_alt(setelev,self.jdmoonset,self.lat, \
			self.longit,self.elevsea)

		[self.par_dra,self.par_ddec,self.aber_dra,self.aber_ddec] = \
			_skysub.parellipse(self.jd,self.ra.val,self.dec.val,self.equinox,
					self.lat,self.longit)
Esempio n. 6
0
    def computesunmoon(self):
        [ras,decs,dists,toporas,topodecs,xs,ys,zs] = \
         _skysub.accusun(self.jd, self.sidereal.val,self.lat)
        self.SunCoords = celest([ras, decs, self.julian_epoch()])
        self.hasun = ha(self.sidereal.val - self.SunCoords.ra.val)
        [self.altsun,self.azsun,parangsun] = \
         _skysub.altit(self.SunCoords.dec.val,self.hasun.val,\
          self.lat)
        self.ztwilight = _skysub.ztwilight(self.altsun)

        [georam,geodm,geodism,toporam,topodecm,topodistm] = \
         _skysub.accumoon(self.jd,self.lat,self.sidereal.val,
            self.elevsea)
        self.MoonCoords = celest([toporam, topodecm, self.julian_epoch()])
        self.hamoon = ha(self.sidereal.val - self.MoonCoords.ra.val)
        [self.altmoon,self.azmoon,parangmoon] = \
         _skysub.altit(self.MoonCoords.dec.val,self.hamoon.val,\
          self.lat)
        self.sun_moon = _skysub.subtend(self.MoonCoords.ra.val,
                                        self.MoonCoords.dec.val,
                                        self.SunCoords.ra.val,
                                        self.SunCoords.dec.val)  # radians
        self.moonillfrac = 0.5 * (1. - math.cos(self.sun_moon))
        self.sun_moon = self.sun_moon * _skysub.DEG_IN_RADIAN
        self.obj_moon = _skysub.subtend(
            self.MoonCoords.ra.val, self.MoonCoords.dec.val,
            self.CoordsOfDate.ra.val,
            self.CoordsOfDate.dec.val) * _skysub.DEG_IN_RADIAN
        self.lunsky = _skysub.lunskybright(self.sun_moon, self.obj_moon, 0.17,
                                           self.altmoon, self.altit, topodistm)
        [self.barytcor,
         self.baryvcor] = _skysub.helcor(self.jd, self.CoordsOfDate.ra.val,
                                         self.CoordsOfDate.dec.val,
                                         self.hanow.val, self.lat,
                                         self.elevsea)
        self.baryjd = self.jd + self.barytcor / _skysub.SEC_IN_DAY

        # find the jd at the nearest clock-time midnight ...
        localtimestr = self.calstring(stdz=self.stdz, use_dst=self.use_dst)
        x = string.split(localtimestr)
        ymd = x[0] + " " + x[1] + " " + x[2]
        if float(x[3]) >= 12.:
            midnstring = ymd + " 23 59 59.99"
        else:
            midnstring = ymd + " 0 0 0 "
        self.jdmid = time_to_jd(midnstring, stdz = self.stdz, \
         use_dst = self.use_dst)
        self.stmid = ra(_skysub.lst(self.jdmid, self.longit))

        # elevation correction (in degrees) for horizon depression
        horiz = math.sqrt(2. * self.elevhoriz / _skysub.EQUAT_RAD) \
          * _skysub.DEG_IN_RADIAN
        setelev = -1. * (0.83 + horiz)

        hasunset = _skysub.ha_alt(self.SunCoords.dec.val, self.lat, setelev)

        if hasunset > 900.:
            self.jdsunset = 1000.  # never sets
            self.jdsunrise = 1000.
            self.jdcent = 1000.
        elif hasunset < -900.:
            self.jdsunset = -1000.  # never rises
            self.jdsunrise = -1000.
            self.jdcent = -1000.
        else:
            self.jdsunset = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
         + hasunset - self.stmid.val)/24.  # initial guess
            # print "entering jdsunset - self.jdsunset = ",self.jdsunset,
            self.jdsunset = _skysub.jd_sun_alt(setelev,self.jdsunset,self.lat, \
         self.longit)
            self.jdsunrise = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
         - hasunset - self.stmid.val)/24.  # initial guess
            self.jdsunrise = _skysub.jd_sun_alt(setelev,self.jdsunrise,self.lat, \
         self.longit)

            self.jdcent = (self.jdsunset + self.jdsunrise) / 2.

        hatwilight = _skysub.ha_alt(self.SunCoords.dec.val, self.lat, -18.)

        if hatwilight > 900.:
            self.jdevetwi = 1000.  # never gets dark
            self.jdmorntwi = 1000.
        elif hatwilight < -900.:
            self.jdevetwi = -1000.  # never gets light
            self.jdmorntwi = -1000.

        else:
            self.jdevetwi = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
         + hatwilight - self.stmid.val)/24.  # initial guess
            self.jdevetwi = _skysub.jd_sun_alt(-18.,self.jdevetwi,self.lat, \
         self.longit)
            self.jdmorntwi = self.jdmid + _skysub.adj_time(self.SunCoords.ra.val \
         - hatwilight - self.stmid.val)/24.  # initial guess
            self.jdmorntwi = _skysub.jd_sun_alt(-18.,self.jdmorntwi,self.lat, \
         self.longit)

        [ramoonmid,decmoonmid,distmoonmid] = \
           _skysub.lpmoon(self.jdmid,self.lat,self.sidereal.val)
        [minmoonalt, maxmoonalt] = _skysub.min_max_alt(self.lat, decmoonmid)
        # rough (close enough) check to see if moonrise or moonset occur ...
        if maxmoonalt < setelev:
            self.jdmoonrise = -100.  # never rises
            # -1000. is used later to signal non-convergence
            self.jdmoonset = -100.
        if minmoonalt > setelev:
            self.jdmoonrise = 100.  # never sets
            self.jdmoonset = 100.
        else:
            hamoonset = _skysub.ha_alt(decmoonmid, self.lat, setelev)
            tmoonrise = _skysub.adj_time(ramoonmid - hamoonset -
                                         self.stmid.val)
            tmoonset = _skysub.adj_time(ramoonmid + hamoonset - self.stmid.val)
            self.jdmoonrise = self.jdmid + tmoonrise / 24.
            self.jdmoonrise = _skysub.jd_moon_alt(setelev,self.jdmoonrise, \
         self.lat,self.longit,self.elevsea)
            self.jdmoonset = self.jdmid + tmoonset / 24.
            self.jdmoonset = _skysub.jd_moon_alt(setelev,self.jdmoonset,self.lat, \
         self.longit,self.elevsea)

        [self.par_dra,self.par_ddec,self.aber_dra,self.aber_ddec] = \
         _skysub.parellipse(self.jd,self.ra.val,self.dec.val,self.equinox,
           self.lat,self.longit)
Esempio n. 7
0
def subtendang(ra1, dec1, ra2, dec2):
    # simple wrapper for _skysub.subtend.  To hide dependence on skysub
    # from pyskycal.

    return _skysub.subtend(ra1, dec1, ra2, dec2)