Exemplo n.º 1
0
def gen_lookup_table(db_name, db_folder):
    dat = DataHandler(db_name=db_name, database_dir=db_folder)

    hashes = dat.load(save_location="params",
                      parameters=dat.get_keys("params"))
    lookup = {}
    for hash_id in hashes:
        params = dat.load(
            save_location=f"params/{hash_id}",
            parameters=dat.get_keys(f"params/{hash_id}", recursive=True),
        )
        for key, val in params.items():
            if key not in lookup:
                lookup[key] = {str(val): [hash_id]}
            elif str(val) not in lookup[key].keys():
                lookup[key][str(val)] = [hash_id]
            elif str(val) in lookup[key].keys():
                lookup[key][str(val)].append(hash_id)
    return lookup
# instantiate a database with your desired name
dat = DataHandler(db_name='abr_analyze_examples')

# save our data
dat.save(data=data_dict, save_location=save_location, overwrite=True)

# load our data
# we can specify what parameters to load
data = dat.load(parameters=['trajectory', 'time'], save_location=save_location)
trajectory = data['trajectory']
time = data['time']

# we can rename our save_location as well
new_save_location = 'data_handling_rename'
dat.rename(old_save_location=save_location,
           new_save_location=new_save_location,
           delete_old=True)

# if we don't know the parameters, or want to load all of them and want to
# avoid writing out the entire list we can get all the keys at the save
# location
keys = dat.get_keys(save_location=new_save_location)
data = dat.load(parameters=keys, save_location=new_save_location)

# delete data we don't need anymore
dat.delete(save_location='%s/time' % new_save_location)

# we can also delete the entire group if we want
dat.delete(save_location=new_save_location)