analitics

Pages

Friday, March 24, 2017

Take weather data with pyowm from openweathermap .

This tutorial shows you how to download and install the pyowm python module.
One of the great things about using this python module let you to provide data from openweathermap website (need to have one account).
PyOWM runs on Python 2.7 and Python 3.2+, and integrates with Django 1.10+ models.
All documentation can be found here.

The install is simple with pip , python 2.7 and Fedora 25.
 
[root@localhost mythcat]# pip install pyowm
Collecting pyowm
  Downloading pyowm-2.6.1.tar.gz (3.6MB)
    100% |████████████████████████████████| 3.7MB 388kB/s 
Building wheels for collected packages: pyowm
  Running setup.py bdist_wheel for pyowm ... done
  Stored in directory: /root/.cache/pip/wheels/9a/91/17/bb120c765f08df77645cf70a16aa372d5a297f4ae2be749e81
Successfully built pyowm
Installing collected packages: pyowm
Successfully installed pyowm-2.6.1
The source code is very simple just connect with API key and print data.
#/usr/bin/env python
#" -*- coding: utf-8 -*-
import pyowm

print " Have a account to openweathermap.org and use with api key free or pro"
print " owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')"

owm = pyowm.OWM("327407589df060c7f825b63ec1d9a096")  
forecast = owm.daily_forecast("Falticeni,ro")
tomorrow = pyowm.timeutils.tomorrow()
forecast.will_be_sunny_at(tomorrow)  

observation = owm.weather_at_place('Falticeni,ro')
w = observation.get_weather()
print (w)                     
print " Weather details"
print " =============== "
                                    
print " Get cloud coverage"
print w.get_clouds() 
print " ----------------"                                     
print " Get rain volume"
print w.get_rain() 
print " ----------------"
print " Get snow volume"
print w.get_snow()                                       

print " Get wind degree and speed"
print w.get_wind() 
print " ----------------"                                      
print " Get humidity percentage"
print w.get_humidity()    
print " ----------------"                               
print " Get atmospheric pressure"
print w.get_pressure()                                   
print " ----------------"
print " Get temperature in Kelvin degs"
print w.get_temperature() 
print " ----------------"                              
print " Get temperature in Celsius degs"
print w.get_temperature(unit='celsius')
print " ----------------"                 
print " Get temperature in Fahrenheit degs"
print w.get_temperature('fahrenheit')                    
print " ----------------"
print " Get weather short status"
print w.get_status()                                     
print " ----------------"
print " Get detailed weather status"
print w.get_detailed_status()                           
print " ----------------"
print " Get OWM weather condition code"
print w.get_weather_code()                               
print " ----------------"
print " Get weather-related icon name"
print w.get_weather_icon_name()                          
print " ----------------"
print " Sunrise time (ISO 8601)"
print w.get_sunrise_time('iso')    
print " Sunrise time (GMT UNIXtime)"
print w.get_sunrise_time()                               
print " ----------------"
print " Sunset time (ISO 8601)"
print w.get_sunset_time('iso')  
print " Sunset time (GMT UNIXtime)"
print w.get_sunset_time()                          
print " ----------------"
print " Search current weather observations in the surroundings of"
print " Latitude and longitude coordinates for Fălticeni, Romania:"
observation_list = owm.weather_around_coords(47.46, 26.30)

Let's see and the result of running the python script for one random location:
 
[root@localhost mythcat]# python openweather.py 
 Have a account to openweathermap.org and use with api key free or pro
 owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')

 Weather details
 =============== 
 Get cloud coverage
20
 ----------------
 Get rain volume
{}
 ----------------
 Get snow volume
{}
 Get wind degree and speed
{u'speed': 5.7, u'deg': 340}
 ----------------
 Get humidity percentage
82
 ----------------
 Get atmospheric pressure
{'press': 1021, 'sea_level': None}
 ----------------
 Get temperature in Kelvin degs
{'temp_max': 287.15, 'temp_kf': None, 'temp': 287.15, 'temp_min': 287.15}
 ----------------
 Get temperature in Celsius degs
{'temp_max': 14.0, 'temp_kf': None, 'temp': 14.0, 'temp_min': 14.0}
 ----------------
 Get temperature in Fahrenheit degs
{'temp_max': 57.2, 'temp_kf': None, 'temp': 57.2, 'temp_min': 57.2}
 ----------------
 Get weather short status
Clouds
 ----------------
 Get detailed weather status
few clouds
 ----------------
 Get OWM weather condition code
801
 ----------------
 Get weather-related icon name
02d
 ----------------
 Sunrise time (ISO 8601)
2017-03-24 04:08:33+00
 Sunrise time (GMT UNIXtime)
1490328513
 ----------------
 Sunset time (ISO 8601)
2017-03-24 16:33:59+00
 Sunset time (GMT UNIXtime)
1490373239
 ----------------
 Search current weather observations in the surroundings of
 Latitude and longitude coordinates for Fălticeni, Romania:

Thursday, March 16, 2017

The tensorflow python module - part 003.

This short tutorial come to fix your work and help you with examples and tutorials.
You can look to the internet and you can search many examples and tutorials but you can get errors.
How to fix that:
The first step is to know what tensorflow version of you use.
[mythcat@localhost ~]$ python -c "import tensorflow; print(tensorflow.__version__)"
1.0.1
Then yo need to know what parts from tensorflow old version is deprecated from the last version.
One superannuated method is to fix old source code with this:
import tensorflow as tf
tf.scalar_summary = tf.summary.scalar
tf.merge_all_summaries = tf.summary.merge_all
tf.train.SummaryWriter = tf.summary.FileWriter
A better method is to fix your source code and read the documentation.

Monday, March 13, 2017

The tensorflow python module - part 002.

Today I will show you how to install tensorflow python module on Windows OS with pip tool.
I used python version 3.5.3.
C:\Python35>cd Scripts

C:\Python35\Scripts>pip3 install --upgrade tensorflow
Collecting tensorflow
  Downloading tensorflow-1.0.1-cp35-cp35m-win_amd64.whl (14.7MB)
    100% |################################| 14.7MB 43kB/s
...
Successfully installed appdirs-1.4.3 numpy-1.12.0 packaging-16.8 
protobuf-3.2.0 pyparsing-2.2.0 setuptools-34.3.2 six-1.10.0 
tensorflow-1.0.1 wheel-0.29.0
Next step is to install the GPU version of TensorFlow:
C:\Python35\Scripts>pip3 install --upgrade tensorflow-gpu
Collecting tensorflow-gpu
  Downloading tensorflow_gpu-1.0.1-cp35-cp35m-win_amd64.whl (43.1MB)
    100% |################################| 43.1MB 11kB/
...
Installing collected packages: tensorflow-gpu
Successfully installed tensorflow-gpu-1.0.1
If you are installing TensorFlow with GPU support then the following NVIDIA software must be installed on your system:

CUDA Toolkit 8.0. , the NVIDIA drivers associated with CUDA Toolkit 8.0 and cuDNN v5.1.
The cuDNN is typically installed in a different location from the other CUDA DLLs.
Now you need to add the directory where you installed the cuDNN DLL to your %PATH% environment variable.
The result will be output under python result when you import this python module, see my output:
 Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 740M, pci bus id: 0000:01:00.0)

Friday, March 10, 2017

Strange code in python.

Try this:

>>> 2*2
4
>>> _*2
8
>>> print _*3
24
>>> print _*'a'
aaaaaaaa