Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noise analysis #22

Merged
merged 9 commits into from
Oct 1, 2024
Merged
13 changes: 13 additions & 0 deletions analysis/NoiseAnalysis.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module NoiseAnalysis

using Distributions
using LinearAlgebra
using ShockwaveDetection #: FlowData

export NoiseData
export apply_noise, apply_noise_to_flow
export compare_shock_clusters_over_time, compare_shock_positions_over_time, compare_shock_fits_over_time

include("noise.jl")

end
24 changes: 24 additions & 0 deletions analysis/examples/sod_shock_tube_1d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Euler2D
using LinearAlgebra
using ShockwaveProperties
using Unitful
using ShockwaveDetection
include("../NoiseAnalysis.jl")
using .NoiseAnalysis
using Distributions

# Create a NoiseData instance
noise_data = NoiseAnalysis.NoiseData(0.01, Normal(0, 0.2)) #Gaussian distribution

flow_data = FlowData("examples/data/sod_shock_left_1d.tape", false)

# Apply noise to flow data
noisy_flow_data = NoiseAnalysis.apply_noise_to_flow(flow_data, noise_data)

point_detect_algo = GradientShockDetectionAlgo(0.8)

original_shock_positions_over_time = detect(flow_data, point_detect_algo)
noisy_shock_positions_over_time = detect(noisy_flow_data, point_detect_algo)

# Detect and compare shock positions with and without noise
shock_diff = NoiseAnalysis.compare_shock_positions_over_time_1d(original_shock_positions_over_time, noisy_shock_positions_over_time; threshold=10.0)
23 changes: 23 additions & 0 deletions analysis/examples/sod_shock_tube_2d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ShockwaveDetection
include("../NoiseAnalysis.jl")
using .NoiseAnalysis
using Distributions
ENV["JULIA_NUM_THREADS"] = "4"

flow_data = FlowData("examples/data/sod_shock_right_2d.tape", false)
noise_data = NoiseAnalysis.NoiseData(0.01, Normal(0, 0.1))
noisy_flow_data = NoiseAnalysis.apply_noise_to_flow(flow_data, noise_data)

point_detect_algo = ImageProcessingShockDetectionAlgo(0.8, :prewitt)
fitting_algo = FittingAlgo(0.1, true)
dbscan_algo = DBSCANAlgo(5.95, 3, 10)

# Detect shock points, clusters, and fits for original and noisy data
original_result = detect(flow_data, point_detect_algo, dbscan_algo, fitting_algo)
noisy_result = detect(noisy_flow_data, point_detect_algo, dbscan_algo, fitting_algo)

rmse_value = NoiseAnalysis.compare_shock_fits_over_time(original_result, noisy_result, flow_data; threshold=10.0)
println("RMSE between fits, cluster_fit_mismatch_count, empty_residuals_count, shock_data_missing_count, residual_length_mismatch_count: ", rmse_value)

#plot_shock_fits_over_time(flow_data, original_detection, true)
#plot_shock_fits_over_time(noisy_flow_data, noisy_detection, true)
Loading
Loading