Skip to content

Commit 83908b9

Browse files
committed
Docs for multi-color stuff
1 parent bacd197 commit 83908b9

File tree

9 files changed

+100
-2
lines changed

9 files changed

+100
-2
lines changed

src/multicolor/features/color_of_maximum.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub use serde::{Deserialize, Serialize};
1111
use std::collections::BTreeSet;
1212
use std::fmt::Debug;
1313

14+
/// Difference maximum value magnitudes of two passbands
15+
///
16+
/// Note that maximum is calculated for each passband separately, and maximum has mathematical
17+
/// meaning, not "magnitudial" (astronomical) one.
1418
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1519
#[serde(bound(deserialize = "P: PassbandTrait + Deserialize<'de>"))]
1620
pub struct ColorOfMaximum<P>
@@ -27,6 +31,10 @@ impl<P> ColorOfMaximum<P>
2731
where
2832
P: PassbandTrait,
2933
{
34+
/// Create new [ColorOfMaximum] evaluator
35+
///
36+
/// # Arguments
37+
/// - `passbands` - two passbands
3038
pub fn new(passbands: [P; 2]) -> Self {
3139
let set: BTreeSet<_> = passbands.clone().into();
3240
Self {

src/multicolor/features/color_of_median.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub use serde::{Deserialize, Serialize};
1414
use std::collections::BTreeSet;
1515
use std::fmt::Debug;
1616

17+
/// Difference of median magnitudes in two passbands
18+
///
19+
/// Note that median is calculated for each passband separately
1720
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1821
#[serde(bound(deserialize = "P: PassbandTrait + Deserialize<'de>"))]
1922
pub struct ColorOfMedian<P>

src/multicolor/features/color_of_minimum.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub use serde::{Deserialize, Serialize};
1111
use std::collections::BTreeSet;
1212
use std::fmt::Debug;
1313

14+
/// Difference of minimum magnitudes of two passbands
15+
///
16+
/// Note that minimum is calculated for each passband separately, and maximum has mathematical
17+
/// meaning, not "magnitudial" (astronomical) one.
1418
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1519
#[serde(bound(deserialize = "P: PassbandTrait + Deserialize<'de>"))]
1620
pub struct ColorOfMinimum<P>
@@ -27,6 +31,10 @@ impl<P> ColorOfMinimum<P>
2731
where
2832
P: PassbandTrait,
2933
{
34+
/// Create new [ColorOfMinimum] evaluator
35+
///
36+
/// # Arguments
37+
/// - `passbands` - two passbands
3038
pub fn new(passbands: [P; 2]) -> Self {
3139
let set: BTreeSet<_> = passbands.clone().into();
3240
Self {

src/multicolor/features/multi_color_periodogram.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ use crate::evaluator::TmArrays;
44
use crate::evaluator::{
55
EvaluatorInfo, EvaluatorInfoTrait, FeatureEvaluator, FeatureNamesDescriptionsTrait, OwnedArrays,
66
};
7-
87
use crate::features::{Periodogram, PeriodogramPeaks};
98
use crate::float_trait::Float;
109
use crate::multicolor::multicolor_evaluator::*;
1110
use crate::multicolor::{PassbandSet, PassbandTrait};
1211
use crate::periodogram::{self, NyquistFreq, PeriodogramPower};
1312

1413
use ndarray::Array1;
15-
1614
use std::fmt::Debug;
1715

16+
/// Multi-passband periodogram
1817
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1918
#[serde(
2019
bound = "T: Float, F: FeatureEvaluator<T> + From<PeriodogramPeaks> + TryInto<PeriodogramPeaks>, <F as TryInto<PeriodogramPeaks>>::Error: Debug,"

src/multicolor/monochrome_feature.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::collections::BTreeSet;
1515
use std::fmt::Debug;
1616
use std::marker::PhantomData;
1717

18+
/// Multi-color feature which evaluates non-color dependent feature for each passband.
1819
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1920
#[serde(bound(
2021
deserialize = "P: PassbandTrait + Deserialize<'de>, T: Float, F: FeatureEvaluator<T>"
@@ -35,6 +36,11 @@ where
3536
T: Float,
3637
F: FeatureEvaluator<T>,
3738
{
39+
/// Creates a new instance of `MonochromeFeature`.
40+
///
41+
/// # Arguments
42+
/// - `feature` - non-multi-color feature to evaluate for each passband.
43+
/// - `passband_set` - set of passbands to evaluate the feature for.
3844
pub fn new(feature: F, passband_set: BTreeSet<P>) -> Self {
3945
let names = passband_set
4046
.iter()
@@ -130,3 +136,32 @@ where
130136
}
131137
}
132138
}
139+
140+
#[cfg(test)]
141+
mod tests {
142+
use super::*;
143+
144+
use crate::features::Mean;
145+
use crate::multicolor::passband::MonochromePassband;
146+
use crate::Feature;
147+
148+
#[test]
149+
fn test_monochrome_feature() {
150+
let feature: MonochromeFeature<MonochromePassband<_>, f64, Feature<_>> =
151+
MonochromeFeature::new(
152+
Mean::default().into(),
153+
[
154+
MonochromePassband::new(4700e-8, "g"),
155+
MonochromePassband::new(6200e-8, "r"),
156+
]
157+
.into_iter()
158+
.collect(),
159+
);
160+
assert_eq!(feature.get_names(), vec!["mean_g", "mean_r"]);
161+
assert_eq!(
162+
feature.get_descriptions(),
163+
vec!["mean magnitude, passband g", "mean magnitude, passband r"]
164+
);
165+
assert_eq!(feature.get_info().size, 2);
166+
}
167+
}

src/multicolor/multicolor_evaluator.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@ pub use serde::{Deserialize, Serialize};
1616
use std::collections::BTreeSet;
1717
use std::fmt::Debug;
1818

19+
/// Trait for getting alphabetically sorted passbands
1920
#[enum_dispatch]
2021
pub trait MultiColorPassbandSetTrait<P>
2122
where
2223
P: PassbandTrait,
2324
{
25+
/// Get passband set for this evaluator
2426
fn get_passband_set(&self) -> &PassbandSet<P>;
2527
}
2628

29+
/// Enum for passband set, which can be either fixed set or all available passbands.
30+
/// This is used for [MultiColorEvaluator]s, which can be evaluated on all available passbands
31+
/// (for example [MultiColorPeriodogram](super::features::MultiColorPeriodogram)) or on fixed set of
32+
/// passbands (for example [ColorOfMaximum](super::ColorOfMaximum)).
2733
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
2834
#[serde(bound(deserialize = "P: PassbandTrait + Deserialize<'de>"))]
2935
#[non_exhaustive]
3036
pub enum PassbandSet<P>
3137
where
3238
P: Ord,
3339
{
40+
/// Fixed set of passbands
3441
FixedSet(BTreeSet<P>),
42+
/// All available passbands
3543
AllAvailable,
3644
}
3745

@@ -44,6 +52,7 @@ where
4452
}
4553
}
4654

55+
/// Helper error for [MultiColorEvaluator]
4756
enum InternalMctsError {
4857
MultiColorEvaluatorError(MultiColorEvaluatorError),
4958
InternalWrongPassbandSet,
@@ -78,6 +87,7 @@ impl InternalMctsError {
7887
}
7988
}
8089

90+
/// Trait for multi-color feature evaluators
8191
#[enum_dispatch]
8292
pub trait MultiColorEvaluator<P, T>:
8393
FeatureNamesDescriptionsTrait

src/multicolor/multicolor_extractor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::collections::BTreeSet;
1212
use std::fmt::Debug;
1313
use std::marker::PhantomData;
1414

15+
/// Bulk feature evaluator.
1516
#[derive(Clone, Debug, Serialize, Deserialize)]
1617
#[serde(
1718
into = "MultiColorExtractorParameters<MCF>",
@@ -37,6 +38,10 @@ where
3738
T: Float,
3839
MCF: MultiColorEvaluator<P, T>,
3940
{
41+
/// Create a new [MultiColorExtractor]
42+
///
43+
/// # Arguments
44+
/// `features` - A vector of multi-color features to be evaluated
4045
pub fn new(features: Vec<MCF>) -> Self {
4146
let passband_set = {
4247
let set: BTreeSet<_> = features

src/multicolor/passband/dump_passband.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub use schemars::JsonSchema;
44
pub use serde::{Deserialize, Serialize};
55
use std::fmt::Debug;
66

7+
/// A passband for the cases where we don't care about the actual passband.
78
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)]
89
pub struct DumpPassband {}
910

@@ -12,3 +13,14 @@ impl PassbandTrait for DumpPassband {
1213
""
1314
}
1415
}
16+
17+
#[cfg(test)]
18+
mod tests {
19+
use super::*;
20+
21+
#[test]
22+
fn test_dump_passband() {
23+
let passband = DumpPassband {};
24+
assert_eq!(passband.name(), "");
25+
}
26+
}

src/multicolor/passband/monochrome_passband.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use serde::{Deserialize, Serialize};
77
use std::cmp::Ordering;
88
use std::fmt::Debug;
99

10+
/// A passband specified by a single wavelength.
1011
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
1112
pub struct MonochromePassband<'a, T> {
1213
pub name: &'a str,
@@ -17,6 +18,11 @@ impl<'a, T> MonochromePassband<'a, T>
1718
where
1819
T: Float,
1920
{
21+
/// Create a new `MonochromePassband`.
22+
///
23+
/// # Arguments
24+
/// - `wavelength`: The wavelength of the passband, panic if it is not a positive normal number.
25+
/// - `name`: The name of the passband.
2026
pub fn new(wavelength: T, name: &'a str) -> Self {
2127
assert!(
2228
wavelength.is_normal(),
@@ -67,3 +73,15 @@ where
6773
self.name
6874
}
6975
}
76+
77+
#[cfg(test)]
78+
mod tests {
79+
use super::*;
80+
81+
#[test]
82+
fn test_monochrome_passband() {
83+
let passband = MonochromePassband::new(1.0, "test");
84+
assert_eq!(passband.name(), "test");
85+
assert_eq!(passband.wavelength, 1.0);
86+
}
87+
}

0 commit comments

Comments
 (0)