Skip to content

Géophysique.be

Dr. Thomas Lecocq : Seismologist – Geologist @ the Royal Observatory of Belgium

Following a very old post (link), and questions from Matthias and Kevin, I’ve finally managed to test the R2-related scripts I wrote long-long time ago…

I’m really sorry, but don’t quite have the time now to really document all functions/actions, but it should be quite straightforward. This script assumes you start from a ABEM S4K file, or with a ABEM AMP file converted using the command ‘s 4kconv.exe -F:a -z0 -x myinputfile.s4k’. If you have the S4K file, you should be able to convert is on the fly with the script (look for the “convert=False” flag). There are no fancy python imports, except the classic trio: numpy, scipy and matplotlib.

NOTE: there seems to be a problem with the os.spawnl() call to R2.exe within the code, I don’t quite know why for now. So, to run the test, I simply launched R2.exe in console and re-ran the python script to plot the results.

The ouptut of the test case should look like :

The scripts, thus, expects :

  • a data folder with
  • a .S4K of .AMP file
  • a .wgs84 file, N lines of ‘LON LAT ALT’, 1 per electrode
  • R2.exe
  • if you need to convert, a folder with the s4kconv.exe program
  • This code should really be improved to be more “dynamic”, if you edit/modify/improve it, please report back and I’ll update/add your contribution to this blog.

    The full code and the example data files are present after the break !

    continue reading…

    Le site web de ma soeur et de ma mère est en ligne !

    Visitez, réservez ! Ca détend !

    http://www.youdo.be !

    Dag iedereen, Bonjour à tous,

    Gisterenavond om 21u02, was er een aardbeving van magnitude ML=4.3 bij de grens tussen Duitsland en Nederland, 15 km ten zuidoosten van Nijmegen. Het werd gevoeld door veel mensen in Brussel, Leuven en Luik. Iedereen die het gevoeld heeft kan de enquête invullen op onze website:

     

    Hier soir, à 21h02, un séisme de magnitude ML=4.3 a eu lieu à la frontière entre l’Allemagne et les Pays-Bas, à 15 km au sud est de Nijmegen. Il a été ressenti par plusieurs personnes à Bruxelles, Leuven et Liège. Quiconque l’ayant ressenti est invité à remplir l’enquête sur notre site internet:

    Yesterday evening, at 21:02, a magnitude ML4.3 earthquake occurred at the border between Germany and The Netherlands. Some people also felt it in Brussels, Leuven or Liège. Anyone who felt it is invited to fill in the inquiry on our website :

     

    http://seismologie.be

    AUB, stuur deze email naar u vrienden/familie !

    SVP transmettez cet email à vos amis/famille !

    Please forward to your friends/family !
    Merci,

    Thomas

    
    

    Obspy is a really cool package for seismological observatories. In fact, it’s a super set of packages. They are distributed using eggs and have a nice way of declaring namespaces and entry points.

    The disadvantage, in my case, is that the namespace- approach is quite not compatible with py2exe (will maybe/surely change one day)…

     

    So, to create a super simple test case to try different approaches suggested in the obspy-users mailing list, I went for this :

    import sys, os
    file = open('eggs.pth','r')
    for path in file.readlines():
        sys.path.append(os.path.join(os.getcwd(),path.replace('\n','')))
    sys.path.append(os.getcwd())
    
    from obspy.core import read
    
    st = read(r'test.gse',verify_chksum=False)
    
    for trace in st.traces:
        print trace.stats

    and called it ‘gseinfo.py’. We will need to create a eggs.pth file inside the directory to make sure the script does find the eggs.

     

    The idea here is to collect the required eggs names from the osbpy.gse2 module, build a complete list of files that will be copied by py2exe as data_files.

    Py2exe data_files is  a list of tuples formatted as (relative_destination_folder, array of source files). To do it easily, I append every file to the data_files array using a walk method :

    def walk(path):
        names = os.listdir(path)
        for name in names:
            fname = os.path.join(path,name)
    
            if os.path.isdir(fname):
                walk(fname)
            else:
                destination = os.path.join(path.replace('c:\python27\lib\site-packages\\',''))
                source = os.path.join(path, name)
                global data_files
                print source, "->>", destination
                data_files.append((destination,[source]))

    Note the replace part, needed to create the relative destination path.

    The required modules are obtained this way :

    eggs = pkg_resources.require("obspy.gse2")
    eggpacks = set()
    eggspth = open("dist/eggs.pth", "w")
    
    for egg in eggs:
        print "EGG:", egg.egg_name()
        try:
            eggspth.write(os.path.basename(egg.location))
            eggspth.write("\n")
            eggpacks.update(egg.get_metadata_lines("top_level.txt"))
    
            print os.path.basename(egg.location), egg.location
            if egg.egg_name().count('setuptools') != 0 :
                walk(egg.location+'-info')
                egg.location = egg.location.replace('-0.6c11-py2.7.egg','')
    
            walk(egg.location)
    
        except:
            pass
    
    eggspth.close()

    In this part, it is important to note that we create a eggs.pth file in the output /dist directory. Then we process the eggs one by one, calling the walk method. There is a special case we need to take care of, indeed, the setuptools egg does not install like a regular egg inside a single folder, but has a setuptools/ folder in addition to a setuptools-06c11-py2.7.egg/ folder. Your installation may vary in this.

    One SUPER important note is that, although I’m using obspy.* and setuptools eggs, I don’t want to use numpy eggs (crappy links to scipy eggs that are far less easy to install on windows than the scipy.exe from sf.net) … But, if I leave osbpy as-is, the obspy.gse module will ask for a numpy>=1.1.0 (as stated in obspy.core-0.4.8-py2.7.egg\EGG-INFO\requires.txt).

    The solution is simply to remove the line from requires.txt (will be empty), and to include the numpy package in the normal way of py2exe :

    includes = []
    includes.append('numpy')

    and to finally define the setup function :

    setup(console=['gseinfo.py'],
        author="ROB Seismology - THOMAS LECOCQ",
        version = "1.0",
        description = "gseinfo",
        name = "gseinfo",
        options = {"py2exe": {    "optimize": 0,
                                  "packages": packages,
                                  "includes": includes,
                                  "dist_dir": 'dist',
                                  "bundle_files":2,
                                  "xref": False,
                                  "skip_archive": True,
                                  "ascii": False,
                                  "custom_boot_script": '',
                                  "compressed":False,
                                  "dll_excludes":["MSVCP90.dll", 'libiomp5md.dll',
    'libifcoremd.dll','libmmd.dll' , 'svml_dispmd.dll','libifportMD.dll' ]
                                 },},data_files=data_files)

    Note, I’ve excluded some annoying .dll files, I still have to test whether the .exe is fully portable that way.

     

    Running $python setup.py py2exe will build the .exe in a /dist directory BUT will not bundle all files inside a single EXE. As for now, I don’t care about have 100MB of files and folders in the my application directory ; Moreover, my bigger project runs on Enthought Tool Suite and can’t be zipped to a single Library.zip. One could try the last step of this tutorial, but I’m not quite sure it will work.

    Please let me know if you find an easier way… Py2exe guys, pleeeeeeeeeeeeease, find a way to support that asap :-)

    Cheers,

    (the full setup.py is after the break :)

    continue reading…

    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. Il a été ressenti par la population dans les villages de Ruddervoorde, Zedelgem et même peut-être jusque Bruges. Quiconque l’ayant ressenti est invité à remplir l’enquête sur notre site internet:

    http://seismologie.be/