how to get Moon condition (like Waxing Gibbous ) its showing in site but how to get it in api
- 15 Posts
- 0 Reply Likes
Posted 7 years ago
Brendan Hayes, Official Rep
- 962 Posts
- 123 Reply Likes
- 29 Posts
- 0 Reply Likes
I calculate the moon condition like this using python.
def convertMoonPhase(percentIlluminated,moonState): # convert percentIlluminated to the moonPhase string (have to know if waxing or waning already. This is stored in moonState)
if percentIlluminated == 0:
moonPhase = 'New Moon'
moonState = False # set moonState to false (new moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif percentIlluminated == 100:
moonPhase = 'Full Moon'
moonState = True # set moonState to True (full moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif moonState == False:
if percentIlluminated < 50:
moonPhase = 'Waxing Crescent'
elif percentIlluminated == 50:
moonPhase = 'First Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waxing Gibbous'
#endif
elif moonState == True:
if percentIlluminated < 50:
moonPhase = 'Waning Crescent'
elif percentIlluminated == 50:
moonPhase = 'Last Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waning Gibbous'
#endif
else: # prevents crash if non-vaild data is given as input
moonPhase = "N/A"
#endif
return [moonPhase, moonState]
#enddef
def convertMoonPhase(percentIlluminated,moonState): # convert percentIlluminated to the moonPhase string (have to know if waxing or waning already. This is stored in moonState)
if percentIlluminated == 0:
moonPhase = 'New Moon'
moonState = False # set moonState to false (new moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif percentIlluminated == 100:
moonPhase = 'Full Moon'
moonState = True # set moonState to True (full moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif moonState == False:
if percentIlluminated < 50:
moonPhase = 'Waxing Crescent'
elif percentIlluminated == 50:
moonPhase = 'First Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waxing Gibbous'
#endif
elif moonState == True:
if percentIlluminated < 50:
moonPhase = 'Waning Crescent'
elif percentIlluminated == 50:
moonPhase = 'Last Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waning Gibbous'
#endif
else: # prevents crash if non-vaild data is given as input
moonPhase = "N/A"
#endif
return [moonPhase, moonState]
#enddef
- 15 Posts
- 0 Reply Likes
is this function returning correct value for the moon condition
- 29 Posts
- 0 Reply Likes
I should be I got the data for it from here
http://aa.usno.navy.mil/faq/docs/moon...
This is the relavent section from that page.
The percent of the Moon's surface illuminated is a more refined, quantitative description of the Moon's appearance than is the phase. Considering the Moon as a circular disk, the ratio of the area illuminated by direct sunlight to its total area is the fraction of the Moon's surface illuminated; multiplied by 100, it is the percent illuminated. At New Moon the percent illuminated is 0; at First and Last Quarters it is 50%; and at Full Moon it is 100%. During the crescent phases the percent illuminated is between 0 and 50% and during gibbous phases it is between 50% and 100%.
http://aa.usno.navy.mil/faq/docs/moon...
This is the relavent section from that page.
The percent of the Moon's surface illuminated is a more refined, quantitative description of the Moon's appearance than is the phase. Considering the Moon as a circular disk, the ratio of the area illuminated by direct sunlight to its total area is the fraction of the Moon's surface illuminated; multiplied by 100, it is the percent illuminated. At New Moon the percent illuminated is 0; at First and Last Quarters it is 50%; and at Full Moon it is 100%. During the crescent phases the percent illuminated is between 0 and 50% and during gibbous phases it is between 50% and 100%.
- 15 Posts
- 0 Reply Likes
def convertMoonPhase(percentIlluminated,moonState): # convert percentIlluminated to the moonPhase string (have to know if waxing or waning already. This is stored in moonState)
if percentIlluminated == 0:
moonPhase = 'New Moon'
moonState = False # set moonState to false (new moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif percentIlluminated == 100:
moonPhase = 'Full Moon'
moonState = True # set moonState to True (full moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif moonState == False:
if percentIlluminated < 50:
moonPhase = 'Waxing Crescent'
elif percentIlluminated == 50:
moonPhase = 'First Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waxing Gibbous'
#endif
elif moonState == True:
if percentIlluminated < 50:
moonPhase = 'Waning Crescent'
elif percentIlluminated == 50:
moonPhase = 'Last Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waning Gibbous'
#endif
else: # prevents crash if non-vaild data is given as input
moonPhase = "N/A"
#endif
return [moonPhase, moonState]
#enddef
================================
but in this code either Waning Crescent,Last Quarter,Waning Gibbous will be shown or New Moon,Full Moon,Waxing Crescent,First Quarter,Waxing Gibbous part will be executed . i think there is some problem in code plz check the code as i m not familiar with Python code
if percentIlluminated == 0:
moonPhase = 'New Moon'
moonState = False # set moonState to false (new moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif percentIlluminated == 100:
moonPhase = 'Full Moon'
moonState = True # set moonState to True (full moon)
moonStateBackup = open(logDirectory + "/moonStateBackup.txt", "w") # open lastPullBackup.txt for writeing
pickle.dump(moonState, moonStateBackup) # write the new last poll time to the log file
moonStateBackup.close()
elif moonState == False:
if percentIlluminated < 50:
moonPhase = 'Waxing Crescent'
elif percentIlluminated == 50:
moonPhase = 'First Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waxing Gibbous'
#endif
elif moonState == True:
if percentIlluminated < 50:
moonPhase = 'Waning Crescent'
elif percentIlluminated == 50:
moonPhase = 'Last Quarter'
elif percentIlluminated < 100:
moonPhase = 'Waning Gibbous'
#endif
else: # prevents crash if non-vaild data is given as input
moonPhase = "N/A"
#endif
return [moonPhase, moonState]
#enddef
================================
but in this code either Waning Crescent,Last Quarter,Waning Gibbous will be shown or New Moon,Full Moon,Waxing Crescent,First Quarter,Waxing Gibbous part will be executed . i think there is some problem in code plz check the code as i m not familiar with Python code
- 29 Posts
- 0 Reply Likes
What?
Could you try to refrase that question more clearly?
The code is hard to read here because posting here strips out all the formating.
It works fine, I am using it right now.
Could you try to refrase that question more clearly?
The code is hard to read here because posting here strips out all the formating.
It works fine, I am using it right now.
- 15 Posts
- 0 Reply Likes
hmm ok. can you plz tell me how do the same in android
- 15 Posts
- 0 Reply Likes
actually percentIlluminated tag of wounder-ground api is always returning more then 50 as value than how to define first Quarter and Last Quarter ??
- 29 Posts
- 0 Reply Likes
That is what the moonState variable is for it lets the function know if the percentIlluminated is increasing or decreasing.
It is false if the moon is Waxing (increasing) and true if it is Waning (decreasing).
You give the function moonState as an input that is held in the rest of your script.
The function automatically changes this value at a full or new moon for you.
I keep a log of the value in a textfile so you don't have to manually set the value every time you start the script.
I put the code here where it should be easier to read, it should make more sense there.
http://pastebin.com/1bimiKZq
I can't help you with android I have never worked on an android app before.
It is false if the moon is Waxing (increasing) and true if it is Waning (decreasing).
You give the function moonState as an input that is held in the rest of your script.
The function automatically changes this value at a full or new moon for you.
I keep a log of the value in a textfile so you don't have to manually set the value every time you start the script.
I put the code here where it should be easier to read, it should make more sense there.
http://pastebin.com/1bimiKZq
I can't help you with android I have never worked on an android app before.
- 15 Posts
- 0 Reply Likes
one more question
suppose we get 96 as percentIlluminated tag value then what would be the out put of that code ? plz reply me soon
suppose we get 96 as percentIlluminated tag value then what would be the out put of that code ? plz reply me soon
- 29 Posts
- 0 Reply Likes
If moonState = False
['Waxing Gibbous', false]
if moonState = True
['Waning Gibbous', true]
the output is a list with the first entry being the moonPhase string and the second entrie being the value of moonState since it changes at a full or new moon.
['Waxing Gibbous', false]
if moonState = True
['Waning Gibbous', true]
the output is a list with the first entry being the moonPhase string and the second entrie being the value of moonState since it changes at a full or new moon.
- 15 Posts
- 0 Reply Likes
if i run the script first time suppose today than what would be the value of moonState??
- 29 Posts
- 0 Reply Likes
Since we just had a full moon moonState should be True.
- 15 Posts
- 0 Reply Likes
and in script there is no initialization of moonPhase before checking the value of
percentIlluminated .
percentIlluminated .
- 15 Posts
- 0 Reply Likes
and in the script the no code is for fetching the value of moonState from data base or from text file ??
- 29 Posts
- 0 Reply Likes
You have to initialize moonPhase in your script before you call the function.
I do that by reading the moonPhase value from a textfile I use to backup the variable everytime the script starts.
The convertMoonPhase function updates this textfile when it changes the value.
You should be able to add something to your script to do the same thing yourself.
I did not give you my whole script just the function that does the calculation of the moon phase string.
I can help you with what you don't understand in my example but I can't rewrite your script for you.
I do that by reading the moonPhase value from a textfile I use to backup the variable everytime the script starts.
The convertMoonPhase function updates this textfile when it changes the value.
You should be able to add something to your script to do the same thing yourself.
I did not give you my whole script just the function that does the calculation of the moon phase string.
I can help you with what you don't understand in my example but I can't rewrite your script for you.
arclance