:param ekey: export key, i.e. a pair (datastore key, fmt)
    :param dstore: datastore object
487233
def export_avg_losses_ebrisk(ekey, dstore):
    
    name = ekey[0]
    oq = dstore['oqparam']
    dt = oq.loss_dt()
    value = dstore[name].value  # shape (A, L)
    writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
    assets = get_assets(dstore)
    dest = dstore.build_fname(name, 'mean', 'csv')
    array = numpy.zeros(len(value), dt)
    for l, lt in enumerate(dt.names):
        array[lt] = value[:, l]
    writer.save(compose_arrays(assets, array), dest)
    return writer.getsaved()
310836
def expose_outputs(dstore, owner=getpass.getuser(), status='complete'):
    
    oq = dstore['oqparam']
    exportable = set(ekey[0] for ekey in export.export)
    calcmode = oq.calculation_mode
    dskeys = set(dstore) & exportable  # exportable datastore keys
    dskeys.add('fullreport')
    rlzs = dstore['csm_info'].rlzs
    if len(rlzs) > 1:
        dskeys.add('realizations')
    if len(dstore['csm_info/sg_data']) > 1:  # export sourcegroups.csv
        dskeys.add('sourcegroups')
    hdf5 = dstore.hdf5
    if 'hcurves-stats' in hdf5 or 'hcurves-rlzs' in hdf5:
        if oq.hazard_stats() or oq.individual_curves or len(rlzs) == 1:
            dskeys.add('hcurves')
        if oq.uniform_hazard_spectra:
            dskeys.add('uhs')  # export them
        if oq.hazard_maps:
            dskeys.add('hmaps')  # export them
    if 'avg_losses-stats' in dstore or (
            'avg_losses-rlzs' in dstore and len(rlzs)):
        dskeys.add('avg_losses-stats')
    if 'curves-rlzs' in dstore and len(rlzs) == 1:
        dskeys.add('loss_curves-rlzs')
    if 'curves-stats' in dstore and len(rlzs) > 1:
        dskeys.add('loss_curves-stats')
    if oq.conditional_loss_poes:  # expose loss_maps outputs
        if 'loss_curves-stats' in dstore:
            dskeys.add('loss_maps-stats')
    if 'all_loss_ratios' in dskeys:
        dskeys.remove('all_loss_ratios')  # export only specific IDs
    if 'ruptures' in dskeys and 'scenario' in calcmode:
        exportable.remove('ruptures')  # do not export, as requested by Vitor
    if 'rup_loss_table' in dskeys:  # keep it hidden for the moment
        dskeys.remove('rup_loss_table')
    if 'hmaps' in dskeys and not oq.hazard_maps:
        dskeys.remove('hmaps')  # do not export the hazard maps
    if logs.dbcmd('get_job', dstore.calc_id) is None:
        # the calculation has not been imported in the db yet
        logs.dbcmd('import_job', dstore.calc_id, oq.calculation_mode,
                   oq.description + ' [parent]', owner, status,
                   oq.hazard_calculation_id, dstore.datadir)
    keysize = []
    for key in sorted(dskeys & exportable):
        try:
            size_mb = dstore.get_attr(key, 'nbytes') / MB
        except (KeyError, AttributeError):
            size_mb = None
        keysize.append((key, size_mb))
    ds_size = os.path.getsize(dstore.filename) / MB
    logs.dbcmd('create_outputs', dstore.calc_id, keysize, ds_size)
996734
def extract_assets(dstore, what):
    
    qdict = parse(what)
    dic = {}
    dic1, dic2 = dstore['assetcol/tagcol'].__toh5__()
    dic.update(dic1)
    dic.update(dic2)
    arr = dstore['assetcol/array'].value
    for tag, vals in qdict.items():
        cond = numpy.zeros(len(arr), bool)
        for val in vals:
            tagidx, = numpy.where(dic[tag] == val)
            cond |= arr[tag] == tagidx
        arr = arr[cond]
    return ArrayWrapper(arr, dic)
1099298
def get_assets(dstore):
    
    assetcol = dstore['assetcol']
    tagnames = sorted(assetcol.tagnames)
    tag = {t: getattr(assetcol.tagcol, t) for t in tagnames}
    dtlist = [('asset_ref', (bytes, 100))]
    for tagname in tagnames:
        dtlist.append((tagname, (bytes, 100)))
    dtlist.extend([('lon', F32), ('lat', F32)])
    asset_data = []
    for aref, a in zip(assetcol.asset_refs, assetcol.array):
        tup = tuple(b'"%s"' % tag[t][a[t]].encode('utf-8') for t in tagnames)
        asset_data.append((aref,) + tup + (a['lon'], a['lat']))
    return numpy.array(asset_data, dtlist)
1267234
static List<Entity> fetch(Datastore reader, Key[] keys, ReadOption... options) {
    return compileEntities(keys, reader.get(Arrays.asList(keys), options));
  }
148394
def make_datastore_query(self, cursor=None):
    
    filters = {}
    filters['__key__ >= '] = _key_for_namespace(
        self.namespace_start, self.app)
    filters['__key__ <= '] = _key_for_namespace(
        self.namespace_end, self.app)

    return datastore.Query('__namespace__',
                           filters=filters,
                           keys_only=True,
                           cursor=cursor,
                           _app=self.app)
821025
def put(self, key, value):
    '''
    '''
    self.cache_datastore.put(key, value)
    self.child_datastore.put(key, value)
1237530
def _execute(self, query, model, adapter, raw=False):
        
        values = self.load(model, adapter)
        return IterableStore(values=values)._execute(query, model=model, adapter=None, raw=raw)
1040528
def check_version(dstore):
    
    ds_version = dstore.hdf5.attrs['engine_version']
    if ds_version != __version__:
        return (': the datastore is at version %s, but the exporter at '
                'version %s' % (ds_version, __version__))
    else:
        return ''
682635
def insertDatastore(self, index, store):
    ''''''
    if not isinstance(store, Datastore):
      raise TypeError("stores must be of type %s" % Datastore)

    self._stores.insert(index, store)
1059510
def export_dmg_by_event(ekey, dstore):
    
    damage_dt = build_damage_dt(dstore, mean_std=False)
    dt_list = [('event_id', numpy.uint64), ('rlzi', numpy.uint16)] + [
        (f, damage_dt.fields[f][0]) for f in damage_dt.names]
    all_losses = dstore[ekey[0]].value  # shape (E, R, LI)
    events_by_rlz = group_array(dstore['events'], 'rlz')
    rlzs = dstore['csm_info'].get_rlzs_assoc().realizations
    writer = writers.CsvWriter(fmt=writers.FIVEDIGITS)
    fname = dstore.build_fname('dmg_by_event', '', 'csv')
    writer.save(numpy.zeros(0, dt_list), fname)
    with open(fname, 'ab') as dest:
        for rlz in rlzs:
            data = all_losses[:, rlz.ordinal].copy().view(damage_dt)  # shape E
            arr = numpy.zeros(len(data), dt_list)
            arr['event_id'] = events_by_rlz[rlz.ordinal]['eid']
            arr['rlzi'] = rlz.ordinal
            for field in damage_dt.names:
                arr[field] = data[field].squeeze()
            writer.save_block(arr, dest)
    return [fname]
1011967
def export_maxloss_ruptures(ekey, dstore):
    
    oq = dstore['oqparam']
    mesh = get_mesh(dstore['sitecol'])
    rlzs_by_gsim = dstore['csm_info'].get_rlzs_by_gsim_grp()
    num_ses = oq.ses_per_logic_tree_path
    fnames = []
    for loss_type in oq.loss_dt().names:
        ebr = getters.get_maxloss_rupture(dstore, loss_type)
        root = hazard_writers.rupture_to_element(
            ebr.export(mesh, rlzs_by_gsim[ebr.grp_id], num_ses))
        dest = dstore.export_path('rupture-%s.xml' % loss_type)
        with open(dest, 'wb') as fh:
            nrml.write(list(root), fh)
        fnames.append(dest)
    return fnames
538404
def read(cls, dstore):
        
        oqparam = dstore['oqparam']
        tmap = (dstore['taxonomy_mapping'] if 'taxonomy_mapping' in dstore
                else {})
        crm = dstore.getitem('risk_model')
        # building dictionaries riskid -> loss_type -> risk_func
        fragdict, vulndict, consdict, retrodict = (
            AccumDict(), AccumDict(), AccumDict(), AccumDict())
        fragdict.limit_states = crm.attrs['limit_states']
        for quoted_id, rm in crm.items():
            riskid = unquote_plus(quoted_id)
            fragdict[riskid] = {}
            vulndict[riskid] = {}
            consdict[riskid] = {}
            retrodict[riskid] = {}
            for lt_kind in rm:
                lt, kind = lt_kind.rsplit('-', 1)
                rf = dstore['risk_model/%s/%s' % (quoted_id, lt_kind)]
                if kind == 'consequence':
                    consdict[riskid][lt, kind] = rf
                elif kind == 'fragility':  # rf is a FragilityFunctionList
                    try:
                        rf = rf.build(
                            fragdict.limit_states,
                            oqparam.continuous_fragility_discretization,
                            oqparam.steps_per_interval)
                    except ValueError as err:
                        raise ValueError('%s: %s' % (riskid, err))
                    fragdict[riskid][lt, kind] = rf
                else:  # rf is a vulnerability function
                    rf.init()
                    if lt.endswith('_retrofitted'):
                        # strip _retrofitted, since len('_retrofitted') = 12
                        retrodict[riskid][lt[:-12], kind] = rf
                    else:
                        vulndict[riskid][lt, kind] = rf
        return CompositeRiskModel(
            oqparam, tmap, fragdict, vulndict, consdict, retrodict)
856709
@SneakyThrows
    public KeyStore createEmptyKeystore() {
        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(null, "".toCharArray());
        return keyStore;
    }
962035
def fetchItems(self, ekey, cls=None, **kwargs):
        
        data = self._server.query(ekey)
        items = self.findItems(data, cls, ekey, **kwargs)
        librarySectionID = data.attrib.get('librarySectionID')
        if librarySectionID:
            for item in items:
                item.librarySectionID = librarySectionID
        return items
22474
def sinterstore(self, dest, keys, *args):
        """"""
        result = self.sinter(keys, *args)
        self.redis[self._encode(dest)] = result
        return len(result)
1203615
def export_losses_by_asset_npz(ekey, dstore):
    
    fname = dstore.export_path('%s.%s' % ekey)
    savez(fname, **dict(extract(dstore, 'losses_by_asset')))
    return [fname]