using a dstore in the new oq engine version

94 views
Skip to first unread message

Anne Hulsey

unread,
Sep 22, 2021, 4:01:14 PM9/22/21
to OpenQuake Users
Hello,

I've recently upgraded to the 3.12 version and need to modify my Jupyter Notebooks for the new version. After much unsuccessful searching, I have to ask: What is the equivalent of the old "read" function that returned a dstore?

For example, I used to use

from openquake.calculators.export.hazard import *
from openquake.baselib.datastore import read

filename = 'calc_%s.hdf5' % oq_id
dstore = read(filename)
export_realizations('realizations', dstore)


Now, the closest function I have found is hdf5.File and it doesn't return a dstore with the necessary attributes. For example, here is my code and the output:

from openquake.baselib.hdf5 import *
from openquake.calculators.export.hazard import *

dstore = File(filename)
oq = dstore['oqparam']

ekey = ('hcurves', 'csv')
key, kind, fmt = get_kkf(ekey)
R = dstore['full_lt'].get_num_rlzs()

for kind in oq.get_kinds(kind, R):
    fname = hazard_curve_name(dstore, (key, fmt), kind)
    print(fname)

--------------------------------------------------------------------------- 
AttributeError Traceback (most recent call last) 
<ipython-input-24-563def7361db> in <module> 
         6 
         7 for kind in oq.get_kinds(kind, R): 
----> 8 fname = hazard_curve_name(dstore, (key, fmt), kind)

~\Anaconda3\envs\py38\lib\site-packages\openquake\calculators\export\hazard.py in hazard_curve_name(dstore, ekey, kind) 
         152 fname = dstore.build_fname('quantile_' + prefix[7:], kind[9:], fmt) 
         153 else: 
   --> 154 fname = dstore.build_fname(prefix, kind, fmt) 
         155 return fname 
         156 AttributeError: 'File' object has no attribute 'build_fname'

Thanks,
Anne


Marco Pagani

unread,
Sep 22, 2021, 4:24:33 PM9/22/21
to OpenQuake Users

Hi Anne,

The read function is still there and returns a DataStore instance
https://github.com/gem/oq-engine/blob/master/openquake/commonlib/datastore.py#L100

However, the export_realizations function requires an argument with a different format than the one you have in your example. See: https://github.com/gem/oq-engine/blob/master/openquake/calculators/export/hazard.py#L160

Michele can certainly provide more insightful help, however, I wonder if it wouldn’t be better for you to use what’s explained here:
https://docs.openquake.org/oq-engine/advanced/pandas.html

Marco

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/openquake-users/db5c77c0-3596-451b-bdd8-efbac093a36cn%40googlegroups.com.
MARCO PAGANI | Seismic Hazard Team Lead | Skype mm.pagani | +39-0382-5169863
GLOBAL EARTHQUAKE MODEL | working together to assess risk

Anne Hulsey

unread,
Sep 22, 2021, 6:56:58 PM9/22/21
to OpenQuake Users
Thanks, Marco! I knew the read function must still be in there somewhere. I combed through so many .py files in baselib and then other folders but somehow I never thought to check the commonlib folder...

Thanks for the other links as well. My googling usually finds really old documentation from several versions ago instead of the https://docs.openquake.org/oq-engine/advanced pages. I am now adding it as a bookmark to always check there first.
Reply all
Reply to author
Forward
0 new messages