Esempio n. 1
0
 def test_timezone_aware_utc(self):
     timezoned_date = to_timezone(self.date, UTC)
     self.assertEqual(timezoned_date.tzinfo, UTC)
     self.assertEqual(timezoned_date.hour, 0)
     self.assertEqual(timezoned_date.minute, 17)
     self.assertEqual(timezoned_date.second, 15)
     self.assertEqual(timezoned_date.day, 4)
     self.assertEqual(timezoned_date.month, 9)
     self.assertEqual(timezoned_date.year, 2004)
Esempio n. 2
0
 def test_timezone_aware_utc(self):
     timezoned_date = to_timezone(self.date, UTC)
     self.assertEqual(timezoned_date.tzinfo, UTC)
     self.assertEqual(timezoned_date.hour, 0)
     self.assertEqual(timezoned_date.minute, 17)
     self.assertEqual(timezoned_date.second, 15)
     self.assertEqual(timezoned_date.day, 4)
     self.assertEqual(timezoned_date.month, 9)
     self.assertEqual(timezoned_date.year, 2004)
Esempio n. 3
0
 def test_timezone_aware_cet(self):
     cet = CET()
     timezoned_date = to_timezone(self.date, cet)
     self.assertEqual(timezoned_date.tzinfo, cet)
     self.assertEqual(timezoned_date.hour, 1)
     self.assertEqual(timezoned_date.minute, 17)
     self.assertEqual(timezoned_date.second, 15)
     self.assertEqual(timezoned_date.day, 4)
     self.assertEqual(timezoned_date.month, 9)
     self.assertEqual(timezoned_date.year, 2004)
Esempio n. 4
0
 def test_timezone_aware_cet(self):
     cet = CET()
     timezoned_date = to_timezone(self.date, cet)
     self.assertEqual(timezoned_date.tzinfo, cet)
     self.assertEqual(timezoned_date.hour, 1)
     self.assertEqual(timezoned_date.minute, 17)
     self.assertEqual(timezoned_date.second, 15)
     self.assertEqual(timezoned_date.day, 4)
     self.assertEqual(timezoned_date.month, 9)
     self.assertEqual(timezoned_date.year, 2004)
Esempio n. 5
0
    def step_draw(self):
        """Calculate and draw the next position of each planet.
        """
        # If we don't call step_draw at all, we'll never get further key events
        # that could restart the animation. So just step at a much slower pace.
        if not self.stepping:
            self.canvas.after(500, self.step_draw)
            return

        # Adding a float to ephem.Date turns it into a float.
        # You can get back an ephem.Date with: ephem.Date(self.time).
        self.time += self.time_increment

        for p in (earth, mars):
            p["obj"].compute(self.time)

            # ephem treats Earth specially, what a hassle!
            # There is no ephem.Earth body; ephem.Sun gives the Earth's
            # hlon as hlon, but I guess we need to use earth_distance.
            oppy = False
            if p["name"] == "Earth":
                hlon = p["obj"].hlon
                sundist = p["obj"].earth_distance
                earthdist = 0
                size = 0
            else:
                hlon = p["obj"].hlon
                sundist = p["obj"].sun_distance
                earthdist = p["obj"].earth_distance
                size = p["obj"].size

                if abs(self.time - self.opp_date) <= .5:
                    oppy = True
                    if self.opp_date < self.closest_date:
                        print(table_format % (self.opp_date, earthdist, size),
                              "Opposition")
                        print(
                            table_format %
                            (self.closest_date, earthdist, size),
                            "Closest approach")
                    else:
                        print(
                            table_format %
                            (self.closest_date, earthdist, size),
                            "Closest approach")
                        print(table_format % (self.opp_date, earthdist, size),
                              "Opposition")

            xn, yn = self.planet_x_y(hlon, sundist)
            radius = 10

            if oppy:
                # Create outline circles for Mars and Earth at opposition.
                # xn, yn should be Mars since Earth was done first.
                self.canvas.create_oval(xn - radius,
                                        yn - radius,
                                        xn + radius,
                                        yn + radius,
                                        outline=p["color"],
                                        width=3)
                earthx = earth["xypath"][-2]
                earthy = earth["xypath"][-1]
                self.canvas.create_oval(earthx - radius,
                                        earthy - radius,
                                        earthx + radius,
                                        earthy + radius,
                                        outline=earth["color"],
                                        width=3)
                localtz = datetime.now().astimezone().tzinfo
                oppdate = ephem.to_timezone(self.opp_date, localtz)
                opp_str = oppdate.strftime("%Y-%m-%d") + \
                    '\n%.3f AU\n%.1f"' % (earthdist, size)
                if xn < self.width / 2:
                    if yn < self.height / 2:
                        anchor = "se"
                    else:
                        anchor = "ne"
                    xtxt = xn - radius
                else:
                    if yn < self.height / 2:
                        anchor = "sw"
                    else:
                        anchor = "nw"
                    xtxt = xn + radius
                ytxt = yn

                txtobj = self.canvas.create_text(xtxt,
                                                 ytxt,
                                                 fill="white",
                                                 justify=LEFT,
                                                 font=('sans', 14, 'bold'),
                                                 anchor=anchor,
                                                 text=opp_str)
                # Make sure it's not offscreen
                xt1, yt1, xt2, yt2 = self.canvas.bbox(txtobj)
                if xt1 < 0:
                    xtxt -= xt1
                elif xt2 > self.width:
                    xtxt -= (xt2 - self.width)
                if yt1 < 0:
                    ytxt -= yt1
                elif yt2 > self.height:
                    ytxt -= yt2 - self.height
                self.canvas.coords(txtobj, xtxt, ytxt)

                # Done with this opposition: find the next one.
                self.opp_date, self.closest_date \
                    = find_next_opposition(self.time + 500)

            p["xypath"].append(int(xn))
            p["xypath"].append(int(yn))
            if p["line"]:
                self.canvas.coords(p["line"], p["xypath"])
                self.canvas.coords(p["disk"], xn - radius, yn - radius,
                                   xn + radius, yn + radius)

            else:
                p["line"] = self.canvas.create_line(xn,
                                                    yn,
                                                    xn,
                                                    yn,
                                                    width=self.linewidth,
                                                    fill=p["color"])
                p["disk"] = self.canvas.create_oval(xn - radius,
                                                    yn - radius,
                                                    xn + radius,
                                                    yn + radius,
                                                    fill=p["color"])

            p["path"].append((hlon, sundist, earthdist, size))

        if self.stepping:
            self.canvas.after(self.timestep, self.step_draw)
Esempio n. 6
0
https://rhodesmill.org/pyephem/quick.html#dates
@author: PC
"""

import ephem

d = ephem.Date('1997/3/9 5:13')
print(d)
print(d.triple())
print(d.tuple())
print(d + ephem.hour)
print(ephem.date(d + ephem.hour))
print(ephem.date(d + 1))

ephem.Date(35497.7197916667)
ephem.Date('1997/3/10.2197916667')
ephem.Date('1997/3/10 05.275')
ephem.Date('1997/3/10 05:16.5')
ephem.Date('1997/3/10 05:16:30')
ephem.Date('1997/3/10 05:16:30.0')
ephem.Date((1997, 3, 10.2197916667))
ephem.Date((1997, 3, 10, 5, 16, 30.0))

d = ephem.Date('1997/3/9 5:13')
ephem.localtime(d)
print(ephem.localtime(d))

d = ephem.Date('1997/3/9 5:13')
ephem.to_timezone(d, ephem.UTC)
print(ephem.to_timezone(d, ephem.UTC))
Esempio n. 7
0
File: sun.py Progetto: 2020pili/sun
weather                     = observation.weather           
temp                        = weather.temperature()         
wind_dict_in_meters_per_sec = observation.weather.wind()    
pressure_dict               = observation.weather.pressure  

# Observer settings for PyEphem
Viewpoint                   = ephem.Observer()
Viewpoint.pressure          = pressure_dict['press']             
Viewpoint.horizon           = '-0:34'                       
Viewpoint.temp              = temp["temp"]                 
Viewpoint.elevation         = 10                            
Viewpoint.lat               = str(lat_lng[0])               
Viewpoint.lon               = str(lat_lng[1])               

#Sunrise and sunset 
ViewpointSunrise            = ephem.to_timezone(Viewpoint.next_rising(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))
ViewpointSet                = ephem.to_timezone(Viewpoint.next_setting(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))

#Computing twilight
Viewpoint.horizon           = '-0:0'                        #
HorizonTwilightRising       = ephem.to_timezone(Viewpoint.next_rising(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))
HorizonTwilightSetting      = ephem.to_timezone(Viewpoint.next_setting(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))

Viewpoint.horizon           = '-6'                          # Civil Twilightn.
CivilTwilightRising         = ephem.to_timezone(Viewpoint.next_rising(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))
CivilTwilightSetting        = ephem.to_timezone(Viewpoint.next_setting(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))

Viewpoint.horizon           = '-12'                         # Nautical twilight.
NauticalTwilightRising      = ephem.to_timezone(Viewpoint.next_rising(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))
NauticalTwilightSetting     = ephem.to_timezone(Viewpoint.next_setting(ephem.Sun()), ephem.UTC).replace(tzinfo=utc).astimezone(pytz.timezone(LocationTimezone))