Jacknife

The Jacknife  is also sometimes called the “Leave One Out” method, and is a method to somehow evaluate the stability of statistics done on data. By leaving one element out of the input array and studying the mean of the values, one can identify outliers. Here is a small Python implementation, generalised to “Leave N…

I’m 30…

24 September 1983. I’m born. Since then, damn, already 30 years… I’m not going to talk about my life, it’s not even interesting to myself. I’d rather give a brief history of the IT background I’ve learnt during the last 21-something years. It all started when I was 9, in the primary school classroom where…

Pack an Enthought Traits app inside a .exe using py2exe (Canopy Edit)

10 months ago, I published the updated version of my tutorial to pack an Enthought TraitsUI based application inside an .exe Windows Executable file, using a standard Python 2.7 install and the Enthought Tool Suite 4.0 (ETS4.0). In April 2013, Enthought published their latest distribution called “Canopy”. This distribution marks a clear change in the…

Old 16bit DOS programs on Windows 7 (x64)

We needed to execute an old-but-working 16bits program to locate earthquakes called “HypoEllipse” (source), but calling it from the Windows 7 x64 boxes resulted in a nice : Bam ! Not working, sorry for you… No ! I say No ! Some great guys developed “DosBOX”: a super emulator for old-but-working DOS applications ! All…

North Korean nuclear tests with Obspy

This morning, North Korea tested some nuclear “bomb” somewhere in the middle of the country (confirmed by Pyongyang officials and CTBTO), and many seismic sensors worldwide recorded the triggered waveforms. The location of the test is the same as the 2009 one, confirmed by the location provided by global monitoring networks (USGS, GEOFON). To pythonise…

New Tutorial Series: Pandas

In the coming months, I’ll prepare some tutorials over an excellent data analysis package called pandas ! To show you the power of pandas, just take a look at this old tutorial, where I exploited the power of itertools to group sparse data into 5 seconds bins. The magic of pandas is that, when you…

Honoured !

This blog is cited in the excellent book of Wes McKinney: “Python for Data Analysis” (eds.O’Reilly)! Oh yeah! I’m proud! Thanks Wes!    

New Theme

Geophysique.be has been updated to WordPress 3.5 and while the previous theme is still compatible with this new version, I’ve decided to switch to the very clean TwentyTwelve theme. This theme is completely responsive, so the site is now viewable on smartphones and tabs !!

Matplotlib & Datetimes – Tutorial 02: Bar Plot

To add some interesting information to the previous tutorial, I’ve downloaded the number of licence plates given for new cars in Belgium for the same time span: 2005 587764 2006 633570 2007 644313 2008 652590 2009 571001 2010 642086 2011 679619 Load them in the same fashion: plates, number = np.loadtxt(‘newplates.txt’,skiprows=1,unpack=True) xdates2 = [datetime.datetime.strptime(str(int(date)),’%Y’) for…

Aardbeving in West-Vlaanderen

Vanavond om 20:38, een aardbeving vond plaats in West-Vlaanderen. Het werd gevoeld door de bevolking in de dorpen van Ruddervoorde, Zedelgem en misschien zelfs tot Brugge. Iedereen die heeft het gevoeld is uitgenodigd om de enquête in te vullen op onze website:   Ce soir, à 20h38, un séisme a eu lieu en Flandre Occidentale.…

Matplotlib Basemap tutorial 09: Drawing circles

In the previous tutorial, I defined a “shoot” method to compute the landing point of a shoot from one point, to a given azimuth and distance. Using this logic, it’s possible to find the points situated at a given distance from a “centre” point, a circle. The goal: Drawing circles of a given radius around…

Matplotlib Basemap tutorial 08: Shooting Great Circles

Following a question from Ricardo Gama (see his comment), I’ve prepared this new tutorial. He wondered if Basemap has a function similar to the track1 function in matlab (you know, that crappy costly thing…)… Here is what I obtained : The goal: Plotting great circles with Basemap, but knowing only the longitude, latitude, the azimuth…

Matplotlib Basemap: Tell me what you need !

Dear visitors, I’m always searching new ideas of preparing new tutorials for things doable with Basemap, but I’d like these examples to be as useful as possible, which means : If you have something you would like to appear here, please, use the Comment box below to tell me ! I’ll do my best to…

Numpy Trick 01

I usually forget how much Numpy makes life easy : Say, you have a 101 element array, e.g.: import numpy as np a = np.linspace(0,100,101) and you want to take every 4th item in that array, that’s as easy as : print a[::4] will output: array([0., 4., … , 96., 100.]) I love Numpy !

Numpy.ma not always necessary

I just discovered that there is an easier way to do this (e.g. from tutorial06): import numpy.ma as ma mask = ma.masked_where(countries[‘ISO’] != iso, countries[‘ISO’]) country = ma.array(countries[‘country’],mask=mask.mask).compressed()[0] by using the built-in numpy.where method: import numpy as np index = np.where(countries[‘ISO’] == iso) country = countries[‘country’][index][0] Yeah, that’s fun ! The numpy.where method takes two…

Don’t be scared …

Don’t be scared, you are on geophysique.be ! I’m just trying some new themes for this blog/website. I want to make it more readable, but also easier to search/scroll. I kinda like this “eos” theme, the “content” column is nice and large, quite good for my python pre formatted code snippets. I also like the…

Matplotlib Basemap tutorial 06: Real Case pie charts

Here is a new tutorial that will include “a bit of all” tutorials previously published on this blog and some new cool stuff to play with ! Idea: Find some resources on the Internet and plot them on the map of Europe ! In brief: do that: Step 0: Input Preparation I found some statistics…

Update to ETS 3.5.0 !

Great news from last week : ETS 3.5.0 is out ! Note the change in the source-download process.. Now using an unique ets.py file instead of the ProjectTools ! http://blog.enthought.com/open-source/enthought-tool-suite-3-5-0-released/ http://www.optiniche.com/blog/117/wordpress-trackback-tutorial/

Matplotlib Basemap tutorial 04 : using inside_poly() to select data !

# remember to define the ax instance : ax = plt.subplot(111) zone = “Roetgen – Monschau” x,y = m(6.15,50.41) x2,y2 = m(6.59,50.67) x3,y3 = m(6.34,50.855) x4,y4 = m(5.83,50.65) data = np.array(([x,x2,x3,x4], [y,y2,y3,y4])) p = Polygon(data.T,edgecolor=’red’,linewidth=1.5,facecolor=’none’) ax.add_artist(p) Note that we have an array containing the points already projected using m(x,y) : basemapped_points x,y = m(data[:,0],data[:,1]) data[:,0]=x…

Matplotlib Basemap tutorial 03 : Masked arrays & Zoom

Here, we will focus on adding a “zoom box” on the top left corner of the plot. But before that, we will mask a part of the earthquakes, in order to have a “cleaner” map ! This is achieved by using the numpy.ma module : import numpy.ma as ma Mlon = ma.masked_outside(lon, 5.6, 7.5) #…

Matplotlib Basemap tutorial 02 : Let’s add some earthquakes !

Now, let’s imagine we have a dataset containing latitude/longitudes of earthquakes, plus their depth and magnitude. Of course, you don’t always have this dataset available, so let’s build a fake one : import numpy as np lon = np.random.random_integers(11,79,1000)/10. lat = np.random.random_integers(491,519,1000)/10. depth = np.random.random_integers(0,300,1000)/10. magnitude = np.random.random_integers(0,100,1000)/10. We create random integer values, and we…

Matplotlib Basemap tutorial 01 : Your first map

# # BaseMap example by geophysique.be # tutorial 01 from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(11.7,8.3)) #Custom adjust of the subplots plt.subplots_adjust(left=0.05,right=0.95,top=0.90,bottom=0.05,wspace=0.15,hspace=0.05) ax = plt.subplot(111) #Let’s create a basemap around Belgium m = Basemap(resolution=’i’,projection=’merc’, llcrnrlat=49.0,urcrnrlat=52.0,llcrnrlon=1.,urcrnrlon=8.0,lat_ts=51.0) m.drawcountries(linewidth=0.5) m.drawcoastlines(linewidth=0.5) m.drawparallels(np.arange(49.,53.,1.),labels=[1,0,0,0],color=’black’,dashes=[1,0],labelstyle=’+/-‘,linewidth=0.2) # draw parallels m.drawmeridians(np.arange(1.,9.,1.),labels=[0,0,0,1],color=’black’,dashes=[1,0],labelstyle=’+/-‘,linewidth=0.2) # draw meridians plt.show()

Installing EPD on Windows 7 (64bits)

I finally managed to install Enthought Python Distribution on my Windows 7 64bit box. In fact, I installed EPD 32bits (I’m a student, the academic licence is free). So, the solution was in the Mailing List Archive (enthought-dev) : Disable the UAC (User Account Control) of Windows 7 in order to let the msi installer…

Stop using griddata, use matplotlib.mlab.griddata !

I just discovered that I was using from griddata import griddata in quite a lot of python scripts I wrote for scientific data plotting. While struggling to recompile it under my new win7 x64 box, I googled a little and found out that it’s now included in matplotlib (which was already installed…). So, now, I’ll…

Bonjour tout le monde !

Premier billet de “Géophysique.be”, où je publierai des informations en relation avec la Géophysique, les méthodes de prospection, leur théorie, des exemples de codes informatiques de traitement de données scientifiques, … Un premier code python pour démarrer : print “Hello World !!” First note on “Geophysique.be”, where I’ll post information about Geophysics, prospection methodologies, the…