Skip to content

Commit

Permalink
modified: Cargo.lock
Browse files Browse the repository at this point in the history
	modified:   Cargo.toml
	modified:   README.md
	modified:   assets/favicon.ico
	modified:   assets/icon-1024.png
	modified:   assets/icon-256.png
	modified:   assets/icon_ios_touch_192.png
	modified:   assets/maskable_icon_x512.png
	modified:   assets/sw.js
	modified:   index.html
	modified:   src/app.rs
	modified:   src/app_web.rs
	modified:   src/histoer/histogram1d.rs
	modified:   src/histoer/histogrammer.rs
	modified:   src/histoer/plot_settings.rs
	modified:   src/lib.rs
	modified:   src/main.rs
	modified:   src/pane.rs
  • Loading branch information
alconley committed Jun 6, 2024
1 parent 28381fd commit cd092f0
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 52 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "muc"
name = "nat"
version = "0.1.0"
authors = ["Alex Conley <[email protected]>"]
edition = "2021"
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# muc
# Nuclear Analysis Tool (NAT)

The Nuclear Analysis Tool (NAT) is a comprehensive software designed for nuclear data analysis. It provides functionalities for histogramming, Gaussian fitting, and interactive data visualization using `egui` and `egui_plot` crates.

## Features

- Create and manage histograms
- Fit Gaussian peaks
- Interactive data visualization
- Export and import fits
- Customizable plot settings

### Testing locally

Make sure you are using the latest version of stable rust by running `rustup update`.
Make sure you are using the latest version of stable rust by running `rustup update`. Rust is very easy to install on any computer. First, you'll need to install the Rust toolchain (compiler, cargo, etc). Go to the [Rust website](https://www.rust-lang.org/tools/install) and follow the instructions there.

Then clone the respository recursively

`git clone --recursive https://github.com/alconley/NAT.git`

`cargo run --release`

Expand All @@ -13,3 +27,22 @@ On Linux you need to first run:
On Fedora Rawhide you need to run:

`dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel gtk3-devel atk fontconfig-devel`

## 1D Histogram

### Fitting
Multiple gaussians can be fitted interactively similar to [hdtv](https://github.com/janmayer/hdtv).

**Keybinds**
- P: Add Marker
- B: Add Background Marker
- R: Add Region Marker
- -: Remove Marker Closest to Cursor
- Delete: Remove All Markers and Temp Fits
- G: Fit Background (Fit a linear background using the background markers)
- F: Fit Gaussians (Fit gaussians at the peak markers within a specified region with a linear background)
- S: Store Fit (Store the current fit as a permanent fit which can be saved and loaded later)
- I: Toggle Stats
- L: Toggle Log Y

The idea is to put region markers around you peak of intrest. If there are multiple peaks in between the region markers, add the centroid approximately with the peak markers. The background will be calculated with a linear line. To manually select the background data, add the background markers. If no background markers are supplied, background markers will be put at the region markers. The fits can be stored, and then the user can save/load them by right clicking on the plot and going into the fit menu.
Binary file modified assets/favicon.ico
100755 → 100644
Binary file not shown.
Binary file modified assets/icon-1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon_ios_touch_192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/maskable_icon_x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var cacheName = 'egui-template-pwa';
var filesToCache = [
'./',
'./index.html',
'./muc.js',
'./muc_bg.wasm',
'./NAT.js',
'./NAT_bg.wasm',
];

/* Start the service worker and cache all of the app's content */
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<head>
<!-- change this to your project name -->
<title>muc</title>
<title>NAT</title>

<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
<link data-trunk rel="rust" data-wasm-opt="2" />
Expand Down
7 changes: 4 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ impl Default for NATApp {
let workspacer = Workspacer::new();
let processer = Processer::new();

let mut tabs = vec![];
tabs.push(tiles.insert_pane(Pane::Workspace(workspacer.clone())));
// let mut tabs = vec![];
// tabs.push(tiles.insert_pane(Pane::Workspace(workspacer.clone())));
let tabs = vec![tiles.insert_pane(Pane::Workspace(workspacer.clone()))];

let root = tiles.insert_tab_tile(tabs);

Expand Down Expand Up @@ -101,7 +102,7 @@ impl eframe::App for NATApp {
});

egui::SidePanel::left("tree")
.max_width(300.0)
.max_width(200.0)
.show_animated(ctx, self.side_panel_open, |ui| {
egui::global_dark_light_mode_buttons(ui);

Expand Down
6 changes: 3 additions & 3 deletions src/app_web.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use eframe::App;

#[derive(serde::Deserialize, serde::Serialize, Debug, Default)]
pub struct MUCApp {}
pub struct NATApp {}

impl MUCApp {
impl NATApp {
pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
Self::default()
}
}

impl App for MUCApp {
impl App for NATApp {
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("muc is not supported in the browser yet. Please run it natively.");
Expand Down
34 changes: 29 additions & 5 deletions src/histoer/histogram1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ use crate::fitter::fit_handler::{FitModel, Fits, Fitter};

use super::plot_settings::EguiPlotSettings;

// background_fit_line: DrawLine::new(true, egui::Color32::GREEN),
// deconvoluted_fit_line: DrawLine::new(true, egui::Color32::from_rgb(255, 0, 255)),
// convoluted_fit_line: DrawLine::new(true, egui::Color32::BLUE),
// stored_fit_lines: DrawLine::new(true, egui::Color32::BLUE),

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PlotSettings {
#[serde(skip)]
Expand Down Expand Up @@ -325,6 +320,34 @@ impl Histogram {
}
}

// create a ui function to show the keybinds in the context menu
fn keybinds_ui(&mut self, ui: &mut egui::Ui) {
ui.menu_button("Keybind Help", |ui| {
egui::ScrollArea::vertical()
.id_source("keybinds_scroll")
.max_height(300.0)
.show(ui, |ui| {
ui.heading("Keybinds");
ui.separator();
ui.label("Markers");
ui.label("P: Add Marker");
ui.label("B: Add Background Marker");
ui.label("R: Add Region Marker");
ui.label("-: Remove Marker Closest to Cursor");
ui.label("Delete: Remove All Markers and Temp Fits");
ui.separator();
ui.label("Fitting");
ui.label("G: Fit Background").on_hover_text("Fit a linear background using the background markers");
ui.label("F: Fit Gaussians").on_hover_text("Fit gaussians at the peak markers give some region with a linear background");
ui.label("S: Store Fit").on_hover_text("Store the current fit as a permanent fit which can be saved and loaded later");
ui.separator();
ui.label("Plot");
ui.label("I: Toggle Stats");
ui.label("L: Toggle Log Y");
});
});
}

// Draw the histogram, fit lines, markers, and stats
fn draw(&mut self, plot_ui: &mut egui_plot::PlotUi) {
// update the histogram and fit lines with the log setting and draw
Expand Down Expand Up @@ -354,6 +377,7 @@ impl Histogram {
self.line.menu_button(ui);
self.plot_settings.settings_ui(ui);
self.fits.fit_context_menu_ui(ui);
self.keybinds_ui(ui);
}

// Renders the histogram using egui_plot
Expand Down
3 changes: 2 additions & 1 deletion src/histoer/histogrammer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ impl Histogrammer {
let mut panes = vec![];

for hist in &self.histograms1d {
panes.push(Pane::Histogram(hist.clone()));
// panes.push(Pane::Histogram(hist.clone()));
panes.push(Pane::Histogram(Box::new(hist.clone())));
}

panes
Expand Down
6 changes: 2 additions & 4 deletions src/histoer/plot_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ impl EguiPlotSettings {
plot
};

let plot = if log_y {
if log_y {
plot.y_grid_spacer(log_axis_spacer)
.y_axis_formatter(log_axis_formatter)
} else {
plot
};

plot
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ pub mod tree;
#[cfg(target_arch = "wasm32")]
mod app_web;
#[cfg(target_arch = "wasm32")]
pub use app_web::MUCApp;
pub use app_web::NATApp;
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use muc::NATApp;
use nat::NATApp;

use eframe::egui;

Expand All @@ -20,13 +20,12 @@ fn main() -> eframe::Result<()> {
..Default::default()
};
eframe::run_native(
"muc",
"NAT",
native_options,
Box::new(|cc| Box::new(NATApp::new(cc))),
)
}


// When compiling to web using trunk:
#[cfg(target_arch = "wasm32")]
fn main() {
Expand All @@ -40,9 +39,9 @@ fn main() {
.start(
"NAT", // hardcode it
web_options,
Box::new(|cc| Box::new(muc::app::new(cc))),
Box::new(|cc| Box::new(NATApp::new(cc))),
)
.await
.expect("failed to start eframe");
});
}
}
2 changes: 1 addition & 1 deletion src/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::workspacer::Workspacer;
#[derive(Clone, serde::Serialize, serde::Deserialize)]
pub enum Pane {
Workspace(Workspacer),
Histogram(Histogram),
Histogram(Box<Histogram>),
Histogram2D(Histogram2D),
}

Expand Down

0 comments on commit cd092f0

Please sign in to comment.