Commit 921632f1 authored by Thorsten Alteholz's avatar Thorsten Alteholz
Browse files

initial commit of Python3 port

parent e213bd56
Loading
Loading
Loading
Loading

CHANGELOG.txt

0 → 100755
+73 −0
Original line number Diff line number Diff line
Version 0.4.0
	general:
		port to python3

Version 0.3.1
	general:
		Disable by default datacenter
	plot:
		Change default plot size
		Use tight_layout
		Improve detection of AM/PM dates
		Allow to plot only the 2nd plot (NSB vs datetime)
		plot.py now works also as a standalone tool (with user provided data file path).


Version 0.3.0
	general:
	    Added datacenter support


Version 0.2.2
	general:
		Adopt v1.0 of the standard format
		 (including the filename for the daily data and plots)
	read:
		put the rx,cx and ix data in the header
	plot:
		Change de Serial number label		
		

Version 0.2.1
	read:
		Print the errors in make_plot call on screen.
	plot:
		Only print the PM/AM/Moon labels on one panel.
		Print the SQM serial number.

Version 0.2.0
	general:
		Deep changes to make the program more modular.
		The program now can be packaged as a single .exe file with PyInstaller.
		The program can also be packaged for Linux systems.
	read:
		Try to use the fixed device address before looking for it automatically
		 this should allow the use of multiple devices in a single computer.
	plot:
		Code cleanup.
		Use local date/time in plots.
		Write statistics file.
		Use pyephem to calculate the moon phase (more accurate).
		Show the Moon max altitude (transit altitude or culmination).
		Plot the astronomical twilights.
		Object Oriented programming.
	email:
		Now the program can be distributed without email module.

Version 0.1.X
	read:
		Variables moved to config file.
		Clean-up of the code.
		Improve device reset.
		New read software. OO programing.
	plot:
		Variables moved to config file.
		Renamed from plot_sqmle.py to pysqm_plot.py
		Make the code and linebreaks less ugly
		Fixed axis.
		Moon phase plot.
	email:
		Renamed from email_sqmle.py to pysqm_email.py  

Version 0.0.X
	First version.

MANIFEST.in

0 → 100644
+1 −0
Original line number Diff line number Diff line
include LICENSE.txt

README.txt

0 → 100644
+115 −0
Original line number Diff line number Diff line
PySQM
=====

PySQM is a multi-platform, open-source software designed to read and
plot data from Unihedron SQM-LE and SQM-LU photometers, giving as 
an output files with the 'International Dark Sky Association (IDA) 
NSBM Community Standards for Reporting Skyglow Observations' format
(http://www.darksky.org/night-sky-conservation/248).

PySQM is distributed under GNU GPL, either version 3 of the License, 
or (at your option) any later version. See the file LICENSE.txt for details.

This software has been developed by Mireia Nievas <mnievas@ucm.es> with
the invaluable help of:

 - Sergio Pascual (UCM)
 - Jaime Zamorano (UCM)
 - Laura Barbas (OAN)
 - Pablo de Vicente (OAN)

The initial port to Python3 has been done by Anthony Tekatch (Unihedron).

SETUP
=====

After downloading the software, you need to modify the file config.py. 
In this file you will find several variables that need to be configured
to match your hardware settings. For example:

 - Location of the observatory (geographical coordinates).
 - Device identifier.
 - Device address (either IP address for SQM-LE or COM/ttyUSB port).
 - Location of the data files.
 - Axis limits for the plot.

Remember that python (2.7) syntax is mandatory in this file


HOW TO USE THE SOFTWARE
=======================

After configuring the software, make sure you are in the parent directory were
the README, LICENSE and MANIFEST files are located
> ls 
LICENSE.txt  MANIFEST.in  README.txt  pysqm  config.py  setup.py

And then run the software.
> python -m pysqm 

The program should find your SQM device and the data adquisition.will start 
(if it's night-time). 

In some systems, where python3 is the default version of python, you need 
to specify python2 as the interpreter to use. This is done usually running 
it as:

> python2 -m pysqm

or

> python2.7 -m pysqm

Note: running the setup.py script is neither tested nor required.
The program is currently being redesigned as a normal python package, but at 
present no setup is required.


HOW IT WORKS
============

In a first step, the program tries to connect to the SQM photometer and takes
some 'tests' measures (metadata/information, calibration and data) to check 
that the device is working as expected. 

After that, the program begins data acdquisition. In each iteration, it checks 
whether it is night-time. In that case new data is taken. 

Each N measurements, the main program calls a plotting function to generate 
a graphical representation of the current nightly data.


PySQM known issues
==================

Non-ASCII characters are not supported in the config.py file. Please, avoid using 'ñ', accented vowels, etc.
In headless systems, such as the Raspberry PI, if you run the program without X, you may suffer from the following fatal error when the program tries to generate the plot:

This application failed to start because it could not find or load the Qt platform plugin “xcb”.
Available platform plugins are: eglfs, kms, linuxfb, minimal, minimalegl, offscreen, xcb.
Reinstalling the application may fix this problem.  Aborted (core dumped)

In order to avoid this problem, you need to create (or modify if the file exists) in your HOME directory the following file: 

.config/matplotlib/matplotlibrc

You just need to set the matplotlib backend to Agg:
backend : Agg

Save the changes and exit. Now, PySQM should make the plots without issues. You may need to restart PySQM to apply the changes.

Path to EXE files (windows only):
https://www.dropbox.com/s/xlbr6ktk8spjsse/PySQM.exe?dl=0

CHANGELOG
=========

v0.3:
    Added datacenter option (optional, disabled by default)

v0.2:
    ...

v0.1:
    ...

config.py

0 → 100644
+109 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

'''
PySQM configuration File.
____________________________

Copyright (c) Mireia Nievas <mnievas[at]ucm[dot]es>

This file is part of PySQM.

PySQM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PySQM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PySQM.  If not, see <http://www.gnu.org/licenses/>.

____________________________
Notes:

You may need to change the following variables to match your
observatory coordinates, instrumental properties, etc.

Python syntax is mandatory.
____________________________
'''


'''
-------------
SITE location
-------------
'''

_observatory_name = 'GURUGU'
_observatory_latitude  = 40.447862
_observatory_longitude = -3.364992
_observatory_altitude  = 680
_observatory_horizon   = 10     # If Sun is below this altitude, the program will take data

_device_shorttype = 'SQM' # Device STR in the file
_device_type = 'SQM_LU'   # Device type in the Header
_device_id = _device_type + '-' + _observatory_name # Long Device lame
_device_locationname = 'Villalbilla/Spain - Observatorio GURUGU'         # Device location in the world
_data_supplier = 'Mireia Nievas / Universidad Complutense de Madrid'  # Data supplier (contact)
_device_addr = '/dev/ttyUSB1'  # Default IP address of the ethernet device (if not automatically found)
_measures_to_promediate = 1       # Take the mean of N measures
_delay_between_measures = 2    # Delay between two measures. In seconds.
_cache_measures = 1             # Get X measures before writing on screen/file
_plot_each = 1                 # Call the plot function each X measures.

_use_mysql = False        # Set to True if you want to store data on a MySQL db.
_mysql_host = None        # Host (ip:port / localhost) of the MySQL engine.
_mysql_user = None        # User with write permission on the db.
_mysql_pass = None        # Password for that user.
_mysql_database = None    # Name of the database.
_mysql_dbtable = None     # Name of the table
_mysql_port = None        # Port of the MySQL server.

_local_timezone     = +1     # UTC+1
_computer_timezone  = +0     # UTC
_offset_calibration = -0.11  # magnitude = read_magnitude + offset
_reboot_on_connlost = False  # Reboot if we loose connection

# Monthly (permanent) data
monthly_data_directory = "/tmp/sqm_gurugu/"
# Daily (permanent) data
daily_data_directory = monthly_data_directory+"/datos_diarios/"
limits_nsb = [20.0,16.5] # Limits in Y-axis

# Daily (permanent) graph
daily_graph_directory = monthly_data_directory+"/graficos_diarios/"
# Current data, deleted each day.
current_data_directory = monthly_data_directory
# Current graph, deleted each day.
current_graph_directory = monthly_data_directory
# Summary with statistics for the night
summary_data_directory = monthly_data_directory


'''
----------------------------
PySQM data center (OPTIONAL)
----------------------------
'''

# Send the data to the data center
_send_to_datacenter = False


'''
Ploting options
'''
full_plot = True
limits_nsb = [20.0,16.5] # Limits in Y-axis
limits_time   = [17,9] # Hours
limits_sunalt = [-80,5] # Degrees

'''
Email options
'''
_send_data_by_email = False

pysqm/__init__.py

0 → 100644
+44 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

'''
PySQM __init__ code
____________________________

Copyright (c) Mireia Nievas <mnievas[at]ucm[dot]es>

This file is part of PySQM.

PySQM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PySQM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PySQM.  If not, see <http://www.gnu.org/licenses/>.
'''

__author__ = "Mireia Nievas"
__copyright__ = "Copyright (c) 2014 Mireia Nievas"
__credits__ = [\
 "Mireia Nievas @ UCM",\
 "Jaime Zamorano @ UCM",\
 "Laura Barbas @ OAN",\
 "Pablo de Vicente @ OAN"\
 "Anthony Tekatch @ Unihedron "\
 ]
__license__ = "GNU GPL v3"
__shortname__ = "PySQM"
__longname__ = "Python Sky Quality Meter pipeline"
__version__ = "0.4.0"
__maintainer__ = "Thorsten Alteholz"
__email__ = "python[at]alteholz[dot]de"
__status__ = "Development" # "Prototype", "Development", or "Production"

from types import ModuleType
import sys
Loading