@@ -18,7 +18,8 @@ use hpxlib::nested::{
1818 img:: { ColorMapFunctionType , PosConversion , Val } ,
1919 mom:: {
2020 impls:: { bslice:: FITSMom , zvec:: MomVecImpl } ,
21- new_chi2_count_merger, Mom as MomTrait , ViewableMom , WritableMom ,
21+ new_chi2_count_merger_no_depth_threshold, new_chi2_count_merger_with_depth_threshold,
22+ Mom as MomTrait , ViewableMom , WritableMom ,
2223 } ,
2324 skymap:: SkyMapValue ,
2425 } ,
@@ -64,14 +65,22 @@ pub struct Count {
6465 /// Completeness of the chi2 distribution of 3 degrees of freedom.
6566 #[ clap( default_value_t = 16.266 ) ]
6667 threshold : f64 ,
68+ /// Depth threshold
69+ #[ clap( short = 't' , long, value_name = "DEPTH_MIN" ) ]
70+ depth_threshold : Option < u8 > ,
6771 /// Count MOM destination FITS file.
6872 output : PathBuf ,
6973 #[ clap( subcommand) ]
7074 input : PosOrHash ,
7175}
7276impl Count {
7377 pub fn exec ( self ) -> Result < ( ) , Box < dyn Error > > {
74- self . input . exec ( self . depth , self . threshold , self . output )
78+ self . input . exec (
79+ self . depth ,
80+ self . threshold ,
81+ self . depth_threshold ,
82+ self . output ,
83+ )
7584 }
7685}
7786
@@ -89,22 +98,30 @@ enum PosOrHash {
8998 } ,
9099}
91100impl PosOrHash {
92- pub fn exec ( self , depth : u8 , threshold : f64 , output : PathBuf ) -> Result < ( ) , Box < dyn Error > > {
101+ pub fn exec (
102+ self ,
103+ depth : u8 ,
104+ threshold : f64 ,
105+ depth_threshold : Option < u8 > ,
106+ output : PathBuf ,
107+ ) -> Result < ( ) , Box < dyn Error > > {
93108 match self {
94- Self :: Pos { input } => build_count_mom_from_pos ( depth, threshold, input) ,
95- Self :: Hash { input } => build_count_mom_from_hash ( depth, threshold, input) ,
109+ Self :: Pos { input } => build_count_mom_from_pos ( depth, threshold, depth_threshold , input) ,
110+ Self :: Hash { input } => build_count_mom_from_hash ( depth, threshold, depth_threshold , input) ,
96111 }
97112 . and_then ( |mom| mom. to_fits_file ( output, "DENSITY" ) . map_err ( |e| e. into ( ) ) )
98113 }
99114}
100115fn build_count_mom_from_pos (
101116 depth : u8 ,
102117 threshold : f64 ,
118+ depth_threshold : Option < u8 > ,
103119 input : PosListInput ,
104120) -> Result < MomVecImpl < u64 , u32 > , Box < dyn Error > > {
105121 struct Op {
106122 depth : u8 ,
107123 threshold : f64 ,
124+ depth_threshold : Option < u8 > ,
108125 }
109126 impl PosItOperation for Op {
110127 type R = MomVecImpl < u64 , u32 > ;
@@ -123,25 +140,37 @@ fn build_count_mom_from_pos(
123140 self . depth ,
124141 SortedHashIt :: new ( self . depth , it) ,
125142 ) ;
126- let chi2_merger = new_chi2_count_merger ( self . threshold ) ;
127- MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
128- self . depth ,
129- hash_count_it,
130- chi2_merger,
131- )
143+ match self . depth_threshold {
144+ None => MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
145+ self . depth ,
146+ hash_count_it,
147+ new_chi2_count_merger_no_depth_threshold ( self . threshold ) ,
148+ ) ,
149+ Some ( depth_threshold) => MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
150+ self . depth ,
151+ hash_count_it,
152+ new_chi2_count_merger_with_depth_threshold ( self . threshold , depth_threshold) ,
153+ ) ,
154+ }
132155 . map_err ( |e| e. into ( ) )
133156 }
134157 }
135- input. exec ( Op { depth, threshold } )
158+ input. exec ( Op {
159+ depth,
160+ threshold,
161+ depth_threshold,
162+ } )
136163}
137164fn build_count_mom_from_hash (
138165 depth : u8 ,
139166 threshold : f64 ,
167+ depth_threshold : Option < u8 > ,
140168 input : HashListInput ,
141169) -> Result < MomVecImpl < u64 , u32 > , Box < dyn Error > > {
142170 struct Op {
143171 depth : u8 ,
144172 threshold : f64 ,
173+ depth_threshold : Option < u8 > ,
145174 }
146175 impl HashItOperation for Op {
147176 type R = MomVecImpl < u64 , u32 > ;
@@ -157,16 +186,26 @@ fn build_count_mom_from_hash(
157186 }
158187 } ) ;
159188 let hash_count_it = SortedHash2HashCountIncludingZeroIt :: new_from_infallible ( self . depth , it) ;
160- let chi2_merger = new_chi2_count_merger ( self . threshold ) ;
161- MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
162- self . depth ,
163- hash_count_it,
164- chi2_merger,
165- )
189+ match self . depth_threshold {
190+ None => MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
191+ self . depth ,
192+ hash_count_it,
193+ new_chi2_count_merger_no_depth_threshold ( self . threshold ) ,
194+ ) ,
195+ Some ( depth_threshold) => MomVecImpl :: < u64 , u32 > :: from_hpx_sorted_entries_fallible (
196+ self . depth ,
197+ hash_count_it,
198+ new_chi2_count_merger_with_depth_threshold ( self . threshold , depth_threshold) ,
199+ ) ,
200+ }
166201 . map_err ( |e| e. into ( ) )
167202 }
168203 }
169- input. exec ( Op { depth, threshold } )
204+ input. exec ( Op {
205+ depth,
206+ threshold,
207+ depth_threshold,
208+ } )
170209}
171210
172211#[ derive( Debug , Subcommand ) ]
@@ -229,6 +268,9 @@ pub enum OpType {
229268 /// Completeness of the chi2 distribution of 3 degrees of freedom below which cells are post-merged.
230269 #[ clap( short, long, default_value_t = 16.266 ) ]
231270 threshold : f64 ,
271+ /// Depth threshold
272+ #[ clap( short = 't' , long, value_name = "DEPTH_MIN" ) ]
273+ depth_threshold : Option < u8 > ,
232274 } ,
233275}
234276
@@ -257,6 +299,7 @@ impl Operation {
257299 cte,
258300 value_name,
259301 threshold,
302+ depth_threshold,
260303 } => match ( l, r) {
261304 ( FITSMom :: U32U32 ( _l) , FITSMom :: U32U32 ( _r) ) => {
262305 Err ( String :: from ( "Method not available for integers" ) . into ( ) )
@@ -267,6 +310,7 @@ impl Operation {
267310 r. get_mom ( ) ,
268311 cte as f32 ,
269312 threshold,
313+ depth_threshold,
270314 )
271315 . to_fits_file ( self . output , value_name)
272316 . map_err ( |e| e. into ( ) )
@@ -277,6 +321,7 @@ impl Operation {
277321 r. get_mom ( ) ,
278322 cte,
279323 threshold,
324+ depth_threshold,
280325 )
281326 . to_fits_file ( self . output , value_name)
282327 . map_err ( |e| e. into ( ) )
@@ -290,6 +335,7 @@ impl Operation {
290335 r. get_mom ( ) ,
291336 cte as f32 ,
292337 threshold,
338+ depth_threshold,
293339 )
294340 . to_fits_file ( self . output , value_name)
295341 . map_err ( |e| e. into ( ) )
@@ -300,6 +346,7 @@ impl Operation {
300346 r. get_mom ( ) ,
301347 cte,
302348 threshold,
349+ depth_threshold,
303350 )
304351 . to_fits_file ( self . output , value_name)
305352 . map_err ( |e| e. into ( ) )
0 commit comments