Mapping the location of the International Space Station in Linux Fedora

Because it is not a specifc Turtle discussion any more, I started this new discussion. The previous discussion is readable in:
https://discuss.python.org/t/turtle-doesnt-show-window-in-full-format-in-linux-fedora/35546/21
In the mean time I have changed the Worldmap by the suggested Blue Marble Earth Image and made the necessary adjustments. I also add more info of the actual ISS position. The last code is now:

import json
import turtle
import time
import tkinter
import urllib
import urllib.request
from tkinter import *
from turtle import RawTurtle, TurtleScreen
from datetime import datetime
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
print(result, '\n')
location = result['iss_position']
lat = location['latitude']
lon = location['longitude']
print('latitude: ', lat)
print('longitude:', lon)
lat = float(lat)
lon = float(lon)
win = tkinter.Tk()
win.title('ISS Location')
width_value = win.winfo_screenwidth()
height_value = win.winfo_screenheight()
print(width_value)
print(height_value)
canv = tkinter.Canvas(master = win, width = 876, height = 438)
canv.grid(row = 0, column = 0)
screen = TurtleScreen(canv)
screen.bgpic('worldmap.gif')
x0 = 7 # zero point corrections
y0 = -7
my_turtle = turtle.RawTurtle(screen)
# ISS-point coordinates
my_turtle.goto(x0 + lon * 2.4, y0 + lat * 2.2) # draw corrections
# ISS-point 
my_turtle.fillcolor('red')
my_turtle.begin_fill()
my_turtle.circle(10)
my_turtle.end_fill()
style = ('Arial', 15, 'bold')
# zero point and ISS-location information
my_turtle.goto(x0, y0)
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("date and time =", dt_string)
my_turtle.color('yellow')
my_turtle.write('Lat^ ' + str(lat)
                + '\n' + 'Lon> ' + str(lon) + '\n' + dt_string, font=style)
win.mainloop()

But I have please one remark or question for the presentation.
From IDLE, I have no problem to run it, but it doesn’t run from the terminal.
I receive the following error, I suppose I can not run it from terminal?

gastonv@localhost Python_The_Bible]$ python3 isslocation.py
Traceback (most recent call last):
  File "/home/gastonv/Programmeren/Python_The_Bible/isslocation.py", line 8, in <module>
    import urllib.request
  File "/usr/lib64/python3.11/urllib/request.py", line 88, in <module>
    import http.client
  File "/usr/lib64/python3.11/http/client.py", line 71, in <module>
    import email.parser
  File "/usr/lib64/python3.11/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/usr/lib64/python3.11/email/feedparser.py", line 27, in <module>
    from email._policybase import compat32
  File "/usr/lib64/python3.11/email/_policybase.py", line 9, in <module>
    from email.utils import _has_surrogates
  File "/usr/lib64/python3.11/email/utils.py", line 28, in <module>
    import random
  File "/home/gastonv/Programmeren/Python_The_Bible/random.py", line 5, in <module>
    print(random.random())
          ^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable
1 Like

It looks like you’ve made your own file called random.py, which is shadowing the standard library’s random module, and also importing it. Rename or remove that file and everything should work.

1 Like

I have to thank you very much for the quick reply.
Indeed, I had a file called random.py in the same directory.
I have changed it and the program ran immediately successfully.
I go check the directory for similar program names.

[gastonv@localhost Python_The_Bible]$ python3 isslocation.py
{'iss_position': {'latitude': '-39.5660', 'longitude': '5.8891'}, 'timestamp': 1697480707, 'message': 'success'} 
latitude:  -39.5660
longitude: 5.8891
3840
1080
date and time = 16/10/2023 20:25:09
1 Like

@gastverh, your map looks great!

Since you changed the background map from the original to the Blue Marble Earth Image, an additional suggestion would be to perform some testing in order to make sure that your mapping of latitudes and longitudes from the real world to the image map coordinates is still correct. You can choose the latitudes and longitudes of some cities in various parts of the world as test points to observe whether they map to the correct locations on the background map.

I have made many comparisons with the worldmap from:
https://laulima.hawaii.edu/access/content/group/dbd544e4-dcdd-4631-b8ad-3304985e1be2/book/chapter_1/longitude.htm
But the result is not accurate, but it has to be in nearness.

Does this mean that the result is much different from what it should be, or is it only off by a small acceptable amount? If the result is unacceptably inaccurate, it might be that the pixel dimensions and the map projection of the Blue Marble Earth Image are quite different from those aspects of your original image. Taking that into account might require some adjustments of the numbers in the following lines of code:

x0 = 7 # zero point corrections
y0 = -7

… and …

my_turtle.goto(x0 + lon * 2.4, y0 + lat * 2.2) # draw corrections

This morning, I performed some testing of how your code plots points. In order to do this, I copied the image of the Tk window that you posted most recently, cropped off the edges, so that only the map image remained, then scaled that map image to conform to the size specified here:

canv = tkinter.Canvas(master = win, width = 876, height = 438)

Then, after the commenting out of some lines of your code, and adding of lines to denote locations of some cities, the following was used to specify points to plot:

# location = result['iss_position']
# lat = location['latitude']
# lon = location['longitude']

lat, lon =  40.7128, -74.0060 # NYC
# lat, lon =  51.5072, -0.1276 # London
# lat, lon = -33.8688, 151.2093 # Sydney
# lat, lon = -36.8509, 174.7645 # Auckland

The above specifies a point for New York City.

The plotted points for New York City and London were fairly close to where they should be, however, the ones for Sydney and Auckland were a bit more distant from their actual locations.

It is possible that my copying and adjusting of your map image was less than ideal, and that your results have been better than mine. However, if you also notice some drifting of points from their proper locations in the lower-right portion of you map, some minor adjustments of the multipliers 2.4 and 2.2 within this calculation might offer improved results:

my_turtle.goto(x0 + lon * 2.4, y0 + lat * 2.2) # draw corrections

Yes, it should be possible to make it more accurate. Every time I start the program I take a look to the results.
The main reason of my topic was to learn more about Python Turtle.
I saw it for the first time in Python The Bible and I would run the program in Linux Fedora. With the splendid help and good communication in this fine Python Forum, I could make and run a program.
A last step I would make was to show the worldmap window in the center of the screen, like I did in my wine program. Here the selected code of it, only in order to show the centered window. If asked, I can send the whole code.

# The same modules as before.
import json
import turtle
import time
import tkinter
import urllib
import urllib.request
from tkinter import *
from turtle import RawTurtle, TurtleScreen
from datetime import datetime
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
print(result, '\n')
location = result['iss_position']
lat = location['latitude']
lon = location['longitude']
print('latitude: ', lat)
print('longitude:', lon)
lat = float(lat)
lon = float(lon)
win = tkinter.Tk()
win.title("ISS Location")
# calculation of the coordinates for the position of the window.
width_value = win.winfo_screenwidth()/2
height_value = win.winfo_screenheight()
print(width_value)
print(height_value)
x_location = (width_value - 876)/2
y_location = (height_value - 438)/2
print(x_location)
print(y_location)
win.geometry("876x438+%i+%i" % (x_location, y_location))
canv = tkinter.Canvas(master = win, width = 876, height = 438)
canv.grid(row = 0, column = 0)
screen = TurtleScreen(canv)
screen.bgpic('worldmap.gif')
win.mainloop()
2 Likes

Thanks for sending us the selected code. There’s no need to send the whole code to us at this time, unless someone here asks for it, or if you have additional questions about it.

We’re glad you have benefited from your communication with us, and have enjoyed discussing this project with you. Please continue to enjoy this forum, and feel free to bring our attention to any other projects that you may wish to discuss with us in the future.