Skip to content

Commit

Permalink
Convert vdswrapperpart to use direct call rather than subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Nov 8, 2017
1 parent 461afc6 commit f0ccb57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 47 deletions.
65 changes: 21 additions & 44 deletions malcolm/modules/excalibur/parts/vdswrapperpart.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os
import sys
from subprocess import check_call

#sys.path.insert(0, "/dls_sw/work/tools/RHEL6-x86_64/odin/venv/lib/python2.7/"
# "site-packages")
import h5py as h5
import numpy as np
import h5py as h5
from vdsgen import SubFrameVDSGenerator

from malcolm.modules.scanning.controllers import RunnableController
from malcolm.core import method_takes, REQUIRED, Part
from malcolm.modules.ADCore.infos import DatasetProducedInfo
from malcolm.modules.builtin.vmetas import StringMeta, NumberMeta
from malcolm.modules.scanpointgenerator.vmetas import PointGeneratorMeta
from copy import deepcopy

# Number of points too look ahead of the current id index to account for dropped frames
NUM_LOOKAHEAD = 100
Expand All @@ -23,23 +20,6 @@
"stripeWidth", NumberMeta("int16", "Width of stripes"), REQUIRED)
class VDSWrapperPart(Part):

# Constants for vds-gen CLI app
#VENV = "/dls_sw/work/tools/RHEL6-x86_64/odin/venv/bin/python"
#VDS_GEN = "/dls_sw/work/tools/RHEL6-x86_64/odin/vds-gen/vdsgen/app.py"
VDS_GEN = "/dls_sw/prod/tools/RHEL6-x86_64/defaults/bin/dls-vds-gen.py"
EMPTY = "-e"
OUTPUT = "-o"
FILES = "-f"
SHAPE = "--shape"
DATA_TYPE = "--data_type"
DATA_PATH = "-d"
STRIPE_SPACING = "-s"
MODULE_SPACING = "-m"
FILL_VALUE = "-F"
SOURCE_NODE = "--source_node"
TARGET_NODE = "--target_node"
LOG_LEVEL = "-l"

# Constants for class
RAW_FILE_TEMPLATE = "FEM{}"
OUTPUT_FILE = "EXCALIBUR"
Expand Down Expand Up @@ -85,7 +65,6 @@ def close_files(self):
self.raw_datasets = []
self.vds = None


def _create_dataset_infos(self, generator, filename):
uniqueid_path = "/entry/NDAttributes/NDArrayUniqueId"
data_path = "/entry/detector/detector"
Expand Down Expand Up @@ -152,30 +131,28 @@ def configure(self, context, completed_steps, steps_to_do, part_info,
self.vds.create_dataset(self.ID, initial_shape,
maxshape=max_shape, dtype="int32")
self.vds.create_dataset(self.SUM, initial_shape,
maxshape=max_shape, dtype="float64", fillvalue=np.nan)
maxshape=max_shape, dtype="float64",
fillvalue=np.nan)
files = [params.fileTemplate % self.RAW_FILE_TEMPLATE.format(fem)
for fem in self.fems]
shape = [str(d) for d in params.generator.shape] + \
[str(self.stripe_height), str(self.stripe_width)]
# Base arguments
#command = [self.VENV, self.VDS_GEN, params.fileDir]
command = [self.VDS_GEN, params.fileDir]
# Define empty and required arguments to do so
command += [self.EMPTY,
self.FILES] + files + \
[self.SHAPE] + shape + \
[self.DATA_TYPE, self.data_type]
# Override default spacing and data path
command += [self.STRIPE_SPACING, "0",
self.MODULE_SPACING, "121",
self.FILL_VALUE, str(params.fillValue),
self.SOURCE_NODE, "/entry/detector/detector",
self.TARGET_NODE, "/entry/detector/detector"]
# Define output file path
command += [self.OUTPUT, params.fileTemplate % self.OUTPUT_FILE]
command += [self.LOG_LEVEL, "1"] # str(self.log.level / 10)]
self.log.info("VDSGen Command: %s", command)
check_call(command)

# Create the VDS using vdsgen
fgen = SubFrameVDSGenerator(
params.fileDir,
prefix=None,
files=files,
output=params.fileTemplate % self.OUTPUT_FILE,
source=dict(shape=shape, dtype=self.data_type),
source_node="/entry/detector/detector",
target_node="/entry/detector/detector",
stripe_spacing=0,
module_spacing=121,
fill_value=params.fillValue,
log_level=1 # DEBUG
)
fgen.generate_vds()

# Store required attributes
self.raw_paths = [os.path.abspath(os.path.join(params.fileDir, file_))
Expand Down
4 changes: 2 additions & 2 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ plop==0.3.0
pytest>=3
pytest-catchlog
pytest-cov
git+https://github.com/aaron-parsons/h5py.git#egg=h5py
git+https://github.com/dls-controls/vds-gen.git#egg=vds-gen
h5py==2.7.1
git+https://github.com/dls-controls/vds-gen.git@0-2#egg=vds-gen
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def add_multiversion_require(module):
install_requires=install_requires,
extras_require={
'websocket': ['tornado'],
'ca': ['cothread']
'ca': ['cothread'],
'hdf5': ['h5py', 'vds-gen'],
},
include_package_data=True,
test_suite='nose.collector',
Expand Down

0 comments on commit f0ccb57

Please sign in to comment.