analitics

Pages

Thursday, August 10, 2017

The pysolar - python module.

Today I tested another python module named pysolar with python 2.7 and 3.6.2 versions.
You can read more about this python module here:
Pysolar is a collection of Python libraries for simulating the irradiation of any point on earth by the sun. It includes code for extremely precise ephemeris calculations and more.
Using pip under Windows OS to install this python module:
C:\Python27\Scripts>pip install pysolar
...
Successfully built pysolar
Installing collected packages: pysolar
Successfully installed pysolar-0.7
I try also with python 3.6.2 version:
C:\Python362\Scripts>pip install pysolar
Collecting pysolar
  Using cached pysolar-0.7.tar.gz
Installing collected packages: pysolar
  Running setup.py install for pysolar ... done
Successfully installed pysolar-0.7
Let's start with a simple example to calculate the angle between the sun and a plane tangent to the earth where
you are:
C:\Python362>python.exe
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysolar.solar import *
>>> import datetime
>>> my_data = datetime.datetime.now()
>>> print (my_data)
2017-08-10 18:12:01.997373
>>> get_altitude_fast(47.4616,26.3015,datetime.datetime.now())
-6.393190003993212
Let's try the scattering of light by the atmosphere, though it uses an
atmospheric model based on data taken in the United States:
>>> latitude_deg =47.2741
>>> longitude_deg = 26.185
>>> my_data = datetime.datetime.now()
>>> altitude_deg = get_altitude(latitude_deg, longitude_deg,my_data)
C:\Python362\lib\site-packages\pysolar\time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)
>>> azimuth_deg = get_azimuth(latitude_deg, longitude_deg,  my_data)
>>> radiation.get_radiation_direct(my_data, altitude_deg)
634.4916522219954
About this issue:I don't know about leap seconds after 2015 read here.

Using Flask and Flask-WTF to build websites in Python 2.7 and 3.6.2 - part 002.

This is one update of my old tutorial about Flask and python 2.7 under Linux from here.
The default install of python 2.7 and pip is very simple - read this tutorial.
First, you need to install the Flask python module under Windows 10:
C:\Python27\Scripts>pip install Flask
Collecting Flask
Downloading Flask-0.11.1-py2.py3-none-any.whl (80kB)
100% |################################| 81kB 564kB/s
Collecting click>=2.0 (from Flask)
Downloading click-6.6-py2.py3-none-any.whl (71kB)
100% |################################| 71kB 1.3MB/s
Collecting Werkzeug>=0.7 (from Flask)
Downloading Werkzeug-0.11.11-py2.py3-none-any.whl (306kB)
100% |################################| 307kB 231kB/s
Collecting Jinja2>=2.4 (from Flask)
Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
100% |################################| 266kB 890kB/s
Collecting itsdangerous>=0.21 (from Flask)
Downloading itsdangerous-0.24.tar.gz (46kB)
100% |################################| 51kB 1.3MB/s
Collecting MarkupSafe (from Jinja2>=2.4->Flask)
Downloading MarkupSafe-0.23.tar.gz
Installing collected packages: click, Werkzeug, MarkupSafe, Jinja2, itsdangerous
, Flask
Running setup.py install for MarkupSafe ... done
Running setup.py install for itsdangerous ... done
Successfully installed Flask-0.11.1 Jinja2-2.8 MarkupSafe-0.23 Werkzeug-0.11.11
click-6.6 itsdangerous-0.24
The simple example of the running Flask python module is one script named hello.py:
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
Using the command to run the script and show the result into your browser:
C:\Python27>python.exe hello.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Now the installation of Flask-WTF python module:
C:\Python27\Scripts>pip install Flask-WTF
Collecting Flask-WTF
  Downloading Flask_WTF-0.14.2-py2.py3-none-any.whl
Collecting WTForms (from Flask-WTF)
  Downloading WTForms-2.1.zip (553kB)
    100% |################################| 563kB 1.7MB/s
Requirement already satisfied: Flask in c:\python27\lib\site-packages (from Flask-WTF)
Requirement already satisfied: click>=2.0 in c:\python27\lib\site-packages (from Flask->Flask-WTF)
Requirement already satisfied: Werkzeug>=0.7 in c:\python27\lib\site-packages (from Flask->Flask-WTF)
Requirement already satisfied: Jinja2>=2.4 in c:\python27\lib\site-packages (from Flask->Flask-WTF)
Requirement already satisfied: itsdangerous>=0.21 in c:\python27\lib\site-packages (from Flask->Flask-WTF)
Requirement already satisfied: MarkupSafe>=0.23 in c:\python27\lib\site-packages (from Jinja2>=2.4->Flask->Flask-WTF)
Installing collected packages: WTForms, Flask-WTF
  Running setup.py install for WTForms ... done
Successfully installed Flask-WTF-0.14.2 WTForms-2.1
Now I try with Python 3.6.2 with both python modules and works great.
C:\Python362\Scripts>pip3.6.exe install flask
...
Successfully installed Jinja2-2.9.6 MarkupSafe-1.0 Werkzeug-0.12.2 click-6.7 flask-0.12.2 itsdangerous-0.24

C:\Python362\Scripts>Flask-WTF
'Flask-WTF' is not recognized as an internal or external command,
operable program or batch file.

C:\Python362\Scripts>pip3.6.exe install Flask-WTF
...
Successfully installed Flask-WTF-0.14.2 WTForms-2.1