Skip to content
Open

att #71

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion xpdsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
__version__ = '0.1.2'

pyfai_path = rs_fn('xpdsim', 'data/pyfai/pyFAI_calib.yml')

# first initial attempt to fix the pgkg_resources issue
#pyfai_path = importlib_resources.files('xpdsim') / 'resource.dat'
#with importlib_resources.as_file(ref) as path:
# Do something with path. After the with-statement exits, any
# temporary file created will be immediately cleaned up.

sim_db_dir, db = build_sim_db() # default is sqlite
db.reg.register_handler('NPY_SEQ', NumpySeqHandler)
Expand Down
59 changes: 43 additions & 16 deletions xpdsim/build_sim_db.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
"""this module exists for simulation environment"""
import os
import tempfile

from databroker import Broker
from tiled.config import parse_configs
import yaml

def build_sim_db(sim_db_dir=None):
from databroker import Broker
if not sim_db_dir:
sim_db_dir = tempfile.mkdtemp()
config = {
'metadatastore': {
'module': 'databroker.headersource.sqlite',
'class': 'MDS',
'config': {
'directory': sim_db_dir,
'timezone': 'US/Eastern'}
},
'assets': {
'module': 'databroker.assets.sqlite',
'class': 'Registry',
'config': {
'dbpath': os.path.join(sim_db_dir, 'assets.sqlite')}
"authentication": {"allow_anonymous_access": True},
# The default is false. Set to true to enable any HTTP client that can
# connect to _read_. An API key is still required to write.
"trees": [{
"path": "/",
"tree": "catalog",
"args": {
"uri": "sqlite+aiosqlite:////storage/catalog.db",
"writable_storage": sim_db_dir,
# This creates the database if it does not exist. This is convenient, but in
# a horizonally-scaled deployment, this can be a race condition and multiple
# containers may simultanouesly attempt to create the database.
# If that is a problem, set this to false, and run:
#
# tiled catalog init URI
#
# separately.
"init_if_not_exists": True
}
}]
# 'metadatastore': {
# 'module': 'databroker.headersource.sqlite',
# 'class': 'MDS',
# 'config': {
# 'directory': sim_db_dir,
# 'timezone': 'US/Eastern'}
# },
# 'assets': {
# 'module': 'databroker.assets.sqlite',
# 'class': 'Registry',
# 'config': {
# 'dbpath': os.path.join(sim_db_dir, 'assets.sqlite')}
}
}
return sim_db_dir, Broker.from_config(config)

with open(os.path.join(sim_db_dir, 'test_sim.yml'), 'w') as f:
yaml.dump(config, f, default_flow_style=False)

print(sim_db_dir)
parse_configs(sim_db_dir)
db = Broker.named('test_sim')
return sim_db_dir, db
3 changes: 2 additions & 1 deletion xpdsim/movers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ophyd.sim import SynAxis, SynSignal, Device, Component
from ophyd.sim import SynAxis, SynSignal
from ophyd.device import Device, Component

cs700 = SynAxis(name='cs700', value=300)
cs700.readback.name = 'temperature'
Expand Down