Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3334622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:55:32+00:00 2026-05-17T23:55:32+00:00

I have looked at the examples here on using ephem to calculate sunrise and

  • 0

I have looked at the examples here on using ephem to calculate sunrise and sunset, and have that working great.

I get in trouble when I try to calculate the midpoint between those two times. Here’s what I have:

import datetime
import ephem

o = ephem.Observer()
o.lat, o.long, o.date = '37.0625', '-95.677068', datetime.datetime.utcnow()
sun = ephem.Sun(o)
print "sunrise:", o.previous_rising(sun), "UTC"
print "sunset:",o.next_setting(sun), "UTC"
print "noon:",datetime.timedelta((o.next_setting(sun)-o.previous_rising(sun))/2)

I get:

sunrise: 2010/11/2 12:47:40 UTC
sunset: 2010/11/2 23:24:25 UTC
noon: 5:18:22.679044

That’s where I’m stuck. I’m a python beginner and frankly not much of a programmer in general.

Any suggestions would be most welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:55:32+00:00Added an answer on May 17, 2026 at 11:55 pm

    Solar noon is not the mean of sunrise and sunset (see equation of time for the explanation). The ephem package has methods for getting transit times which you should use instead:

    >>> import ephem
    >>> o = ephem.Observer()
    >>> o.lat, o.long = '37.0625', '-95.677068'
    >>> sun = ephem.Sun()
    >>> sunrise = o.previous_rising(sun, start=ephem.now())
    >>> noon = o.next_transit(sun, start=sunrise)
    >>> sunset = o.next_setting(sun, start=noon)
    >>> noon
    2010/11/6 18:06:21
    >>> ephem.date((sunrise + sunset) / 2)
    2010/11/6 18:06:08
    

    Note that noon today is 13 seconds later (at your location) than the mean of sunrise and sunset.

    (The line of code ephem.date((sunrise + sunset) / 2) shows how you could easily manipulate dates in the ephem package, if it were the right thing to do.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at few examples here Calling a Method from an Expression and
I have looked on the web and the discussions/examples appear to be for traditional
OK - I have looked and looked and found a lot of examples but
I have looked at this example using php and GD to piecewise-render a spiral
I have looked at many other threads that show how to use accelerometer values,
I have looked all over and cannot figure out why this code isn't working.
I have a small program that is mostly using regular set 's but now
Using MVC3.NET I have a file upload method in a controller that works fine
I looked online for examples of implementation of the form using DIVs and all
I've looked into the API Demos and they have an example of the gallery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.