diff --git a/Server.py b/Server.py index fe15728..f544f7a 100644 --- a/Server.py +++ b/Server.py @@ -5,9 +5,9 @@ from Astronomy import * #Define Area class APICore(object): HTTPHead={ - '200':'HTTP/1.1 200 OK\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n', - '400':'HTTP/1.1 400 BAD REQUEST\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n', - '404':'HTTP/1.1 404 NOT FOUND\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n' + '200':'HTTP/1.1 200 OK\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n', + '400':'HTTP/1.1 400 BAD REQUEST\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n', + '404':'HTTP/1.1 404 NOT FOUND\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n' } def __init__(self): self.__Log=[] @@ -108,6 +108,7 @@ def socket(sock,addr): #No Parameter sock.send(API.HTTPHead['200'].encode("utf-8")) API.SunAzEl(sock,addr) + break elif("POST " in data.decode("utf-8")): #POST Request try: @@ -133,7 +134,7 @@ def socket(sock,addr): else: #Wrong POST Parameter,Return Bad Request API.Error400(sock,addr) - break + break else: #No Such Command sock.send(API.HTTPHead['404'].encode("utf8")) @@ -183,21 +184,6 @@ def socket(sock,addr): API.Log(addr[0],addr[1],"STATUS","Wrong code mode,must be utf-8.") API.Log(addr[0],addr[1],"STATUS","Lost connection.") break -def _async_raise(tid, exctype): - """raises the exception, performs cleanup if needed""" - tid = ctypes.c_long(tid) - if not inspect.isclass(exctype): - exctype = type(exctype) - res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) - if res == 0: - raise ValueError("invalid thread id") - elif res != 1: - # """if it returns a number greater than one, you're in trouble, - # and you should call it again with exc=NULL to revert the effect""" - ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) - raise SystemError("PyThreadState_SetAsyncExc failed") -def stop_thread(thread): - _async_raise(thread.ident, SystemExit) def main(): LogOutput=API.AutoLogOutput log_thread=threading.Thread(target=LogOutput,args=()) diff --git a/old/astronomy/hour_angle/api.php b/old/astronomy/hour_angle/api.php new file mode 100644 index 0000000..84c0084 --- /dev/null +++ b/old/astronomy/hour_angle/api.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/old/astronomy/hour_angle/api_core.py b/old/astronomy/hour_angle/api_core.py new file mode 100644 index 0000000..563b0ad --- /dev/null +++ b/old/astronomy/hour_angle/api_core.py @@ -0,0 +1,168 @@ +import os,time,math,argparse,json +#-------------------------------------# +class Calendar(object): + def calcSunDeclination(self,Stamp=None,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0 + def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525 + L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone) + while (TrueSolarTime > 1440): + TrueSolarTime -= 1440 + HourAngle = TrueSolarTime / 4 - 180.0 + if (HourAngle < -180): + HourAngle += 360.0 + return HourAngle + def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0 + csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone))) + if(csz > 1): + csz = 1 + elif(csz < -1): + csz = -1 + if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001): + azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz))))) + if(abs(azRad) > 1.0): + if(azRad < 0): + azRad = -1.0 + else: + azRad = 1.0 + azimuth = 180.0 - math.degrees(math.acos(azRad)) + if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0): + azimuth = -azimuth + else: + if(Lat > 0.0): + azimuth = 180.0 + else: + azimuth = 0.0 + if(azimuth < 0.0): + azimuth += 360.0 + exoatmElevation = (90.0 - math.degrees(math.acos(csz))) + if (exoatmElevation > 85.0): + refractionCorrection = 0.0 + else: + te = math.tan (math.radians(exoatmElevation)) + if (exoatmElevation > 5.0): + refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te) + elif (exoatmElevation > -0.575): + refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) ) + else: + refractionCorrection = -20.774 / te + refractionCorrection = refractionCorrection / 3600.0 + solarZen = math.degrees(math.acos(csz)) - refractionCorrection + return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0} +c=Calendar() +parser=argparse.ArgumentParser() +parser.add_argument("--stamp",default=time.time()) +parser.add_argument("--lon",default=120) +parser.add_argument("--zone",default=8) +parser=parser.parse_args() +print(json.dumps(c.calcHourAngle(int(parser.stamp),int(parser.lon),int(parser.zone)))) \ No newline at end of file diff --git a/old/astronomy/sun_az_el/api.php b/old/astronomy/sun_az_el/api.php new file mode 100644 index 0000000..6dc0af8 --- /dev/null +++ b/old/astronomy/sun_az_el/api.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/old/astronomy/sun_az_el/api_core.py b/old/astronomy/sun_az_el/api_core.py new file mode 100644 index 0000000..92ad155 --- /dev/null +++ b/old/astronomy/sun_az_el/api_core.py @@ -0,0 +1,170 @@ +import os,time,math,argparse,json +#-------------------------------------# +class Calendar(object): + def calcSunDeclination(self,Stamp=None,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0 + def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525 + L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone) + while (TrueSolarTime > 1440): + TrueSolarTime -= 1440 + HourAngle = TrueSolarTime / 4 - 180.0 + if (HourAngle < -180): + HourAngle += 360.0 + return HourAngle + def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0 + csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone))) + if(csz > 1): + csz = 1 + elif(csz < -1): + csz = -1 + if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001): + azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz))))) + if(abs(azRad) > 1.0): + if(azRad < 0): + azRad = -1.0 + else: + azRad = 1.0 + azimuth = 180.0 - math.degrees(math.acos(azRad)) + if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0): + azimuth = -azimuth + else: + if(Lat > 0.0): + azimuth = 180.0 + else: + azimuth = 0.0 + if(azimuth < 0.0): + azimuth += 360.0 + exoatmElevation = (90.0 - math.degrees(math.acos(csz))) + if (exoatmElevation > 85.0): + refractionCorrection = 0.0 + else: + te = math.tan (math.radians(exoatmElevation)) + if (exoatmElevation > 5.0): + refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te) + elif (exoatmElevation > -0.575): + refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) ) + else: + refractionCorrection = -20.774 / te + refractionCorrection = refractionCorrection / 3600.0 + solarZen = math.degrees(math.acos(csz)) - refractionCorrection + return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0} +c=Calendar() +parser=argparse.ArgumentParser() +parser.add_argument("--stamp",default=time.time()) +parser.add_argument("--lon",default=120) +parser.add_argument("--lat",default=30) +parser.add_argument("--zone",default=8) +parser.add_argument("--zero",default="North") +parser=parser.parse_args() +print(json.dumps(c.calcSunAzEl(int(parser.stamp),int(parser.lon),int(parser.lat),int(parser.zone),parser.zero))) \ No newline at end of file diff --git a/old/astronomy/sun_dec/api.php b/old/astronomy/sun_dec/api.php new file mode 100644 index 0000000..24dce45 --- /dev/null +++ b/old/astronomy/sun_dec/api.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/old/astronomy/sun_dec/api_core.py b/old/astronomy/sun_dec/api_core.py new file mode 100644 index 0000000..348a87a --- /dev/null +++ b/old/astronomy/sun_dec/api_core.py @@ -0,0 +1,168 @@ +import os,time,math,argparse,json +#-------------------------------------# +class Calendar(object): + def calcSunDeclination(self,Stamp=None,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0 + def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525 + L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032)) + while(L0 > 360.0): + L0 -= 360.0 + while(L0 < 0.0): + L0 += 360.0 + TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone) + while (TrueSolarTime > 1440): + TrueSolarTime -= 1440 + HourAngle = TrueSolarTime / 4 - 180.0 + if (HourAngle < -180): + HourAngle += 360.0 + return HourAngle + def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"): + MonthList = [ + {"name": 'January', "numdays": 31}, + {"name": 'February', "numdays": 28}, + {"name": 'March', "numdays": 31}, + {"name": 'April', "numdays": 30}, + {"name": 'May', "numdays": 31}, + {"name": 'June', "numdays": 30}, + {"name": 'July', "numdays": 31}, + {"name": 'August', "numdays": 31}, + {"name": 'September', "numdays": 30}, + {"name": 'October', "numdays": 31}, + {"name": 'November', "numdays": 30}, + {"name": 'December', "numdays": 31}, + ] + if(Stamp==None): + TimeStamp = time.time() + else: + TimeStamp = Stamp + Year=int(time.strftime("%Y",time.localtime(TimeStamp))) + Month=int(time.strftime("%m",time.localtime(TimeStamp))) + Day=int(time.strftime("%d",time.localtime(TimeStamp))) + Hour=int(time.strftime("%H",time.localtime(TimeStamp))) + Minute=int(time.strftime("%M",time.localtime(TimeStamp))) + Second=int(time.strftime("%S",time.localtime(TimeStamp))) + if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)): + if(Day > 29): + Day=29 + else: + if(Day > MonthList[Month-1]['numdays']): + Day = MonthList[Month-1]['numdays'] + if(Month <= 2): + Year -= 1 + Month += 12 + ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0 + csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone))) + if(csz > 1): + csz = 1 + elif(csz < -1): + csz = -1 + if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001): + azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz))))) + if(abs(azRad) > 1.0): + if(azRad < 0): + azRad = -1.0 + else: + azRad = 1.0 + azimuth = 180.0 - math.degrees(math.acos(azRad)) + if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0): + azimuth = -azimuth + else: + if(Lat > 0.0): + azimuth = 180.0 + else: + azimuth = 0.0 + if(azimuth < 0.0): + azimuth += 360.0 + exoatmElevation = (90.0 - math.degrees(math.acos(csz))) + if (exoatmElevation > 85.0): + refractionCorrection = 0.0 + else: + te = math.tan (math.radians(exoatmElevation)) + if (exoatmElevation > 5.0): + refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te) + elif (exoatmElevation > -0.575): + refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) ) + else: + refractionCorrection = -20.774 / te + refractionCorrection = refractionCorrection / 3600.0 + solarZen = math.degrees(math.acos(csz)) - refractionCorrection + return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0} +c=Calendar() +parser=argparse.ArgumentParser() +parser.add_argument("--stamp",default=time.time()) +parser.add_argument("--lon",default=120) +parser.add_argument("--zone",default=8) +parser=parser.parse_args() +print(json.dumps(c.calcSunDeclination(int(parser.stamp),int(parser.zone)))) \ No newline at end of file diff --git a/old/calendar/holiday/api.php b/old/calendar/holiday/api.php new file mode 100644 index 0000000..c6f31b7 --- /dev/null +++ b/old/calendar/holiday/api.php @@ -0,0 +1,14 @@ + [ + "verify_peer"=>false, + "verify_peer_name"=>false, + ] +]; +if($_GET['date'] == null){ + header("Content-type:application/json"); + echo '{"error":"10001"}'; +}else{ + echo @file_get_contents("http://tool.bitefu.net/jiari/?d=".$_GET['date'],false, stream_context_create($stream_opts)); +} \ No newline at end of file diff --git a/old/crypt/decrypt/api.php b/old/crypt/decrypt/api.php new file mode 100644 index 0000000..4bf478b --- /dev/null +++ b/old/crypt/decrypt/api.php @@ -0,0 +1,31 @@ + [ + "verify_peer"=>false, + "verify_peer_name"=>false, + ] +]; +//读取API JSON并转为数组 +$teamjson=file_get_contents("http://api.ghink.net/fah/json/?team=".$_GET['team'],false, stream_context_create($stream_opts)); +$donorjson=file_get_contents("http://api.ghink.net/fah/json/?donor=".$_GET['donor'],false, stream_context_create($stream_opts)); +$team=json_decode($teamjson, true); +$donor=json_decode($donorjson, true); +//---------------------------------------------------------------------// +foreach ($team as $key => $value) { //遍历数组,读取数据 + if($key='name'){ + $teamname=$team['name']; + } +} +foreach ($team as $key => $value) { + if($key='team'){ + $teamid=$team['team']; + } +} +foreach ($team as $key => $value) { + if($key='rank'){ + $teamrank=$team['rank']; + } +} +foreach ($team as $key => $value) { + if($key='wus'){ + $teamwus=$team['wus']; + } +} +foreach ($team as $key => $value) { + if($key='credit'){ + $teamscores=$team['credit']; + } +} +foreach ($donor as $key => $value) { + if($key='name'){ + $name=$donor['name']; + } +} +foreach ($donor as $key => $value) { + if($key='rank'){ + $rank=$donor['rank']; + } +} +foreach ($donor as $key => $value) { + if($key='wus'){ + $wus=$donor['wus']; + } +} +foreach ($donor as $key => $value) { + if($key='credit'){ + $scores=$donor['credit']; + } +} +foreach ($donor as $key => $value) { + if($key='last'){ + $lastwus=$donor['last']; + } +} +//---------------------------------------------------------------------// +if($_GET['mode'] == 'advanced'){//判断是否是高级模式 + if($_GET['donor'] == null){ + echo '{"error":"10001"}'; + }elseif($_GET['team'] == null){ + echo '{"error":"10001"}'; + }else{ + if($_GET['height'] == null){//判断是否有提交画布大小 + if($_GET['weight'] == null){ + $canvas = imagecreatetruecolor(465, 92);//载入默认画布 + $weight = 465; + $height = 95; + $weightdefault = 465; + $heightdefault = 95; + }else{ + $error = 10001; + } + }elseif($_GET['weight'] == null){ + if($_GET['height'] == null){ + $canvas = imagecreatetruecolor(465, 92);//载入默认画布 + $weight = 465; + $height = 95; + $weightdefault = 465; + $heightdefault = 95; + }else{ + $error = 10001; + } + }else{ + $canvas = imagecreatetruecolor($_GET['weight'], $_GET['height']);//根据提交的参数载入画布 + $weightdefault = $_GET['weight']; + $heightdefalut = $_GET['height']; + } + $background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色 + imagefill($canvas, 0, 0, $background);//填充透明色 + imagecolortransparent($canvas, $background);//设置背景色 + if($_GET['fnt'] == null){//判断是否有提交自定义字体 + $text_fonts = 'fnt/default.ttf';//设置默认字体 + }else{ + $text_fonts = 'fnt/'.$_GET['fnt'];//根据提交的字体地址载入自定义字体 + } + if($_GET['red'] == null){//判断是否有提交自定义字体颜色 + if($_GET['green'] == null){ + if($_GET['blue'] == null){ + $color = imagecolorallocate($canvas, 255, 255, 255);//设置默认文字颜色 + }else{ + $error = 10001; + } + }else{ + $error = 10001; + } + }else{ + if($_GET['green'] == null){ + }else{ + if($_GET['blue'] == null){ + }else{ + $color = imagecolorallocate($canvas, $_GET['red'], $_GET['green'], $_GET['blue']);//设置自定义文字颜色 + } + } + } + if($_GET['textsize'] == null){//判断是否有提交自定义字体 + $text_size = 7;//设置默认字体大小 + }else{ + $text_size = $_GET['textsize'];//设置自定义字体大小 + } + if($_GET['img'] == null){//判断是否有提交自定义底图 + $logo_url = 'img.png';//设置默认源图片 + }else{ + $logo_url = $_GET['img'];//设置自定义源图片 + } + $logo = file_get_contents($logo_url);//读取源文件 + $logo_img = imagecreatefromstring($logo);//解析为图片 + if($_GET['imgx'] == null){//判断是否有提交自定义底图位置 + if($_GET['imgy'] == null){ + $imgx = 0;//设置默认底图位置 + $imgy = 0; + }else{ + $error = 10001; + } + }else{ + if($_GET['imgy'] == null){ + $error = 10001; + }else{ + $imgx = $_GET['imgx'];//设置自定义底图位置 + $imgy = $_GET['imgy']; + } + } + if($_GET['putweight'] == null){ + if($_GET['putheight'] == null){ + $weight = $weightdefault; + $height = $heightdefault; + }else{ + $error = 10001; + } + }else{ + if($_GET['putheight'] == null){ + $error = 10001; + }else{ + $weight = $_GET['putweight']; + $height = $_GET['putheight']; + } + } + imagecopyresampled($canvas, $logo_img, $imgx, $imgy, 0, 0, $weight, $height, imagesx($logo_img), imagesy($logo_img));//覆盖图层 + //---------------------------------------------------------------------// + //团队部分 + imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名称 + imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号 + imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名 + imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务 + imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分 + //---------------------------------------------------------------------// + //个人部分 + imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名 + imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名 + imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务 + imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分 + imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成 + //---------------------------------------------------------------------// + if($error == null){//判断是否有错误 + header("content-type:image/png");//设置网页为图片 + imagepng($canvas);//输出图片 + imagedestroy($canvas);//关闭进程 + }elseif($error == 10001){ + header("Content-type:application/json;charset=utf-8"); + echo '{"error":"10001"}'; + } + } +}else{ + if($_GET['donor'] == null){ + header("Content-type:application/json;charset=utf-8"); + echo '{"error":"10001"}'; + }elseif($_GET['team'] == null){ + header("Content-type:application/json;charset=utf-8"); + echo '{"error":"10001"}'; + }else{ + $canvas = imagecreatetruecolor(465, 92);//载入画布 + $background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色 + imagefill($canvas, 0, 0, $background);//填充透明色 + imagecolortransparent($canvas, $background);//设置背景色 + $text_fonts = 'fnt/default.ttf';//设置字体 + $color = imagecolorallocate($canvas, 255, 255, 255);//设置文字颜色 + $text_size = 7;//设置文字大小 + $logo_url = 'img.png';//设置源图片目录 + $logo = file_get_contents($logo_url);//读取源文件 + $logo_img = imagecreatefromstring($logo);//解析为图片 + imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));//覆盖图层 + //---------------------------------------------------------------------// + //团队部分 + imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名 + imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号 + imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名 + imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务 + imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分 + //---------------------------------------------------------------------// + //个人部分 + imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名 + imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名 + imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务 + imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分 + imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成 + //---------------------------------------------------------------------// + header("content-type:image/png");//设置网页为图片 + imagepng($canvas);//输出图片 + imagedestroy($canvas);//关闭进程 + } +} \ No newline at end of file diff --git a/old/fah/json/api.php b/old/fah/json/api.php new file mode 100644 index 0000000..9ebdb15 --- /dev/null +++ b/old/fah/json/api.php @@ -0,0 +1,34 @@ + [ + "verify_peer"=>false, + "verify_peer_name"=>false, + ] +]; +$error = null; +if($_GET['donor'] == null){ + if($_GET['team'] == '*'){ + echo @file_get_contents("http://reverse.ghink.net/fah.php?team=*",false, stream_context_create($stream_opts)); + }else{ + echo @file_get_contents("http://reverse.ghink.net/fah.php?team=".$_GET['team'],false, stream_context_create($stream_opts)); + } +}else{ + if($_GET['team'] == null){ + }else{ + $error = '{"error":"10000"}'; + } +} +if($_GET['team'] == null){ + if($_GET['donor'] == '*'){ + echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=*",false, stream_context_create($stream_opts)); + }else{ + echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=".$_GET['donor'],false, stream_context_create($stream_opts)); + } +}else{ + if($_GET['donor'] == null){ + }else{ + $error = '{"error":"10000"}'; + } +} +echo $error; \ No newline at end of file diff --git a/old/index.json b/old/index.json new file mode 100644 index 0000000..5130d82 --- /dev/null +++ b/old/index.json @@ -0,0 +1 @@ +{"wikis": "https://gitee.com/ghink/api/wikis"} \ No newline at end of file diff --git a/old/ipinfo/api.php b/old/ipinfo/api.php new file mode 100644 index 0000000..2bbf2b4 --- /dev/null +++ b/old/ipinfo/api.php @@ -0,0 +1,38 @@ +array( + 'timeout'=>3, + ) + ); + $context = stream_context_create($opts); + return @file_get_contents("http://whois.pconline.com.cn/ipJson.jsp", false, $context); +} +if(empty($_GET['ip'])){ + $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; +}else{ + $ip=$_GET['ip']; +} +$db=mysqli_connect("database.ghink.net","ghinkapi","ghink2014","ghinkapi"); +mysqli_query($db,"set names utf8"); +$result=mysqli_query($db,"SELECT `ip` FROM `ip_area` WHERE `ip`='".$ip."'"); +if(empty(mysqli_fetch_array($result))){ + if(is_url_alive()){ + $ipinfo=@file_get_contents("http://whois.pconline.com.cn/ipJson.jsp?ip=".$ip."&json=true"); + $ipinfo=iconv("GB2312","UTF-8",$ipinfo); + $ipinfo=json_decode($ipinfo); + foreach($ipinfo as $ii=>$ii2){ + $$ii = $ii2; + } + echo '{"ip":"'.$ip.'","pro":"'.$pro.'","city":"'.$city.'","addr":"'.trim($addr).'"}'; + mysqli_query($db,"INSERT INTO `ip_area` (`ip`, `pro`, `city`, `addr`, `last_update`) VALUES ('".$ip."', '".$pro."', '".$city."', '".trim($addr)."', '".time()."')"); + }else{ + echo '{"error":"10002"}'; + } +}else{ + $result=mysqli_query($db,"SELECT * FROM `ip_area` WHERE `ip`='".$ip."'"); + $result=mysqli_fetch_array($result); + echo '{"ip":"'.$result['ip'].'","pro":"'.$result['pro'].'","city":"'.$result['city'].'","addr":"'.$result['addr'].'"}'; +} +mysqli_close($db); \ No newline at end of file diff --git a/old/live/bilibili/api.php b/old/live/bilibili/api.php new file mode 100644 index 0000000..e9f8874 --- /dev/null +++ b/old/live/bilibili/api.php @@ -0,0 +1,48 @@ +$ii2){ + $$ii = $ii2; +} +foreach($data as $ii=>$ii2){ + $$ii = $ii2; +} +echo $live_status.',"roomid":'; +echo $room_id.',"uid":'; +echo $uid.',"time":'; +echo $live_time.',"url1":"'; +foreach($play_url as $ii=>$ii2){ + $$ii = $ii2; +} +foreach($durl as $ii=>$ii2){ + $$ii = $ii2; +} +foreach($durl[0] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url2":"'; +foreach($durl[1] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url3":"'; +foreach($durl[2] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url4":"'; +foreach($durl[3] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'"}'; +}else{ +echo $json; +} +} \ No newline at end of file diff --git a/old/live/ghink/api.php b/old/live/ghink/api.php new file mode 100644 index 0000000..c1e09aa --- /dev/null +++ b/old/live/ghink/api.php @@ -0,0 +1,42 @@ +$ii2){ + $$ii = $ii2; +} +foreach($data as $ii=>$ii2){ + $$ii = $ii2; +} +echo $live_status.',"time":'; +echo $live_time; +if($live_status=="1"){ +echo ',"url1":"'; +foreach($play_url as $ii=>$ii2){ + $$ii = $ii2; +} +foreach($durl as $ii=>$ii2){ + $$ii = $ii2; +} +foreach($durl[0] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url2":"'; +foreach($durl[1] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url3":"'; +foreach($durl[2] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'","url4":"'; +foreach($durl[3] as $ii=>$ii2){ + $$ii = $ii2; +} +echo $url.'"'; +} +echo '}'; \ No newline at end of file diff --git a/old/time/api.php b/old/time/api.php index 172e215..438d84c 100644 --- a/old/time/api.php +++ b/old/time/api.php @@ -15,7 +15,7 @@ if($_GET['type']==''){ } header("Content-type:application/json"); if($error==true){ - echo '{"error":10004}'; + echo '{"error":"10004"}'; }else{ echo '{"stamp":'.$time.',"year":"'.date("Y",$time_gap).'","month":"'.date("m",$time_gap).'","day":"'.date("d",$time_gap).'","hour":"'.date("H",$time_gap).'","minute":"'.date("i",$time_gap).'","second":"'.date("s",$time_gap).'"}'; }