Skip to content

Commit

Permalink
Add method 'multiordermap_filter_mask_moc' in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Jul 4, 2024
1 parent 7619b57 commit f4bbcab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/storage/u64idx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::{
},
qty::{Frequency, Hpx, MocQty, Time},
storage::u64idx::op1::{
op1_mom_filter, op1_mom_sum, op1_mom_sum_from_data, op1_mom_sum_from_path,
op1_mom_filter, op1_mom_filter_mask, op1_mom_sum, op1_mom_sum_from_data, op1_mom_sum_from_path,
},
};

Expand Down Expand Up @@ -1849,6 +1849,25 @@ impl U64MocStore {
op1_mom_filter(index, mom_it)
}

/// Set to 'false' the booleans associated to the UNIQ HEALPix cells
/// intersecting (or fully covered) by the MOC of given index.
///
/// # Params
/// * `index`: index pf the S-MOC in the storage
/// * `it`: iterator on `uniq` HEALPix cells.
/// * `fully_covered_only`: set the boolean to false only if the cell is fully covered (else if it intersects)
pub fn multiordermap_filter_mask_moc<'a, I>(
&self,
index: usize,
it: I,
fully_covered_only: bool,
) -> Result<(), String>
where
I: Sized + Iterator<Item = (u64, &'a mut bool)>,
{
op1_mom_filter_mask(index, it, fully_covered_only)
}

/// Sum the value of the multi-order map in the given path which are in the given MOC.
/// Remark: we have no information and cannot make any guess on the order if te `UNIQ` cell
/// in the iterator.
Expand Down
37 changes: 36 additions & 1 deletion src/storage/u64idx/op1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub(crate) fn op1_mom_sum_from_data(index: usize, mom_data: &[u8]) -> Result<f64
})
}

/// Retuns the `(values, weights)` from the `values` of the input MOM which are in the MOC.
/// Returns the `(values, weights)` from the `values` of the input MOM which are in the MOC.
pub(crate) fn op1_mom_filter<I>(index: usize, it: I) -> Result<(Vec<f64>, Vec<f64>), String>
where
I: Sized + Iterator<Item = (u64, f64)>,
Expand All @@ -311,3 +311,38 @@ where
InternalMoc::TimeSpace(_) => Err(String::from("MOM Filter not implemented for ST-MOCs.")),
})
}

/// Set to 'false' the booleans associated to the UNIQ HEALPix cells
/// intersecting (or fully covered) by the MOC of given index.
/// # Params
/// * `fully_covered_only`: set the boolean to false only if the cell is fully covered (else if it intersects)
pub(crate) fn op1_mom_filter_mask<'a, I>(
index: usize,
it: I,
fully_covered_only: bool,
) -> Result<(), String>
where
I: Sized + Iterator<Item = (u64, &'a mut bool)>,
{
store::exec_on_one_readonly_moc(index, move |moc| match moc {
InternalMoc::Space(moc) => {
if fully_covered_only {
for (uniq, flag) in it {
let (depth, ipix) = Hpx::<u64>::from_uniq_hpx(uniq);
let cell_fraction = moc.cell_fraction(depth, ipix);
*flag = cell_fraction < 1.0;
}
} else {
for (uniq, flag) in it {
let (depth, ipix) = Hpx::<u64>::from_uniq_hpx(uniq);
let cell_fraction = moc.cell_fraction(depth, ipix);
*flag = cell_fraction == 0.0;
}
}
Ok(())
}
InternalMoc::Time(_) => Err(String::from("MOM Filter not implemented for T-MOCs.")),
InternalMoc::Frequency(_) => Err(String::from("MOM Filter not implemented for F-MOCs.")),
InternalMoc::TimeSpace(_) => Err(String::from("MOM Filter not implemented for ST-MOCs.")),
})
}

0 comments on commit f4bbcab

Please sign in to comment.