Skip to content
This repository has been archived by the owner on Mar 27, 2018. It is now read-only.

Spg update #574

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.scanning.api.annotation.UiHidden;

Expand Down Expand Up @@ -133,4 +135,21 @@ public Map<String, Integer> getIndices() {
}
return indices;
}

private static final String VERTEX = "([a-zA-Z0-9_])+\\((\\d+)\\)=([-+]?[0-9]*\\.?[0-9]+)";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Move this variable to comply with Java Code Conventions. rule

private static final Pattern POSITION = Pattern.compile(VERTEX + ", " + VERTEX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Move this variable to comply with Java Code Conventions. rule


/**
* Parse a point from the toString() method into an instance of Point
* @param asString
* @return
*/
public static Point parse(String asString) {
Matcher m = POSITION.matcher(asString);
if (m.matches()) {
return new Point(m.group(4), Integer.parseInt(m.group(5)), Double.parseDouble(m.group(6)),
m.group(1), Integer.parseInt(m.group(2)), Double.parseDouble(m.group(3)));
}
throw new RuntimeException("Unparsable string" + asString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Define and throw a dedicated exception instead of using a generic one. rule

}
}
32 changes: 25 additions & 7 deletions org.eclipse.scanning.points/scripts/jython_spg_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def toDict(self):
return self.generator.to_dict()

def size(self):
return self.generator.num
return self.generator.size


class JLineGenerator1D(JavaIteratorWrapper):
Expand All @@ -78,7 +78,9 @@ def __init__(self, name, units, start, stop, num_points, alternate_direction=Fal
super(JLineGenerator1D, self).__init__()

self.name = name
self.generator = LineGenerator(name, units, start, stop, num_points, alternate_direction)
line_gen = LineGenerator(name, units, start, stop, num_points, alternate_direction)
self.generator = CompoundGenerator([line_gen], [], [])
self.generator.prepare()
logging.debug(self.generator.to_dict())

def _iterator(self):
Expand All @@ -103,7 +105,9 @@ def __init__(self, names, units, start, stop, num_points, alternate_direction=Fa
stop = stop.tolist()

self.names = names
self.generator = LineGenerator(names, units, start, stop, num_points, alternate_direction)
line_gen = LineGenerator(names, units, start, stop, num_points, alternate_direction)
self.generator = CompoundGenerator([line_gen], [], [])
self.generator.prepare()
logging.debug(self.generator.to_dict())

def _iterator(self):
Expand Down Expand Up @@ -132,7 +136,9 @@ def __init__(self, name, units, points):
points = points.tolist() # Convert from array to list

self.name = name
self.generator = ArrayGenerator(name, units, points)
array_gen = ArrayGenerator(name, units, points)
self.generator = CompoundGenerator([array_gen], [], [])
self.generator.prepare()
logging.debug(self.generator.to_dict())

def _iterator(self):
Expand All @@ -155,11 +161,12 @@ def __init__(self, names, units, centre, radius, scale=1.0, alternate_direction=
super(JSpiralGenerator, self).__init__()

self.names = names
self.generator = SpiralGenerator(names, units, centre, radius, scale, alternate_direction)
spiral_gen = SpiralGenerator(names, units, centre, radius, scale, alternate_direction)
self.generator = CompoundGenerator([spiral_gen], [], [])
self.generator.prepare()
logging.debug(self.generator.to_dict())

def _iterator(self):

x_name = self.names[0]
y_name = self.names[1]

Expand All @@ -183,7 +190,9 @@ def __init__(self, names, units, box, num_lobes, num_points):
super(JLissajousGenerator, self).__init__()

self.names = names
self.generator = LissajousGenerator(names, units, box, num_lobes, num_points)
liss_gen = LissajousGenerator(names, units, box, num_lobes, num_points)
self.generator = CompoundGenerator([liss_gen], [], [])
self.generator.prepare()
logging.debug(self.generator.to_dict())

def _iterator(self):
Expand Down Expand Up @@ -240,6 +249,15 @@ def __init__(self, iterators, excluders, mutators):
scan_name.add(axis)

self.dimension_names.add(scan_name)
for excluder in excluders:
# axes connected by excluders are "unrolled"
matched_axes = [a for a in self.axes_ordering if a in excluder.scannables]
if len(matched_axes) == 0:
continue
inner_axis = matched_axes[0]
inner_idx = self.axes_ordering.index(inner_axis)
for a in matched_axes[1:]:
self.index_locations[a] = inner_idx

logging.debug("Index Locations:")
logging.debug(self.index_locations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


if os.name == 'java':
import scanpointgenerator.numjy as numpy
import numjy as numpy
else:
import numpy

Expand Down
Loading