Skip to content

Commit

Permalink
Fixes for filters, SpectrumNormalizationFilter no longer crashes tryi…
Browse files Browse the repository at this point in the history
…ng to normalize a fitting with no energy calibration
  • Loading branch information
nathanielsherry committed Jan 6, 2024
1 parent 2f968b1 commit 4c90ccf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

public class FramedLayoutStyle extends SimpleLayoutStyle {

private boolean hiddenOnDisable;
private boolean hiddenOnDisable = false, showBorder = true;

public FramedLayoutStyle() {
super("layout-frames");
}

public FramedLayoutStyle(boolean hideWhenDisabled) {
public FramedLayoutStyle(boolean hideWhenDisabled, boolean showBorder) {
this();
this.hiddenOnDisable = hideWhenDisabled;
this.showBorder = showBorder;
}

public boolean isHiddenOnDisable() {
return hiddenOnDisable;
}

public boolean isShowBorder() {
return showBorder;
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
import javax.swing.border.TitledBorder;

import org.peakaboo.framework.autodialog.model.style.layouts.FramedLayoutStyle;
import org.peakaboo.framework.stratus.api.Spacing;

public class FramesSwingLayout extends SimpleSwingLayout {

@Override
public JComponent getComponent() {
FramedLayoutStyle style = (FramedLayoutStyle) group.getStyle();

JPanel panel = new JPanel(new BorderLayout());
panel.add(root, BorderLayout.CENTER);
panel.setBorder(new TitledBorder(group.getName()));
var border = new TitledBorder(group.getName());
if (!style.isShowBorder()) {
border.setBorder(Spacing.bNone());
}
panel.setBorder(border);


FramedLayoutStyle style = (FramedLayoutStyle) group.getStyle();
if (style.isHiddenOnDisable()) {
panel.setVisible(group.isEnabled());
group.getEnabledHook().addListener(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FittingParameters(FittingParametersView params, FittingSet fits) {

/**
* Constructs a new "dead" or "unwired" FittingParameters object without a
* reference to a parent {@link FittingSet} since a readonly params does not
* reference to a parent {@link FittingSet} since a params view does not
* provide access to that.
*/
public FittingParameters(FittingParametersView params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.peakaboo.framework.autodialog.model.style.editors.RealStyle;
import org.peakaboo.framework.autodialog.model.style.layouts.FramedLayoutStyle;
import org.peakaboo.framework.cyclops.spectrum.ArraySpectrum;
import org.peakaboo.framework.cyclops.spectrum.SpectrumView;
import org.peakaboo.framework.cyclops.spectrum.SpectrumCalculations;
import org.peakaboo.framework.cyclops.spectrum.SpectrumView;


public class SpectrumNormalizationFilter extends AbstractFilter {
Expand All @@ -45,7 +45,7 @@ public enum SmoothingIntensity {
private static final String MODE_RANGE = "Channel Range";
private static final String MODE_MAX = "Strongest Channel";
private static final String MODE_SUM = "All Channels";
private static final String MODE_FIT = "Element";
private static final String MODE_FIT = "Element Fitting";

@Override
public String pluginVersion() {
Expand All @@ -55,32 +55,32 @@ public String pluginVersion() {
@Override
public void initialize() {

pMode = new SelectionParameter<>("Mode", new ListStyle<String>(), MODE_FIT, this::validate);
pMode = new SelectionParameter<>("Mode", new ListStyle<String>(), MODE_SUM, this::validate);
pMode.setPossibleValues(MODE_FIT, MODE_RANGE, MODE_MAX, MODE_SUM);
addParameter(pMode);

pHeight = new Parameter<>("Normalized Intensity", new RealStyle(), 10f, this::validate);
pHeight = new Parameter<>("Target Intensity", new RealStyle(), 10f, this::validate);
addParameter(pHeight);

pSmooth = new SelectionParameter<>("Noise Reduction", new ListStyle<>(), SmoothingIntensity.Low, new EnumClassInfo<>(SmoothingIntensity.class), this::validate);
pSmooth = new SelectionParameter<>("Denoise", new ListStyle<>(), SmoothingIntensity.Low, new EnumClassInfo<>(SmoothingIntensity.class), this::validate);
pSmooth.setPossibleValues(SmoothingIntensity.values());
addParameter(pSmooth);

pStartChannel = new Parameter<>("Start Channel", new IntegerStyle(), 1, this::validate);
pEndChannel = new Parameter<>("End Channel", new IntegerStyle(), 10, this::validate);
gChannelRange = new Group("Channel Range", new FramedLayoutStyle(true), pStartChannel, pEndChannel);
gChannelRange = new Group("Channel Range", new FramedLayoutStyle(true, false), pStartChannel, pEndChannel);
addParameter(gChannelRange);


pElement = new SelectionParameter<>("Fiting Element", new ListStyle<>(), Element.Ar, new EnumClassInfo<>(Element.class), this::validate);
pElement = new SelectionParameter<>("Element", new ListStyle<>(), Element.Ar, new EnumClassInfo<>(Element.class), this::validate);
pElement.setPossibleValues(Element.values());
pElement.setEnabled(false);

pShell = new SelectionParameter<>("Fitting Shell", new ListStyle<>(), TransitionShell.K, new EnumClassInfo<>(TransitionShell.class), this::validate);
pShell = new SelectionParameter<>("Shell", new ListStyle<>(), TransitionShell.K, new EnumClassInfo<>(TransitionShell.class), this::validate);
pShell.setPossibleValues(TransitionShell.K, TransitionShell.L, TransitionShell.M);
pShell.setEnabled(false);

gElement = new Group("Element Selection", new FramedLayoutStyle(true), pElement, pShell);
gElement = new Group("Fitting Selection", new FramedLayoutStyle(true, false), pElement, pShell);
addParameter(gElement);

validate(null);
Expand Down Expand Up @@ -127,14 +127,18 @@ protected SpectrumView filterApplyTo(SpectrumView data, Optional<FilterContext>
ITransitionSeries ts = PeakTable.SYSTEM.get(pElement.getValue(), pShell.getValue());
FilterContext context = requireContext(ctx);


float energy = ts.getStrongestTransition().energyValue;
int channel = context.fittings().getFittingParameters().getCalibration().channelFromEnergy(energy);
startChannel = Math.max(channel-5, 0);
endChannel = Math.min(channel+5, data.size()-1);
int frange = (endChannel - startChannel) + 1;
currentIntensity = filteredData.subSpectrum(startChannel, endChannel).sum() / frange;

var calibration = context.fittings().getFittingParameters().getCalibration();
if (calibration.isZero()) {
//Can't filter, return original data
return data;
} else {
float energy = ts.getStrongestTransition().energyValue;
int channel = context.fittings().getFittingParameters().getCalibration().channelFromEnergy(energy);
startChannel = Math.max(channel-5, 0);
endChannel = Math.min(channel+5, data.size()-1);
int frange = (endChannel - startChannel) + 1;
currentIntensity = filteredData.subSpectrum(startChannel, endChannel).sum() / frange;
}
}

float ratio = currentIntensity / desiredIntensity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.peakaboo.framework.autodialog.model.style.editors.RealStyle;
import org.peakaboo.framework.autodialog.model.style.editors.SeparatorStyle;
import org.peakaboo.framework.cyclops.spectrum.ArraySpectrum;
import org.peakaboo.framework.cyclops.spectrum.SpectrumView;
import org.peakaboo.framework.cyclops.spectrum.Spectrum;
import org.peakaboo.framework.cyclops.spectrum.SpectrumView;

//From Handbook of X-Ray Spectrometry
public class SavitskyGolayNoiseFilter extends AbstractFilter {
Expand Down Expand Up @@ -51,7 +51,7 @@ public void initialize() {

reach = new Parameter<>("Half-Window Size", new IntegerStyle(), 4, this::validate);
order = new Parameter<>("Polynomial Order", new IntegerStyle(), 3, this::validate);
Parameter<?> sep = new Parameter<>(null, new SeparatorStyle(), 0);
Parameter<?> sep = new Parameter<>("separator", new SeparatorStyle(), 0);
ignore = new Parameter<>("Only Smooth Weak Signal", new BooleanStyle(), false, this::validate);
max = new Parameter<>("Smoothing Cutoff: (counts)", new RealStyle(), 4.0f, this::validate);
max.setEnabled(false);
Expand Down

0 comments on commit 4c90ccf

Please sign in to comment.