Free time projects

ASTRONOMY JAVASCRIPT
  • Nick's Planetarium
    A fork project based on Stuart Lowe's Virtualsky.
    I've added some new features:
    • Interactive side menu
    • Major stars labels (color coded)
    • 41057 stars (up to Mag.8) from Hipparcos catalogue
    • Sun and Planets surfaces
    • Image for each star from Aladin Sky Atlas
    • Whole Messier's and NGC's object catalogue, with image as well
    • Ceres and Pallas asteroids
    • Some major Comet
    • Jupiter's Galileian moons position (at any time)
    • Earth's Moon phases (at any time)
    • Responsive layout
    • Objects search engine

    Visit the Planetarium!
  • Jupiter's Galilean Satellites
    A brand new U.I. and some new features for the Sky and Telescope utility:
    • Enhanced graphics
    • Satellites images and data
    • More clear transit and occultation
    • Time autoplay in different speeds (forward and reverse)
    • Night view (red color)
    • Desktop layout only (responsive design still to do, sorry)

    Visit the Planetarium!
  • Moon's phases
    Project based on Salvatore Ruiu's astro.js library:
    • Enhanced graphics
    • Moon's data
    • Next 4 phases
    • Forward/Reverse Manual Time
    • Desktop/Smartphone layout

    Visit the Planetarium!
MISCELLANEOUS PYTHON
  • When is I.S.S. visible over my head?
    I had the opportunity to teach a lesson about programming to teenager boys and girls at a school meeting showing Raspberry power.
    The following script is the result of the 2 hour lesson: it puts together some interesting things you can do with Pyhton language.

    If people you're teaching to aren't skilled enough you can show one/two task per lesson.

    • First task: retrieve information about the International Space Station position at current time by public API service (also log it in a file).
    • Second task: given the ISS position, check if it's in a visible range by observer's latitude and longitude position.
    • Third task: plot on a world map the approximate position by using coordinates.
    • Fourth task: send an alert email to the observer with attached plotted map image.

    Note that the script also retrieves crew members number and astronauts names.

    To make the code running you have to put it in crontab: we scheduled it every 3 minutes (yep, ISS is very fast!)
    Here is the code, feel free to get it.
    If you are a teacher and you show it in a lesson... please let me know what the attendants say ;-)

    Copy to clipboard
    import os, requests, email, smtplib, ssl, time, datetime, logging, matplotlib
    
    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle
    from email import encoders
    from email.mime.base import MIMEBase
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.application import MIMEApplication
    from logging.handlers import TimedRotatingFileHandler
    
    #Retrieve ISS position from Open JSON
    ISS = "http://api.open-notify.org/iss-now.json"
    r = requests.get(ISS)
    lat = float(r.json()['iss_position']['latitude'])
    lon = float(r.json()['iss_position']['longitude'])
    
    #Retrieve ISS crew from Open JSON
    crew = "http://api.open-notify.org/astros.json"
    c = requests.get(crew)
    crew_number = int(c.json()['number'])
    people = (c.json()['people'])
    crew_names = ""
    for p in people:
            crew_names += str(p['name']) + ", "
    crew_names = crew_names[:-2]
    
    #Set lat/lon for YOUR_LOCATION
    home_lat = *YOUR_LAT*
    home_lon = *YOUR_LON*
    
    #get datetime
    now = datetime.datetime.now()
    
    #set email sender configuration
    server_host = *YOUR_SMTP_SERVER*
    server_port = *YOUR_SERVER_PORT*
    sender_account = *SENDER_ACCOUNT*
    sender_email = " *SENDER_EMAIL* "
    senderpwd = *SENDER_PASSWORD*
    receivers = ["*RECEIVER_EMAIL_1*","*RECEIVER_EMAIL_2*"]
    
    #rotating log setup
    logger = logging.getLogger("Rotating Log")
    logger.setLevel(logging.INFO)
    logfile = " *PATH_TO_LOG* /ISSdata.log"
    handler = TimedRotatingFileHandler(logfile, when="midnight", interval=1)
    handler.suffix = "%Y%m%d"
    logger.addHandler(handler)
    
    #if ISS is in range, plot image and send email with attachment and log position
    if ( lat >= (home_lat-7) and lat <= (home_lat+4) and lon >= (home_lon-7) and lon <= (home_lon+4) ):
    
            #set temporary image by reading bluemarble file
            bluemarble = plt.imread(' *PATH_TO_IMG* /blue_marble_800.gif')
            fig,ax = plt.subplots(1)
            #crop white space around the image
            plt.subplots_adjust(top=1,bottom=0,right=1,left=0,hspace=0,wspace=0)
            plt.margins(0,0)
            ax.xaxis.set_major_locator(plt.NullLocator())
            ax.yaxis.set_major_locator(plt.NullLocator())
            #set coordinates for temporary image and plot a dot at current ISS position
            ax.set_aspect('equal')
            ax.imshow(bluemarble, zorder=0, extent=[-180, 180, -90, 90])
            ax.add_patch(Circle((lon,lat), 2, color='red'))
            ax.axis('off')
            #save temporary image
            plt.savefig('ISSposition.png', dpi=125, bbox_inches='tight', pad_inches=0)
    
            #record data in log file
            logger.info(now.strftime("%Y-%m-%d;%H:%M:%S") + ";" + str(lat) + ";" + str(lon) + ";Y")
    
            #set email parameters
            srv = smtplib.SMTP(server_host, server_port)
            subject = "ISS at " + str(lat) + ", " + str(lon)
            body = "International Space Station is flying over your head at these coordinates:\n"
            body += "Latitude: " + str(lat) + " Longitude: " + str(lon) + "\n\n"
            body += "Crew: " + str(crew_number) + "\n"
            body += str(crew_names) + "\n\n"
            body += "Have a nice view!\n\nISS Monitor"
            #set email content
            message = MIMEMultipart()
            message['Subject'] = subject
            message['From'] = sender_email
            message['Bcc'] = "," .join(receivers)
            message.attach(MIMEText(body, "plain"))
            #set email attachment file
            filename = ' *PATH_TO_IMG* /ISSposition.png'
            with open(filename, 'rb') as f:
                    contents = f.read()
            part = MIMEApplication(contents)
            part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
            message.attach(part)
            text = message.as_string()
    
            #send email
            try:
                    srv.starttls()
                    srv.login(sender_account,senderpwd)
                    srv.sendmail(sender_email,receivers,text)
                    #print("ISS is close by, an email was successfully sent!")
            except Exception as e:
                    #print(e)
                    f = open("  *PATH_TO_LOG* /ISSerror.log","a+")
                    f.write(now.strftime("%Y-%m-%d %H:%M:%S")+ " > " + e + "\r\n")
                    f.close
            finally:
                    srv.quit
    
    #if ISS is out of range, just log the position
    else:
    		#you can omit this line if you don't want to log ISS position
            logger.info(now.strftime("%Y-%m-%d;%H:%M:%S")+ ";" + str(lat) + ";" + str(lon) + ";N")
    
    #delete temporary image
    if os.path.exists('ISSposition.png'):
            os.remove('ISSposition.png')
    
  • Next Moon phase email alert
    The following Python script is crontab scheduled to be executed every day at 6 a.m. by one of my RaspberryPi.
    It sends an email alert to each element (email) of the receivers array whenever a Moon phase is going to happen within the next 24 hours.
    Ephem, Smtplib and Ssl libraries are needed to run.

    Copy to clipboard
    import ephem, datetime, email, smtplib, ssl
    from email import encoders
    from email.mime.base import MIMEBase
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.application import MIMEApplication
    
    def days_between(d1, d2):
    	return abs(d2 - d1)
    
    def twodigits(n):
    	if len(n)<2:
    		n = '0' + n
    	return n
    
    #set sender configuration: change values between asterisks accordingly
    sender_account = *SENDER_LOGIN* 
    sender_email = *SENDER_EMAIL*
    sender_pwd = *SENDER_PASSWORD*
    receivers = ["*EMAIL_1@DOMAIN.COM*","*EMAIL_2@DOMAIN.COM"]
    srv = smtplib.SMTP("*YOUR_SERVER_SMTP_ADDRESS*",*YOUR_SERVER_PORT*)
    
    theDate = ephem.Date(datetime.datetime.now())
    
    nextfirst = ephem.next_first_quarter_moon(theDate)
    nextfull = ephem.next_full_moon(theDate)
    nextlast = ephem.next_last_quarter_moon(theDate)
    nextnew = ephem.next_new_moon(theDate)
    
    msg = ''
    if int(days_between(theDate,nextfirst)) == 0:
    	msg = 'First quarter:'
    	nextphase = nextfirst
    if int(days_between(theDate,nextfull)) == 0:
    	msg = 'Full moon:'
    	nextphase = nextfull
    if int(days_between(theDate,nextlast)) == 0:
    	msg = 'Last quarter:'
    	nextphase = nextlast
    if int(days_between(theDate,nextnew)) == 0:
    	msg = 'New Moon:'
    	nextphase = nextnew
    
    if len(msg) > 5:
    	(yy, mm, dd, h, m, s) = nextphase.tuple()
    	msg =   (msg+' '+
    			str(dd)+'/'+
    			twodigits(str(mm))+'/'+
    			twodigits(str(yy))+' '+
    			twodigits(str(h))+':'+
    			twodigits(str(m))+':'+
    			twodigits(str(int(s)))+
    			' UTC')
    	message = MIMEMultipart()
    	message['Subject'] = 'Moon phase change'
    	message['From'] = sender_email
    	message['Bcc'] = "," .join(receivers)
    	message.attach(MIMEText(msg, "plain"))
    	text = message.as_string()
    	try:
    		srv.starttls()
    		srv.login(sender_account,sender_pwd)
    		srv.sendmail(sender_email,receivers,text)
    	except Exception as e:
    		print(e)
    	finally:
    		srv.quit
    
DISTRIBUTED COMPUTING
  • Contribution to BOINC
    I'm a proud contributor to some science research using distributed computing to analyse huge amount of data.
    On December 2019 I set up 4 different Raspberry models (1B, 2B, 3B, 4B) stacked in a pile with fans in order to keep temperature as low as possible. On October 2021 one additional separate Zero2W was added to the group, for a total 5 boards working for the project.
    Due to highly increasing energy costs on June 2022 I sadly decided to reduce the whole group to a single unit, so the choice fell on the 4B model.
    The group board is running the open source BOINC software in order to help for the following projects:

    For my contribution - on March 3rd, 2022 - I was chosen as the User of the Day by the Universe@Home project:

    Universe@Home User of the Day

    On February 19th, 2023 it happened again:

    Universe@Home User of the Day

    ...and again on November 18th, 2023! I'm flattered...

    Universe@Home User of the Day

    Have a look at my ongoing contribution to Universe@Home data analysis on Black Holes.


    Here is my current BoincStats ranking:

    Bitstream's BOINC ranking

    Please consider helping too.
LEISURE AND FUN
  • Streaming & Music Player
    When it came out I had the opportunity to buy 2 new Raspberry Zero 2W and I suddenly put them in "production".

    The first one has been added to others contributing to my Distributed Computing project, the second one has been paired to a Pirate Audio Line-Out. The latter is a powerful HAT board with a high-quality I2S DAC I planned to use as a player for listening to streaming music through the PC speakers.

    To make it possible I downloaded and installed Volumio OS on the PiZero2W, then I connected the Pirate Audio lineout to the PC line-in and finally set the PC mixer up to give the right output.

    Volumio OS desktop
Questo sito usa i cookies: per continuare a navigare è necessario accettarne l'utilizzo. Altre info.    ACCETTO