http://matplotlib.org/users/
This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock
Thursday, April 13, 2017
Python Colormaps
Before using the python matplotlib color maps, please read this documentation:
http://matplotlib.org/users/ colormaps.html





http://matplotlib.org/users/
Friday, March 24, 2017
Multiprocessing vs Multithreading
I need to download files fast. I want to swamp my network cables to download as much as it can consume. In the past I've used multiprocessing because it was easy to split jobs to several processors. But it is more efficient to use multithreading.
Multithreading uses one processor, but you can set up a queue so that it will continuously run as much as it can handle.
As an example, here is some code...
There is speed up when downloading, and the copper wires are saturated with as much as it can handle with about 10 threads or ten processors.
Here is a visual of what I learned:
Multithreading uses one processor, but you can set up a queue so that it will continuously run as much as it can handle.
As an example, here is some code...
# Brian Blaylock
# March 24, 2017 Yesterday Salt Lake had lots of rain
"""
Fast download of HRRR grib2 files with threading
"""
from queue import Queue
from threading import Thread
from datetime import datetime, timedelta
import numpy as np
import urllib2
import re
import os
var='TMP:2 m'
def download(URL):
# Code to download something based on a URL
# ...
def worker():
while True:
item = q.get()
print "number:", item
download(item)
q.task_done()
num_of_threads = 10
q = Queue()
for i in range(num_of_threads):
t = Thread(target=worker)
t.daemon = True
t.start()
# List of URL's to download from
URL_list = ['...','...','...']
timer1 = datetime.now()
for item in URL_list:
q.put(item)
q.join() # block until all tasks are done
There is speed up when downloading, and the copper wires are saturated with as much as it can handle with about 10 threads or ten processors.
Here is a visual of what I learned:
Tuesday, February 14, 2017
not python, but I made a handy image viewer
This isn't Python, but I made a handy web page tool for viewing images in a directory. Just dump this photo_viewer.php page in a public_html web directory with images in it, and this page will let you view the images by hovering a mouse over buttons with the image names, clicking the buttons, or selecting images from an option box.
https://github.com/blaylockbk/Web-Homepage/blob/master/photo_viewer/photo_viewer.php
Example page: http://home.chpc.utah.edu/~u0553130/PhD/UWFPS_2017/time-height/photo_viewer.php
https://github.com/blaylockbk/Web-Homepage/blob/master/photo_viewer/photo_viewer.php
Example page: http://home.chpc.utah.edu/~u0553130/PhD/UWFPS_2017/time-height/photo_viewer.php
Friday, January 13, 2017
CGI: Plot mult-station time series
I created a quick web interface for plotting time series from multiple weather stations on the same plot. See here: http://home.chpc.utah.edu/~u0553130/Brian_Blaylock/cgi-bin/plot_ts_multistations.cgi
The code to create this is on github:
The web interface: https://github.com/blaylockbk/Web-Homepage/blob/master/cgi-bin/ts_multistations.cgi
The plotting function: https://github.com/blaylockbk/Web-Homepage/blob/master/cgi-bin/plot_ts_multistations.cgi
The code to create this is on github:
The web interface: https://github.com/blaylockbk/Web-Homepage/blob/master/cgi-bin/ts_multistations.cgi
The plotting function: https://github.com/blaylockbk/Web-Homepage/blob/master/cgi-bin/plot_ts_multistations.cgi
Thursday, January 5, 2017
Subscribe to:
Posts (Atom)
