-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #528 from vallsv/backport-to-0.13
Backport from 0.14-dev to 0.13
- Loading branch information
Showing
7 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "GPLv3+" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "24/11/2016" | ||
__date__ = "12/12/2016" | ||
__status__ = "production" | ||
|
||
import sys | ||
|
@@ -113,7 +113,8 @@ def find_peaks(self, x, nmax=200, annotate=None, massif_contour=None, stdout=sys | |
""" | ||
All in one function that finds a maximum from the given seed (x) | ||
then calculates the region extension and extract position of the neighboring peaks. | ||
:param x: seed for the calculation, input coordinates | ||
:param x: coordinates of the peak, seed for the calculation | ||
:type x: tuple of integer | ||
:param nmax: maximum number of peak per region | ||
:param annotate: call back method taking number of points + coordinate as input. | ||
:param massif_contour: callback to show the contour of a massif with the given index. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "GPLv3+" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "27/10/2016" | ||
__date__ = "12/12/2016" | ||
__status__ = "production" | ||
|
||
import os | ||
|
@@ -413,23 +413,28 @@ def common_creation(points, gpt=None): | |
return gpt | ||
|
||
def new_grp(event): | ||
" * Right-click (click+n): try an auto find for a ring" | ||
points = self.massif.find_peaks([event.ydata, event.xdata], | ||
" * new_grp Right-click (click+n): try an auto find for a ring" | ||
# ydata is a float, and matplotlib display pixels centered. | ||
# we use floor (int cast) instead of round to avoid use of | ||
# banker's rounding | ||
ypix, xpix = int(event.ydata + 0.5), int(event.xdata + 0.5) | ||
points = self.massif.find_peaks([ypix, xpix], | ||
self.defaultNbPoints, | ||
None, self.massif_contour) | ||
if points: | ||
gpt = common_creation(points) | ||
annontate(points[0], [event.ydata, event.xdata], gpt=gpt) | ||
annontate(points[0], [ypix, xpix], gpt=gpt) | ||
logger.info("Created group #%2s with %i points", gpt.label, len(gpt)) | ||
else: | ||
logger.warning("No peak found !!!") | ||
|
||
def single_point(event): | ||
" * Right-click + Ctrl (click+b): create new group with one single point" | ||
newpeak = self.massif.nearest_peak([event.ydata, event.xdata]) | ||
ypix, xpix = int(event.ydata + 0.5), int(event.xdata + 0.5) | ||
newpeak = self.massif.nearest_peak([ypix, xpix]) | ||
if newpeak: | ||
gpt = common_creation([newpeak]) | ||
annontate(newpeak, [event.ydata, event.xdata], gpt=gpt) | ||
annontate(newpeak, [ypix, xpix], gpt=gpt) | ||
logger.info("Create group #%2s with single point x=%5.1f, y=%5.1f", gpt.label, newpeak[1], newpeak[0]) | ||
else: | ||
logger.warning("No peak found !!!") | ||
|
@@ -445,8 +450,10 @@ def append_more_points(event): | |
self.ax.lines.remove(gpt.plot[0]) | ||
|
||
update_fig(self.fig) | ||
# matplotlib coord to pixel coord, avoinding use of banker's round | ||
ypix, xpix = int(event.ydata + 0.5), int(event.xdata + 0.5) | ||
# need to annotate only if a new group: | ||
listpeak = self.massif.find_peaks([event.ydata, event.xdata], | ||
listpeak = self.massif.find_peaks([ypix, xpix], | ||
self.defaultNbPoints, None, | ||
self.massif_contour) | ||
if listpeak: | ||
|
@@ -466,7 +473,9 @@ def append_1_point(event): | |
if gpt.plot[0] in self.ax.lines: | ||
self.ax.lines.remove(gpt.plot[0]) | ||
update_fig(self.fig) | ||
newpeak = self.massif.nearest_peak([event.ydata, event.xdata]) | ||
# matplotlib coord to pixel coord, avoinding use of banker's round | ||
ypix, xpix = int(event.ydata + 0.5), int(event.xdata + 0.5) | ||
newpeak = self.massif.nearest_peak([ypix, xpix]) | ||
if newpeak: | ||
gpt.points.append(newpeak) | ||
logger.info("x=%5.1f, y=%5.1f added to group #%2s", newpeak[1], newpeak[0], gpt.label) | ||
|
@@ -511,8 +520,8 @@ def erase_1_point(event): | |
self.ax.lines.remove(gpt.plot[0]) | ||
if len(gpt) > 1: | ||
# delete single closest point from current group | ||
x0 = event.xdata | ||
y0 = event.ydata | ||
# matplotlib coord to pixel coord, avoinding use of banker's round | ||
y0, x0 = int(event.ydata + 0.5), int(event.xdata + 0.5) | ||
distsq = [((p[1] - x0) ** 2 + (p[0] - y0) ** 2) for p in gpt.points] | ||
# index and distance of smallest distance: | ||
indexMin = min(enumerate(distsq), key=operator.itemgetter(1)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,20 +35,28 @@ __author__ = "Jerome Kieffer" | |
__contact__ = "[email protected]" | ||
__license__ = "GPLv3+" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "28/11/2016" | ||
__date__ = "05/12/2016" | ||
__satus__ = "development" | ||
|
||
|
||
import os | ||
import sys | ||
import h5py | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger("eiger-mask") | ||
import numpy | ||
import fabio | ||
|
||
try: | ||
from argparse import ArgumentParser | ||
except ImportError: | ||
from pyFAI.third_party.argparse import ArgumentParser | ||
|
||
try: | ||
import h5py | ||
except ImportError: | ||
h5py = None | ||
|
||
|
||
def extract_mask(infile): | ||
""" | ||
|
@@ -65,11 +73,18 @@ def extract_mask(infile): | |
|
||
if __name__ == "__main__": | ||
description = "A tool to extract the mask from an Eiger detector file." | ||
parser = ArgumentParser(description=description) | ||
epilog = None | ||
if h5py is None: | ||
epilog = "Python h5py module is missing. It have to be installed to use this application" | ||
parser = ArgumentParser(description=description, epilog=epilog) | ||
parser.add_argument('input_file', help='Input file. Must be an HDF5 file.') | ||
parser.add_argument('output_file', nargs="?", help='Output file. It can be an msk, tif, or an edf file.') | ||
options = parser.parse_args() | ||
|
||
if h5py is None: | ||
logger.error("Python h5py module is expected to use this script") | ||
sys.exit(1) | ||
|
||
infile = os.path.abspath(options.input_file) | ||
if options.output_file is not None: | ||
outfile = options.output_file | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters