Пример #1
0
	def day_of_year(self,stdz = 0.,use_dst = 0) :

		# returns floating-point time since "Jan 0" at 0h.
		# JD should be a true UT jd given how it's initialized,
		# providing stdz and use_dst adjusts day_of_year to local.

		x = self.caldat(stdz,use_dst)
		v = _skysub.new_date_time()
		_skysub.date_time_y_set(v,float(x[0]))
		_skysub.date_time_mo_set(v,1)
		_skysub.date_time_d_set(v,1)
		_skysub.date_time_h_set(v,0)
		_skysub.date_time_mn_set(v,0)
		_skysub.date_time_s_set(v,0)
		jdjan1 = _skysub.date_to_jd(v)
		_skysub.delete_date_time(v)

		return self.jd - jdjan1 + 1.   # anything on Jan 1 is 1.xxx 
Пример #2
0
    def day_of_year(self, stdz=0., use_dst=0):

        # returns floating-point time since "Jan 0" at 0h.
        # JD should be a true UT jd given how it's initialized,
        # providing stdz and use_dst adjusts day_of_year to local.

        x = self.caldat(stdz, use_dst)
        v = _skysub.new_date_time()
        _skysub.date_time_y_set(v, float(x[0]))
        _skysub.date_time_mo_set(v, 1)
        _skysub.date_time_d_set(v, 1)
        _skysub.date_time_h_set(v, 0)
        _skysub.date_time_mn_set(v, 0)
        _skysub.date_time_s_set(v, 0)
        jdjan1 = _skysub.date_to_jd(v)
        _skysub.delete_date_time(v)

        return self.jd - jdjan1 + 1.  # anything on Jan 1 is 1.xxx
Пример #3
0
def jd2cal(jdin, stdz = 0.,use_dst = 0,jd_override = 0.) :

	# jd_override is basically a switch not to use jdin for 
 	# the calculation -- if it's > 100000, it overrides jdin

	if jd_override > 1000000. :
		jdin = jd_override

	# need to find year to get jd's of beginning and end of dst
	v = _skysub.new_date_time()
	jdwork = jdin - stdz / 24.  # local jd, without dst
	dow = _skysub.caldat(jdwork,v)
	y = _skysub.date_time_y_get(v)   # again without dst

	# There's a possible problem about daylight savings time around
	# the turn of the year ... 

	if use_dst != 0 :
		#print "jdwork ",jdwork,"year y", y
		#sys.exit()  # needed to catch a runaway in true_jd.
		
		[jdb,jde] = _skysub.find_dst_bounds(y,stdz,use_dst)
		# print "year",y,"jdb",jdb,"jde",jde
		# print "jdin, jdwork  = ",jdin,jdwork
		# jdb, jde are real jds, so compare to real input jd.	
		offset = _skysub.zone(use_dst,stdz,jdin,jdb,jde) / 24.
		# print "offset ",offset
	else :
		offset = stdz / 24.

	jdwork = jdin - offset
	dow = _skysub.caldat(jdwork,v)
	y = _skysub.date_time_y_get(v)
	mo = _skysub.date_time_mo_get(v)
	d = _skysub.date_time_d_get(v)
	h = _skysub.date_time_h_get(v)
	mn = _skysub.date_time_mn_get(v)
	s = _skysub.date_time_s_get(v)
	_skysub.delete_date_time(v)
	return [y,mo,d,h,mn,s,dow,stdz,use_dst,offset]
Пример #4
0
def jd2cal(jdin, stdz=0., use_dst=0, jd_override=0.):

    # jd_override is basically a switch not to use jdin for
    # the calculation -- if it's > 100000, it overrides jdin

    if jd_override > 1000000.:
        jdin = jd_override

    # need to find year to get jd's of beginning and end of dst
    v = _skysub.new_date_time()
    jdwork = jdin - stdz / 24.  # local jd, without dst
    dow = _skysub.caldat(jdwork, v)
    y = _skysub.date_time_y_get(v)  # again without dst

    # There's a possible problem about daylight savings time around
    # the turn of the year ...

    if use_dst != 0:
        #print "jdwork ",jdwork,"year y", y
        #sys.exit()  # needed to catch a runaway in true_jd.

        [jdb, jde] = _skysub.find_dst_bounds(y, stdz, use_dst)
        # print "year",y,"jdb",jdb,"jde",jde
        # print "jdin, jdwork  = ",jdin,jdwork
        # jdb, jde are real jds, so compare to real input jd.
        offset = _skysub.zone(use_dst, stdz, jdin, jdb, jde) / 24.
        # print "offset ",offset
    else:
        offset = stdz / 24.

    jdwork = jdin - offset
    dow = _skysub.caldat(jdwork, v)
    y = _skysub.date_time_y_get(v)
    mo = _skysub.date_time_mo_get(v)
    d = _skysub.date_time_d_get(v)
    h = _skysub.date_time_h_get(v)
    mn = _skysub.date_time_mn_get(v)
    s = _skysub.date_time_s_get(v)
    _skysub.delete_date_time(v)
    return [y, mo, d, h, mn, s, dow, stdz, use_dst, offset]
Пример #5
0
def time_to_jd(instuff = "NOW",stdz = 0.,use_dst = 0) :
	
	v = _skysub.new_date_time()

	if type(instuff) == ListType or type(instuff) == TupleType :
		yr = float(instuff[0])
		if yr < 1901 or yr > 2099 :
			print "Outside calendrical range, no action."
			_skysub.delete_date_time(v)
			return -1.
		try :
		   mo = float(instuff[1])
		except ValueError :
		   mo = getmonth(instuff[1])
                   if mo == 0 :
                              printx('Illegal month name!!')
		dd = float(instuff[2])

		hh = 0.  # in case they aren't passed in 
		mm = 0.
		ss = 0.
			
		if len(instuff) > 3 :
		   try :
		      if string.find(instuff[3],":") > -1 : # colon-ized
		         temptup = string.split(instuff[3],":")
                         instuff[3] = temptup[0]
		         instuff = instuff + [temptup[1]]
		      if len(temptup) > 2 :
                                    instuff = instuff + [temptup[2]]
		      hh = float(instuff[3])
		   except :
		      hh= float(instuff[3])
		if len(instuff) > 4 :	
		   mm = float(instuff[4])
		if len(instuff) > 5 :
		   ss = float(instuff[5])

		_skysub.date_time_y_set(v,yr)
		_skysub.date_time_mo_set(v,mo)
		_skysub.date_time_d_set(v,dd)
		_skysub.date_time_h_set(v,hh)
		_skysub.date_time_mn_set(v,mm)
		_skysub.date_time_s_set(v,ss)

	elif type(instuff) == StringType :  # it's a string ...
        #        print "instuff ",instuff,"type and StrTy",type(instuff),StringType
		if string.find(instuff,"NOW") > -1 :
			_skysub.get_sys_date(v,0,0,0,0,0)
		else :	
			# de-colonize
			instuff = string.replace(instuff,":"," ")
			instuff = string.replace(instuff,","," ")
			# time given as y m d h m s
			x = string.split(instuff)
			# allow low-order fields to be omitted .. 
				# fill in here
			while len(x) < 6 :
				x = x + [0.]
			# wacky interface to struct date_time in 
					# skysub

			try :
				mo = float(x[1])
			except ValueError :
				mo = getmonth(x[1])

			y = float(x[0])
			if y < 1901 or y > 2099 :
				print "Outside calendrical limits."
				_skysub.delete_date_time(v)
				return -1.
			_skysub.date_time_y_set(v,y)
			_skysub.date_time_mo_set(v,mo)
			_skysub.date_time_d_set(v,float(x[2]))
			_skysub.date_time_h_set(v,float(x[3]))
			_skysub.date_time_mn_set(v,float(x[4]))
			_skysub.date_time_s_set(v,float(x[5]))

	elif type(instuff) == FloatType :	
	# it better be just a JD by itself ... 
		z = float(instuff)
		if z > 1.0e6 :  # it's a JD
			if z > 2415388. and z < 2488069 :
				jdin = z
			else :
				print "JD out of valid range."
				_skysub.delete_date_time(v)
				return -1.
		elif z < 5000. :  # it's a year
			jdin = _skysub.J2000 + \
				365.25 * (z - 2000.) 
		dow = _skysub.caldat(jdin,v)

	else :
		print "ERROR: Can't initialize 'instant' from given info."

	# v is now loaded with the date derived from input jd ... 
	# Now that input info is parsed, let's set the REAL jd:
	
	jd = _skysub.true_jd(v,use_dst,0,0,stdz)
	_skysub.delete_date_time(v)
	
	return(jd)
Пример #6
0
def time_to_jd(instuff="NOW", stdz=0., use_dst=0):

    v = _skysub.new_date_time()

    if type(instuff) == ListType or type(instuff) == TupleType:
        yr = float(instuff[0])
        if yr < 1901 or yr > 2099:
            print "Outside calendrical range, no action."
            _skysub.delete_date_time(v)
            return -1.
        try:
            mo = float(instuff[1])
        except ValueError:
            mo = getmonth(instuff[1])
            if mo == 0:
                printx('Illegal month name!!')
        dd = float(instuff[2])

        hh = 0.  # in case they aren't passed in
        mm = 0.
        ss = 0.

        if len(instuff) > 3:
            try:
                if string.find(instuff[3], ":") > -1:  # colon-ized
                    temptup = string.split(instuff[3], ":")
                    instuff[3] = temptup[0]
                    instuff = instuff + [temptup[1]]
                if len(temptup) > 2:
                    instuff = instuff + [temptup[2]]
                hh = float(instuff[3])
            except:
                hh = float(instuff[3])
        if len(instuff) > 4:
            mm = float(instuff[4])
        if len(instuff) > 5:
            ss = float(instuff[5])

        _skysub.date_time_y_set(v, int(yr))
        _skysub.date_time_mo_set(v, int(mo))
        _skysub.date_time_d_set(v, int(dd))
        _skysub.date_time_h_set(v, int(hh))
        _skysub.date_time_mn_set(v, int(mm))
        _skysub.date_time_s_set(v, ss)

    elif type(instuff) == StringType:  # it's a string ...
        #        print "instuff ",instuff,"type and StrTy",type(instuff),StringType
        if string.find(instuff, "NOW") > -1:
            _skysub.get_sys_date(v, 0, 0, 0, 0, 0)
        else:
            # de-colonize
            instuff = string.replace(instuff, ":", " ")
            instuff = string.replace(instuff, ",", " ")
            # time given as y m d h m s
            x = string.split(instuff)
            # allow low-order fields to be omitted ..
            # fill in here
            while len(x) < 6:
                x = x + [0.]
            # wacky interface to struct date_time in
            # skysub

            try:
                mo = float(x[1])
            except ValueError:
                mo = getmonth(x[1])

            y = float(x[0])
            if y < 1901 or y > 2099:
                print "Outside calendrical limits."
                _skysub.delete_date_time(v)
                return -1.
            _skysub.date_time_y_set(v, int(y))
            _skysub.date_time_mo_set(v, int(mo))
            _skysub.date_time_d_set(v, int(x[2]))
            _skysub.date_time_h_set(v, int(x[3]))
            _skysub.date_time_mn_set(v, int(x[4]))
            _skysub.date_time_s_set(v, float(x[5]))

    elif type(instuff) == FloatType:
        # it better be just a JD by itself ...
        z = float(instuff)
        if z > 1.0e6:  # it's a JD
            if z > 2415388. and z < 2488069:
                jdin = z
            else:
                print "JD out of valid range."
                _skysub.delete_date_time(v)
                return -1.
        elif z < 5000.:  # it's a year
            jdin = _skysub.J2000 + \
             365.25 * (z - 2000.)
        dow = _skysub.caldat(jdin, v)

    else:
        print "ERROR: Can't initialize 'instant' from given info."

    # v is now loaded with the date derived from input jd ...
    # Now that input info is parsed, let's set the REAL jd:

    jd = _skysub.true_jd(v, use_dst, 0, 0, stdz)
    _skysub.delete_date_time(v)

    return (jd)