Skip to content

Commit

Permalink
Fix clippy lints.
Browse files Browse the repository at this point in the history
Damn clippy is awesome.
  • Loading branch information
cjordan committed Mar 5, 2021
1 parent 39b502d commit fcd824f
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/coarse_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl CoarseChannel {
///
pub(crate) fn populate_coarse_channels(
corr_version: metafits_context::CorrelatorVersion,
metafits_coarse_chan_vec: &Vec<usize>,
metafits_coarse_chan_vec: &[usize],
metafits_coarse_chan_width_hz: u32,
gpubox_time_map: Option<&GpuboxTimeMap>,
voltage_time_map: Option<&VoltageFileTimeMap>,
Expand Down
181 changes: 89 additions & 92 deletions src/ffi/mod.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/gpubox_files/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Errors associated with reading in gpubox files.
use thiserror::Error;

#[derive(Error, Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum GpuboxError {
#[error("Invalid timestep index provided. The timestep index must be between 0 and {0}")]
InvalidTimeStepIndex(usize),
Expand Down
11 changes: 6 additions & 5 deletions src/gpubox_files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) struct ObsTimes {

/// This represents one group of gpubox files with the same "batch" identitifer.
/// e.g. obsid_datetime_chan_batch
#[allow(clippy::upper_case_acronyms)]
pub(crate) struct GPUBoxBatch {
pub batch_number: usize, // 00,01,02..n
pub gpubox_files: Vec<GPUBoxFile>, // Vector storing the details of each gpubox file in this batch
Expand All @@ -55,6 +56,7 @@ impl fmt::Debug for GPUBoxBatch {
}

/// This represents one gpubox file
#[allow(clippy::upper_case_acronyms)]
pub(crate) struct GPUBoxFile {
/// Filename of gpubox file
pub filename: String,
Expand Down Expand Up @@ -86,6 +88,7 @@ impl std::cmp::PartialEq for GPUBoxFile {

/// A temporary representation of a gpubox file
#[derive(Clone, Debug)]
#[allow(clippy::upper_case_acronyms)]
struct TempGPUBoxFile<'a> {
/// Filename of gpubox file
filename: &'a str,
Expand Down Expand Up @@ -158,9 +161,7 @@ pub(crate) struct GpuboxInfo {
/// * A Result containing a vector of `GPUBoxBatch`.
///
///
fn convert_temp_gpuboxes(
temp_gpuboxes: Vec<TempGPUBoxFile>,
) -> Result<Vec<GPUBoxBatch>, FitsError> {
fn convert_temp_gpuboxes(temp_gpuboxes: Vec<TempGPUBoxFile>) -> Vec<GPUBoxBatch> {
// unwrap is safe as a check is performed above to ensure that there are
// some files present.
let num_batches = temp_gpuboxes.iter().map(|g| g.batch_number).max().unwrap() + 1;
Expand All @@ -187,7 +188,7 @@ fn convert_temp_gpuboxes(
// Sort the batches by batch number
gpubox_batches.sort_by_key(|b| b.batch_number);

Ok(gpubox_batches)
gpubox_batches
}

/// This function unpacks the metadata associated with input gpubox files. The
Expand Down Expand Up @@ -233,7 +234,7 @@ pub(crate) fn examine_gpubox_files<T: AsRef<Path>>(

let time_map = create_time_map(&temp_gpuboxes, corr_format)?;

let mut batches = convert_temp_gpuboxes(temp_gpuboxes)?;
let mut batches = convert_temp_gpuboxes(temp_gpuboxes);

// Determine the size of each gpubox's image on HDU 1. mwalib will throw an
// error if this size is not consistent for all gpubox files.
Expand Down
4 changes: 2 additions & 2 deletions src/metafits_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl MetafitsContext {
mode,
corr_fine_chan_width_hz: fine_chan_width_hz,
corr_int_time_ms: integration_time_ms,
num_corr_fine_chans_per_coarse: num_corr_fine_chans_per_coarse,
num_corr_fine_chans_per_coarse,
receivers,
delays,
global_analogue_attenuation_db,
Expand All @@ -416,7 +416,7 @@ impl MetafitsContext {
num_coarse_chans: metafits_coarse_chan_vec.len(),
obs_bandwidth_hz: metafits_observation_bandwidth_hz,
coarse_chan_width_hz: metafits_coarse_chan_width_hz,
centre_freq_hz: centre_freq_hz,
centre_freq_hz,
metafits_filename: metafits
.as_ref()
.to_str()
Expand Down
2 changes: 2 additions & 0 deletions src/rfinput/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl fmt::Display for Pol {
}

/// Structure to hold one row of the metafits tiledata table
#[allow(clippy::upper_case_acronyms)]
struct RFInputMetafitsTableRow {
/// This is the ordinal index of the rf_input in the metafits file
input: u32,
Expand Down Expand Up @@ -151,6 +152,7 @@ struct RFInputMetafitsTableRow {

// Structure for storing MWA rf_chains (tile with polarisation) information from the metafits file
#[derive(Clone)]
#[allow(clippy::upper_case_acronyms)]
pub struct RFInput {
/// This is the metafits order (0-n inputs)
pub input: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/timestep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl TimeStep {
///
fn new(unix_time_ms: u64, gps_time_ms: u64) -> Self {
TimeStep {
unix_time_ms: unix_time_ms,
gps_time_ms: gps_time_ms,
unix_time_ms,
gps_time_ms,
}
}

Expand Down
29 changes: 14 additions & 15 deletions src/visibility_pol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ impl VisibilityPol {
/// * A populated vector of visibility polarisations for the MWA
///
pub(crate) fn populate_visibility_pols() -> Vec<Self> {
let mut pols: Vec<VisibilityPol> = Vec::with_capacity(4);
pols.push(VisibilityPol {
polarisation: String::from("XX"),
});
pols.push(VisibilityPol {
polarisation: String::from("XY"),
});
pols.push(VisibilityPol {
polarisation: String::from("YX"),
});
pols.push(VisibilityPol {
polarisation: String::from("YY"),
});

pols
vec![
VisibilityPol {
polarisation: String::from("XX"),
},
VisibilityPol {
polarisation: String::from("XY"),
},
VisibilityPol {
polarisation: String::from("YX"),
},
VisibilityPol {
polarisation: String::from("YY"),
},
]
}
}

Expand Down
36 changes: 16 additions & 20 deletions src/voltage_files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) struct VoltageFileInfo {
///
fn convert_temp_voltage_files(
temp_voltage_files: Vec<TempVoltageFile>,
) -> Result<HashMap<u64, VoltageFileBatch>, VoltageFileError> {
) -> HashMap<u64, VoltageFileBatch> {
// unwrap is safe as a check is performed above to ensure that there are
// some files present.
let batches = temp_voltage_files.iter().map(|g| g.gps_time);
Expand All @@ -187,11 +187,11 @@ fn convert_temp_voltage_files(

// Ensure the output is properly sorted - each batch is sorted by
// channel_identifier.
for (_, v) in &mut voltage_file_batches {
for v in voltage_file_batches.values_mut() {
v.voltage_files
.sort_unstable_by(|a, b| a.channel_identifier.cmp(&b.channel_identifier));
}
Ok(voltage_file_batches)
voltage_file_batches
}

/// Group input voltage files into gpstime_batches. A "voltage batch" refers to the sub_obs_id
Expand Down Expand Up @@ -313,13 +313,11 @@ fn determine_voltage_file_gpstime_batches<T: AsRef<Path>>(
for (_, (batch_num, num_files)) in batches_and_files.iter().enumerate() {
// Check that the previous batch + voltage_file_interval_seconds == the current batch number
// This is our contiguity check
if prev_batch_num != 0 {
if prev_batch_num + voltage_file_interval_seconds != *batch_num {
return Err(VoltageFileError::GpsTimeMissing {
expected: prev_batch_num + voltage_file_interval_seconds,
got: *batch_num,
});
}
if prev_batch_num != 0 && prev_batch_num + voltage_file_interval_seconds != *batch_num {
return Err(VoltageFileError::GpsTimeMissing {
expected: prev_batch_num + voltage_file_interval_seconds,
got: *batch_num,
});
}
prev_batch_num = *batch_num;

Expand Down Expand Up @@ -392,15 +390,15 @@ pub(crate) fn examine_voltage_files<T: AsRef<Path>>(
metafits_context.obs_id as usize,
)?;

let time_map = create_time_map(&temp_voltage_files)?;
let time_map = create_time_map(&temp_voltage_files);

let mut gpstime_batches: HashMap<u64, VoltageFileBatch> =
convert_temp_voltage_files(temp_voltage_files)?;
convert_temp_voltage_files(temp_voltage_files);

// Determine the size of each voltage file. mwalib will throw an
// error if this size is not consistent for all voltage files.
let mut voltage_file_size: Option<u64> = None;
for (_, b) in &mut gpstime_batches {
for b in gpstime_batches.values_mut() {
for v in &mut b.voltage_files {
let this_size;
let metadata = std::fs::metadata(&v.filename);
Expand All @@ -411,7 +409,7 @@ pub(crate) fn examine_voltage_files<T: AsRef<Path>>(
Err(e) => {
return Err(VoltageFileError::VoltageFileError(
(*v.filename).to_string(),
String::from(format!("{}", e)),
format!("{}", e),
));
}
};
Expand All @@ -437,7 +435,7 @@ pub(crate) fn examine_voltage_files<T: AsRef<Path>>(
corr_format,
time_map,
file_size: voltage_file_size.unwrap(),
voltage_file_interval_ms: voltage_file_interval_ms,
voltage_file_interval_ms,
})
}

Expand All @@ -455,20 +453,18 @@ pub(crate) fn examine_voltage_files<T: AsRef<Path>>(
/// * A Result containing the Voltage File Time Map or an error.
///
///
fn create_time_map(
voltage_file_batches: &[TempVoltageFile],
) -> Result<VoltageFileTimeMap, VoltageFileError> {
fn create_time_map(voltage_file_batches: &[TempVoltageFile]) -> VoltageFileTimeMap {
// create a map
let mut voltage_time_map = BTreeMap::new();
for voltage_file in voltage_file_batches.iter() {
voltage_time_map
.entry(voltage_file.gps_time)
.or_insert_with(BTreeMap::new)
.entry(voltage_file.channel_identifier)
.or_insert(voltage_file.filename.to_string());
.or_insert_with(|| voltage_file.filename.to_string());
}

Ok(voltage_time_map)
voltage_time_map
}

/// Determine the proper start and end times of an observation. In this context,
Expand Down
6 changes: 1 addition & 5 deletions src/voltage_files/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,11 @@ fn test_convert_temp_voltage_files() {
gps_time: 1234567000,
});

let result = convert_temp_voltage_files(temp_voltage_files);

// The resulting VoltageFileBatches should:
// * have 2 batches
// * batches sorted by gpstime
// * each batch sorted by coarse channel indentifier
assert!(result.is_ok());

let batches: HashMap<u64, VoltageFileBatch> = result.unwrap();
let batches: HashMap<u64, VoltageFileBatch> = convert_temp_voltage_files(temp_voltage_files);

assert_eq!(
batches.len(),
Expand Down

0 comments on commit fcd824f

Please sign in to comment.