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
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
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)
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)