Commit 3c4c071f authored by Raza, Zamaan's avatar Raza, Zamaan

Merge branch 'filter_extinction' into 'develop'

Filtering by extinction now works

Closes #121

See merge request !122
parents 582dfe42 f35a9996
Pipeline #23008 passed with stage
in 29 minutes and 9 seconds
......@@ -211,7 +211,7 @@ class Experiment:
# Filter by d-range, strength, and allowed by space group
filter.setFilterStrength(True)
filter.setFilterDRange(True)
# filter.setFilterExtinct(True)
filter.setFilterExtinct(filter_params['extinct'])
filter.setDRange(min_d_range, max_d_range)
filter.setStrength(min_strength, max_strength)
......@@ -228,6 +228,10 @@ class Experiment:
self._params.autoindexer['length_tol'],
self._params.autoindexer['angle_tol'])
def assign_unit_cell(self, peak_collection):
cell = self.get_accepted_cell()
self._expt.assignUnitCell(peak_collection)
def autoindex_dataset(self, dataset, start_frame, end_frame, length_tol, angle_tol):
'''
Compute the unit cells from the peaks most a given dataset.
......@@ -290,10 +294,12 @@ class Experiment:
if found:
cell.setSpaceGroup(nsx.SpaceGroup(correct_space_group))
else:
cell.setSpaceGroup(nsx.SpaceGroup(correct_space_group))
self.log(f'WARNING: {correct_space_group} not found in list of compatible space groups')
def set_unit_cell(self, a, b, c, alpha, beta, gamma):
self._expt.addUnitCell("accepted", a, b, c, alpha, beta, gamma)
self.set_space_group()
def build_shape_library(self, data):
'''
......@@ -331,7 +337,7 @@ class Experiment:
Predict shapes of weak peaks
'''
self.log(f"Predicting peaks...")
integrator = "3d profile integrator"
integrator = "1d profile integrator"
interpolation_types = {'None' : nsx.PeakInterpolation_NoInterpolation,
'InverseDistance:': nsx.PeakInterpolation_InverseDistance,
'Intensity:': nsx.PeakInterpolation_Intensity }
......@@ -451,12 +457,16 @@ class Experiment:
raise OSError(f"NSX file {fname} not found")
self.log(f"Loading experiment from {fname}")
self._expt.loadFromFile(fname)
self.set_space_group()
self._found_collection = self._expt.getPeakCollection(self._found_peaks)
self._filtered_collection = \
self._expt.getPeakCollection(self._filtered_peaks)
self._expt.assignUnitCell(self._found_collection)
self._expt.assignUnitCell(self._filtered_collection)
if predicted:
self._predicted_collection = \
self._expt.getPeakCollection(self._filtered_peaks)
self._expt.getPeakCollection(self._predicted_peaks)
self._expt.assignUnitCell(self._predicted_collection)
def remove_peak_collection(self, name):
'''
......
......@@ -40,7 +40,8 @@ class Parameters:
filter = { 'min_strength' : 1.0,
'max_strength' : 1.0e6,
'min_d_range' : 1.5,
'max_d_range' : 50 }
'max_d_range' : 50,
'extinct' : False }
autoindexer = { 'max_dim' : 200.0,
'n_solutions' : 10,
......
#!/usr/bin/env python3
'''
test_filter.py
Test the peak filter for NSXTool
'''
import argparse
import os.path
from nsx.experiment import Experiment, pynsxprint
from nsx.parameters import Parameters
from nsx.peakplot import PeakPlot
from pdb import set_trace
parser = argparse.ArgumentParser(description='NSXTool unit cell/instrument parameters refinement script')
parser.add_argument('-n', '--name', type=str, dest='name', help='name of system', required=True)
parser.add_argument('-d', '--detector', type=str, dest='detector',
help='Type of detector', required=True)
parser.add_argument('-p', '--parameters', type=str, dest='paramfile',
default='parameters', help='File containing experiment paramters')
parser.add_argument('--predicted', action='store_true', dest='predicted',
help='Saved data in .nsx has completed prediction step')
parser.add_argument('-b', '--batches', type=int, dest='batches', default=10,
help='Number of batches of frames')
args = parser.parse_args()
params = Parameters()
if os.path.isfile(args.paramfile):
pynsxprint(f"Reading parameters from {args.paramfile}")
params.load(args.paramfile)
else:
raise RuntimeError("No parameters file detected")
expt = Experiment(args.name, args.detector, params)
expt.set_logger()
logger = expt.get_logger()
expt.load(predicted=args.predicted)
expt.set_space_group()
found_peaks = expt.get_peak_collection('peaks')
npeaks = found_peaks.numberOfPeaks()
params.filter['extinct'] = True
ncaught = expt.filter_peaks(params.filter, found_peaks, 'filtered')
pynsxprint("Filter caught " + str(ncaught) + " of " + str(npeaks) + " peaks")
expt.refine(args.batches)
npeaks = found_peaks.numberOfPeaks()
ncaught = expt.filter_peaks(params.filter, found_peaks, 'filtered')
pynsxprint("Filter caught " + str(ncaught) + " of " + str(npeaks) + " peaks")
......@@ -39,7 +39,9 @@ else:
expt = Experiment(args.name, args.detector, params)
expt.set_logger()
logger = expt.get_logger()
expt.load()
expt.load(predicted=args.predicted)
expt.set_space_group()
collection_name = "peaks"
data = expt.get_data()[0]
refinement_collection = expt.get_peak_collection(collection_name)
......
......@@ -106,7 +106,6 @@ if not args.loadnsx:
gamma = params.cell['gamma']
expt.set_unit_cell(a, b, c, alpha, beta, gamma)
expt.set_space_group()
pynsxprint("Finding peaks...")
expt.find_peaks(data, 0, -1)
pynsxprint("Integrating...")
......@@ -115,6 +114,8 @@ if not args.loadnsx:
found_peaks = expt.get_found_peaks()
pynsxprint("Filtering...")
filtered_collection_name = "filtered"
params.filter['extinct'] = True
expt.assign_unit_cell(found_peaks)
ncaught = expt.filter_peaks(params.filter, found_peaks, filtered_collection_name)
pynsxprint("Filter caught " + str(ncaught) + " of " + str(npeaks) + " peaks")
......@@ -125,14 +126,13 @@ else:
if args.predicted:
expt.load(predicted=args.predicted)
expt.set_space_group()
else:
pynsxprint("Building shape library...")
all_data = expt.get_data()
expt.build_shape_library(all_data)
pynsxprint("Predicting peaks...")
expt.predict_peaks(all_data, 'None')
expt.save(predicted=True) # Exporter does not save shape library to HDF5 (yet)
expt.save(predicted=True)
expt.refine(args.nbatches)
expt.check_peak_collections()
......
......@@ -578,4 +578,9 @@ bool SpaceGroup::isFriedelEquivalent(const MillerIndex& hkl1, const MillerIndex&
return false;
}
std::string SpaceGroup::toString() const
{
return _symbol;
}
} // namespace nsx
......@@ -57,6 +57,8 @@ class SpaceGroup {
//! Returns whether two sets of indices are related by a symmetry up to Friedel reflection
bool isFriedelEquivalent(
const MillerIndex& miller_index1, const MillerIndex& miller_index2) const;
//! Return the symbol as a string
std::string toString() const;
private:
void generateGroupElements();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment