tools to parse xml files

602 views
Skip to first unread message

rongy

unread,
Apr 18, 2012, 9:21:39 AM4/18/12
to OpenQuake Users
Hello,

I wonder if anyone has developed and can share the tool to parse the
xml files for input data and output results?

Thanks a lot,
Yufang

Marco Pagani

unread,
Apr 20, 2012, 1:39:07 AM4/20/12
to openqua...@googlegroups.com
Dear Yufang,

we have several scripts for converting nrml into a number of formats and for plotting input and output. This is  mostly 'scientific' code not following the strict testing rules we adopt for openquake development but so far it worked. We're in a process of creating a repository on github where all these scripts will be made available and will create also a folder in OATS.

However, in other to answer more precisely to your request, it would be useful to understand if there's a specific format you need (e.g. shape files) and if plotting scripts producing postscripts files can be a sufficient (temporary) option. 

The GEM web platform that is currently under development (called openquake, while the calculation code will be named openquake-engine) will offer all the necessary functionalities for plotting and exporting into different formats openquake-engine input and output information.

Thank you and kind regards,
Marco

-- 
Marco Pagani
Global Earthquake Model 
Sent with Sparrow

Yufang Rong

unread,
Apr 20, 2012, 2:14:05 AM4/20/12
to openqua...@googlegroups.com, yufan...@fmglobal.com, harold.m...@fmglobal.com
Dear Marco,

Thank you very much for your detailed explanation. It's great to know that you have a number of scripts for converting nrml files. If possible, I want some scripts to do:
1) convert input and output nrml files to ArcGIS shape files;
2) convert them to text tables so that I can plot them using other software; and
3) convert my own input files (I can prepare the files as shape files or text files) to nrml format. 

If those scripts are not available yet, I'd like to have the plotting script which can produce postscript files. 

Thank you again,
Yufang

BillH

unread,
Mar 21, 2013, 2:07:28 PM3/21/13
to openqua...@googlegroups.com
I also have the same question about plotting NRML output or parsing so it can be translated to a format for plotting. I'm not looking for a particular format, just what is currently available to plot NRML output and parse for further analysis. Is it possible to use tools developed for parsing and plotting GML? For example, I've seen SQL functions to import GML to SQL. Would they work on NRML files?

Bill

Damiano Monelli

unread,
Mar 22, 2013, 4:27:28 AM3/22/13
to openqua...@googlegroups.com
Dear Bill,

could you please tell us which version of OpenQuake/NRML are you using? Depending on the version there are different tools/scripts.

If the OpenQuake version you are running uses NRML 0.3 you can find some (python) scripts that allow to read hazard map/ curves files here: https://github.com/GEMScienceTools/oq-tools/tree/master/output

If you are running OpenQuake based on the latest master, than this utilizes NRML 0.4 and for this we are developing some tools we can share with you.

Best,

Damiano
--
You received this message because you are subscribed to the Google Groups "OpenQuake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openquake-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bill Hoskins

unread,
Mar 22, 2013, 12:42:06 PM3/22/13
to openqua...@googlegroups.com
Thanks Damiano. The link has exactly what I need. I'm using NRML 0.3.

Bill

--
You received this message because you are subscribed to a topic in the Google Groups "OpenQuake Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openquake-users/9KclGf6UtXs/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to openquake-use...@googlegroups.com.

Marlon Pirchiner

unread,
Apr 23, 2013, 7:10:05 PM4/23/13
to openqua...@googlegroups.com
Dear Damiano,

Could you please introduce to me the useful extraction/plotting scripts that works with NRML 0.4 ?!
I've got https://github.com/GEMScienceTools/oq-tools, but my openquake instalation (got today) works on nrm-l0.4.
I've seen oq-nrmllib/openquake/nrmllib/schema/tools/ and I didn't found any xslt to revert 0.4 to 0.3 (just to keep using the same oq-tools).

Greetings,

Marlon

Damiano Monelli

unread,
Apr 24, 2013, 9:46:44 AM4/24/13
to openqua...@googlegroups.com
Dear Marlon,

unfortunately we do not have yet a complete suite of tools that can deal with the NRML 0.4 format. We will prepare it soon and update the githup repo accordingly.

We do not have a tool to convert from 0.4 to 0.3 because between the two formats there is not a 1 to 1 correspondence (things that are defined in 0.3 are not in 0.4 and vicevesa)

I'm attaching a python script that plots NRML 0.4 hazard data (curves/maps/stochastic event sets/ground motion fields) using matplotlib/basemap. You can use it as
starting point and maybe adapt to your needs.

Hope it helps for the moment.

Best,

Damiano

hazard_data_plotter.py

Marlon Pirchiner

unread,
Apr 26, 2013, 10:18:52 AM4/26/13
to openqua...@googlegroups.com
Hi Damiano,

A quite late, but just to feed back for users, I've use the module to generate the outputs for the 'simple fault demo', and for me works very well. Thank you very much.

I did just litle small typo corrections based on the actual version (commit 65baf8096db9ea10d45d9df43780847ba4449641) of the outputs that I'm sending attached.

Just for documentation, I've attached two output examples a curve and a map.

Cheers,

Marlon
hazard_data_plotter.diff
hazard-curves-8.45971847407-46.5.eps
hazard_map-b1-b1-PGA-0.1in50.0years.eps

François Berthoux

unread,
Feb 13, 2014, 11:38:27 AM2/13/14
to openqua...@googlegroups.com
Hello,

Are there any new scripts regarding Yufang' s original request? (inputs/outputs to ArcGIS files, csv, etc.)

Kind regards,
François.

Damiano Monelli

unread,
Feb 13, 2014, 11:58:16 AM2/13/14
to openqua...@googlegroups.com
Dear François,

you can find a number of scripts for converting NRML files to shapefile or .csv format at this link: https://github.com/GEMScienceTools/nrml_converters

These are python based scripts, which require a number of dependencies as described in the README.

Let us know if you find issues. Regards,

Damiano



François Berthoux

unread,
Feb 14, 2014, 6:50:33 AM2/14/14
to openqua...@googlegroups.com
Dear Damiano,

Thank you for your answer.

I tried to process an event set generated with openquake using python eventset_converter.py. It was going fine until what feels like should have been the end of the processing. I had the following error message:

...(lots of "Processing rupture xxxxxx")...
Processing rupture 209031
Processing rupture 209030
number of sochastic event sets: 1
Traceback (most recent call last):
   File "eventset_converter.py", line 372, in <module>
     save_sess_to_txt(sesc, args.output_dir)
   File "eventset_converter,py", line 333, in save_sess_to_txt
     fmt='%s\t%2.1f\t%5.2f\t%5.2f\t%5.2f\t%s\t%5.2f\t%5.2f\t%5.2f\t%s', comments=' ')
TypeError: savetxt() got an unexpected keyword argument 'header'


I have not supplied any header parameter to the script, as only input file and output dir are listed as parameters. Do you have any idea what might be the issue?

Thank you in advance for your help,
François.


Damiano Monelli

unread,
Feb 14, 2014, 7:04:17 AM2/14/14
to openqua...@googlegroups.com
Dear François,

I suppose that you are running the script in the same machine where OQ is running. The error you see is due to the numpy version that OQ uses (which is 1.6).

The script requires numpy version 1.7. I do not wan't you to compromise the OQ installation by upgrading numpy. So I will try to change the script to work with numpy
version 1.6. I'll keep you posted.

In the mean you can just remove the 'header' key word from line 332, that is instead of:

        numpy.savetxt(fname, sesc.data[idx, 2 :], header=header,
            fmt='%s\t%2.1f\t%5.2f\t%5.2f\t%5.2f\t%s\t%5.2f\t%5.2f\t%5.2f\t%s', comments='')

type:

        numpy.savetxt(fname, sesc.data[idx, 2 :],
            fmt='%s\t%2.1f\t%5.2f\t%5.2f\t%5.2f\t%s\t%5.2f\t%5.2f\t%5.2f\t%s', comments='')

You will get a .csv file without the header. The meaning of the columns will remain the same:

rupture id, magnitude, longitude of rupture centroid, latitude of rupture centroid, depth of rupture centroid, rupture strike, rupture dip, rupture rake, rupture boundary

Cheers,

Damiano

Damiano Monelli

unread,
Feb 14, 2014, 9:39:53 AM2/14/14
to openqua...@googlegroups.com
Dear François,

I fixed the bug you found. So, if you download the latest version of the scripts you should not get this error anymore.

Best,

Damiano

François Berthoux

unread,
Feb 14, 2014, 9:49:38 AM2/14/14
to openqua...@googlegroups.com
Dear Damiano,

I would suppose that you are right. I removed the header parameter, rerun, then had the same issue with the "comments" parameter. So I removed it as well and it worked beatifully!

Thank you very much for your help, and also for the script, that's saving me a lot of time. I'll certainly use the other scripts soon, especially the one to convert ESRI shapefiles to source models, will let you know how it goes.

Cheers,
François.
Reply all
Reply to author
Forward
0 new messages