Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OPOSSUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
phelix
rust
OPOSSUM
Commits
9fc9df84
Commit
9fc9df84
authored
1 year ago
by
Udo Eisenbarth
Browse files
Options
Downloads
Patches
Plain Diff
Implement handling of spectra for beamsplitter
parent
8ff579e3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/source_detector_test.rs
+2
-3
2 additions, 3 deletions
examples/source_detector_test.rs
src/lightdata.rs
+1
-1
1 addition, 1 deletion
src/lightdata.rs
src/nodes/node_beam_splitter.rs
+33
-13
33 additions, 13 deletions
src/nodes/node_beam_splitter.rs
src/spectrum.rs
+35
-1
35 additions, 1 deletion
src/spectrum.rs
with
71 additions
and
18 deletions
examples/source_detector_test.rs
+
2
−
3
View file @
9fc9df84
use
std
::
fs
::
File
;
use
std
::
io
::
Write
;
use
uom
::
si
::{
energy
::
joule
,
f64
::
Energy
};
use
opossum
::{
analyzer
::
AnalyzerEnergy
,
error
::
OpossumError
,
lightdata
::{
DataEnergy
,
LightData
},
nodes
::{
BeamSplitter
,
Detector
,
IdealFilter
,
Source
},
optic_scenery
::
OpticScenery
,
optic_scenery
::
OpticScenery
,
spectrum
::
create_he_ne_spectrum
,
};
fn
main
()
->
Result
<
(),
OpossumError
>
{
...
...
@@ -17,7 +16,7 @@ fn main() -> Result<(), OpossumError> {
let
i_s
=
scenery
.add_element
(
"Source"
,
Source
::
new
(
LightData
::
Energy
(
DataEnergy
{
energy
:
Energy
::
new
::
<
joule
>
(
1.0
),
spectrum
:
create_he_ne_spectrum
(
1.0
),
})),
);
let
i_bs
=
scenery
.add_element
(
"Beam splitter"
,
BeamSplitter
::
new
(
0.6
));
...
...
This diff is collapsed.
Click to expand it.
src/lightdata.rs
+
1
−
1
View file @
9fc9df84
...
...
@@ -33,5 +33,5 @@ pub struct DataEnergy {
#[derive(Debug,
Clone)]
pub
struct
DataGeometric
{
ray
:
i32
,
_
ray
:
i32
,
}
This diff is collapsed.
Click to expand it.
src/nodes/node_beam_splitter.rs
+
33
−
13
View file @
9fc9df84
use
std
::
collections
::
HashMap
;
use
uom
::{
num_traits
::
Zero
,
si
::
f64
::
Energy
};
use
crate
::{
analyzer
::
AnalyzerType
,
...
...
@@ -9,6 +8,7 @@ use crate::{
optic_ports
::
OpticPorts
,
spectrum
::
Spectrum
,
};
use
crate
::
spectrum
::
unify_spectrum
;
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
OpossumError
>
;
...
...
@@ -37,30 +37,50 @@ impl BeamSplitter {
let
in1
=
incoming_data
.get
(
"input1"
);
let
in2
=
incoming_data
.get
(
"input2"
);
let
mut
in1_spectrum
:
Option
<
Spectrum
>
=
None
;
let
mut
in2_spectrum
:
Option
<
Spectrum
>
=
None
;
let
mut
out1_1_spectrum
:
Option
<
Spectrum
>
=
None
;
let
mut
out1_2_spectrum
:
Option
<
Spectrum
>
=
None
;
let
mut
out2_1_spectrum
:
Option
<
Spectrum
>
=
None
;
let
mut
out2_2_spectrum
:
Option
<
Spectrum
>
=
None
;
if
let
Some
(
Some
(
in1
))
=
in1
{
match
in1
{
LightData
::
Energy
(
e
)
=>
in1_spectrum
=
Some
(
e
.spectrum
.clone
()),
LightData
::
Energy
(
e
)
=>
{
let
mut
s
=
e
.spectrum
.clone
();
s
.scale_vertical
(
self
.ratio
)
.unwrap
();
out1_1_spectrum
=
Some
(
s
);
let
mut
s
=
e
.spectrum
.clone
();
s
.scale_vertical
(
1.0
-
self
.ratio
)
.unwrap
();
out1_2_spectrum
=
Some
(
s
);
}
_
=>
return
Err
(
OpossumError
::
Analysis
(
"expected DataEnergy value"
.into
())),
}
}
if
let
Some
(
Some
(
in2
))
=
in2
{
match
in2
{
LightData
::
Energy
(
e
)
=>
in2_spectrum
=
Some
(
e
.spectrum
.clone
()),
LightData
::
Energy
(
e
)
=>
{
let
mut
s
=
e
.spectrum
.clone
();
s
.scale_vertical
(
self
.ratio
)
.unwrap
();
out2_1_spectrum
=
Some
(
s
);
let
mut
s
=
e
.spectrum
.clone
();
s
.scale_vertical
(
1.0
-
self
.ratio
)
.unwrap
();
out2_2_spectrum
=
Some
(
s
);
},
_
=>
return
Err
(
OpossumError
::
Analysis
(
"expected DataEnergy value"
.into
())),
}
}
// let out1_energy = Some(LightData::Energy(DataEnergy {
// energy: in1_energy * self.ratio + in2_energy * (1.0 - self.ratio),
// }));
// let out2_energy = Some(LightData::Energy(DataEnergy {
// energy: in1_energy * (1.0 - self.ratio) + in2_energy * self.ratio,
// }));
let
out1_spec
=
unify_spectrum
(
out1_1_spectrum
,
out2_2_spectrum
);
let
out2_spec
=
unify_spectrum
(
out1_2_spectrum
,
out2_1_spectrum
);
let
mut
out1_data
:
Option
<
LightData
>=
None
;
let
mut
out2_data
:
Option
<
LightData
>=
None
;
if
let
Some
(
out1_spec
)
=
out1_spec
{
out1_data
=
Some
(
LightData
::
Energy
(
DataEnergy
{
spectrum
:
out1_spec
}))
}
if
let
Some
(
out2_spec
)
=
out2_spec
{
out2_data
=
Some
(
LightData
::
Energy
(
DataEnergy
{
spectrum
:
out2_spec
}))
}
Ok
(
HashMap
::
from
([
(
"out1_trans1_refl2"
.into
(),
None
),
//out1_energy
),
(
"out2_trans2_refl1"
.into
(),
None
),
//out2_energy
),
(
"out1_trans1_refl2"
.into
(),
out1_data
),
(
"out2_trans2_refl1"
.into
(),
out2_data
),
]))
}
}
...
...
This diff is collapsed.
Click to expand it.
src/spectrum.rs
+
35
−
1
View file @
9fc9df84
...
...
@@ -81,7 +81,9 @@ impl Spectrum {
datas
.push
(
data
*
0.01
);
// percent -> transmisison
}
if
lambdas
.is_empty
()
{
return
Err
(
OpossumError
::
Spectrum
(
"no csv data was found in file"
.into
()));
return
Err
(
OpossumError
::
Spectrum
(
"no csv data was found in file"
.into
(),
));
}
Ok
(
Self
{
data
:
Array1
::
from_vec
(
datas
),
...
...
@@ -93,6 +95,11 @@ impl Spectrum {
Length
::
new
::
<
meter
>
(
*
self
.lambdas
.first
()
.unwrap
())
..
Length
::
new
::
<
meter
>
(
*
self
.lambdas
.last
()
.unwrap
())
}
pub
fn
estimate_resolution
(
&
self
)
->
Length
{
let
r
=
self
.range
();
let
bandwidth
=
r
.end
-
r
.start
;
bandwidth
/
(
self
.lambdas
.len
()
as
f64
)
}
/// Add a single peak to the given [`Spectrum`].
///
/// This functions adds a single (resolution limited) peak to the [`Spectrum`] at the given wavelength and
...
...
@@ -448,6 +455,29 @@ pub fn create_yb_yag_spectrum(energy: f64) -> Spectrum {
.unwrap
();
s
}
pub
fn
unify_spectrum
(
s1
:
Option
<
Spectrum
>
,
s2
:
Option
<
Spectrum
>
)
->
Option
<
Spectrum
>
{
if
s1
.is_none
()
&&
s2
.is_none
()
{
None
}
else
if
s1
.is_some
()
&&
s2
.is_none
()
{
s1
}
else
if
s1
.is_none
()
&&
s2
.is_some
()
{
s2
}
else
{
let
s1_range
=
s1
.as_ref
()
.unwrap
()
.range
();
let
s2_range
=
s2
.as_ref
()
.unwrap
()
.range
();
let
minimum
=
s1_range
.start
.min
(
s2_range
.start
);
let
maximum
=
s1_range
.end
.max
(
s2_range
.end
);
let
resolution
=
s1
.as_ref
()
.unwrap
()
.estimate_resolution
()
.min
(
s2
.as_ref
()
.unwrap
()
.estimate_resolution
());
let
mut
s_out
=
Spectrum
::
new
(
minimum
..
maximum
,
resolution
)
.unwrap
();
s_out
.resample
(
&
s1
.unwrap
());
s_out
.add
(
&
s2
.unwrap
());
Some
(
s_out
)
}
}
#[cfg(test)]
mod
test
{
use
super
::
*
;
...
...
@@ -528,6 +558,10 @@ mod test {
)
}
#[test]
fn
estimate_resolution
()
{
todo!
()
}
#[test]
fn
set_single_peak
()
{
let
mut
s
=
prep
();
assert_eq!
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment