Skip to content

Commit

Permalink
Update Rust use directives style, apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtribick committed Dec 20, 2021
1 parent 9596e40 commit db04260
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 100 deletions.
4 changes: 3 additions & 1 deletion src/astro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{f64, hash::Hash, ops};
use std::f64;
use std::hash::Hash;
use std::ops;

use nalgebra::vector;

Expand Down
8 changes: 3 additions & 5 deletions src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
collections::HashMap,
io::{self, BufRead},
ops::Range,
};
use std::collections::HashMap;
use std::io::{self, BufRead};
use std::ops::Range;

pub struct CsvReader<B: BufRead> {
reader: B,
Expand Down
11 changes: 8 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{any::Any, borrow::Cow, error, fmt, io};

use pyo3::{exceptions::PyRuntimeError, PyErr};
use std::any::Any;
use std::borrow::Cow;
use std::error;
use std::fmt;
use std::io;

use pyo3::exceptions::PyRuntimeError;
use pyo3::PyErr;

use super::votable::DataType;

Expand Down
47 changes: 21 additions & 26 deletions src/hip2dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
fs::File,
io::{self, BufReader, BufWriter, ErrorKind, Write},
path::Path,
};
use std::fs::File;
use std::io::{self, BufReader, BufWriter, ErrorKind, Write};
use std::path::Path;

use crate::{astro::HipId, csv::CsvReader, error::AppError};
use crate::astro::HipId;
use crate::csv::CsvReader;
use crate::error::AppError;

mod distributions;
mod estimate;
Expand Down Expand Up @@ -55,26 +55,21 @@ struct DistanceInfo {
fn load_priors(path: impl AsRef<Path>) -> io::Result<Vec<PriorInfo>> {
let file = File::open(path)?;
let mut reader = CsvReader::new(BufReader::new(file))?;
let healpix_col = reader.index("healpix").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing healpix field",
))?;
let ggd_l_col = reader.index("GGDrlen").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing GGDrlen field",
))?;
let ggd_alpha_col = reader.index("GGDalpha").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing GGDalpha field",
))?;
let ggd_beta_col = reader.index("GGDbeta").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing field GGDbeta",
))?;
let edsd_length_col = reader.index("EDSDrlen").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing EDSDrlen field",
))?;
let healpix_col = reader
.index("healpix")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing healpix field"))?;
let ggd_l_col = reader
.index("GGDrlen")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing GGDrlen field"))?;
let ggd_alpha_col = reader
.index("GGDalpha")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing GGDalpha field"))?;
let ggd_beta_col = reader
.index("GGDbeta")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing field GGDbeta"))?;
let edsd_length_col = reader
.index("EDSDrlen")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing EDSDrlen field"))?;

let mut result = Vec::with_capacity(12288);
while reader.next()?.is_some() {
Expand Down
39 changes: 18 additions & 21 deletions src/hip2dist/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
f64::consts::FRAC_1_SQRT_2,
fs::File,
io::{self, BufRead, BufReader, ErrorKind},
path::Path,
sync::Arc,
thread::{self, JoinHandle},
};
use std::f64::consts::FRAC_1_SQRT_2;
use std::fs::File;
use std::io::{self, BufRead, BufReader, ErrorKind};
use std::path::Path;
use std::sync::Arc;
use std::thread::{self, JoinHandle};

use crossbeam_channel::{Receiver, Sender};
use lazy_static::lazy_static;
use rand::distributions::{Distribution, Uniform};
use statrs::{distribution::Normal, function::erf};

use super::{
distributions::{edsd_mode, geometric_posterior},
DistanceInfo, HipInfo, PriorInfo,
};
use crate::{astro::HipId, csv::CsvReader, error::AppError};
use super::distributions::{edsd_mode, geometric_posterior};
use super::{DistanceInfo, HipInfo, PriorInfo};

use crate::astro::HipId;
use crate::csv::CsvReader;
use crate::error::AppError;

const MCMC_SAMPLES: usize = 50000;
const BURN_IN_SAMPLES: usize = MCMC_SAMPLES / 10;
Expand Down Expand Up @@ -76,14 +75,12 @@ impl<B: BufRead + Send> Parser<B> {
let plx_col = reader
.index("Plx")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing Plx field"))?;
let e_plx_col = reader.index("e_Plx").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing e_Plx field",
))?;
let healpix_col = reader.index("healpix").ok_or_else(|| io::Error::new(
ErrorKind::InvalidData,
"Missing healpix field",
))?;
let e_plx_col = reader
.index("e_Plx")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing e_Plx field"))?;
let healpix_col = reader
.index("healpix")
.ok_or_else(|| io::Error::new(ErrorKind::InvalidData, "Missing healpix field"))?;
Ok(Self {
reader,
hip_col,
Expand Down
24 changes: 10 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
borrow::Cow,
collections::{hash_map::Entry, HashMap, HashSet},
fs::{read_dir, File},
iter::FromIterator,
path::{Path, PathBuf},
};
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::fs::{read_dir, File};
use std::iter::FromIterator;
use std::path::Path;

use flate2::{write::GzEncoder, Compression};
use globset::Glob;
Expand All @@ -37,13 +35,11 @@ mod hip2dist;
mod votable;
mod xmatch;

use crate::{
astro::{HipId, TycId},
error::AppError,
hip2dist::estimate_distances,
votable::VotableReader,
xmatch::Crossmatcher,
};
use crate::error::AppError;
use crate::hip2dist::estimate_distances;
use crate::tychip::load_tyc2hip;
use crate::votable::VotableReader;
use crate::xmatch::Crossmatcher;

const HIP_PATTERN: &str = "**/gaiaedr3-hip2-*.vot.gz";
const TYC_PATTERN: &str = "**/gaiaedr3-tyctdsc-*.vot.gz";
Expand Down
3 changes: 2 additions & 1 deletion src/votable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{fmt, num::NonZeroUsize};
use std::fmt;
use std::num::NonZeroUsize;

use super::error::AppError;

Expand Down
19 changes: 8 additions & 11 deletions src/votable/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
cmp,
collections::HashMap,
convert::TryInto,
io::{self, BufRead, BufReader, ErrorKind, Read},
mem,
};
use std::cmp;
use std::collections::HashMap;
use std::io::{self, BufRead, BufReader, ErrorKind, Read};
use std::mem;

use arrayvec::ArrayVec;
use bitvec::prelude::*;
use byteorder::{BigEndian, ReadBytesExt};
use flate2::read::GzDecoder;
use quick_xml::{
events::{attributes::Attributes, Event},
Reader as XmlReader,
};
use quick_xml::events::attributes::Attributes;
use quick_xml::events::Event;
use quick_xml::Reader as XmlReader;

use super::{DataType, VOTABLE_NS};

use crate::error::AppError;

fn parse_field(attributes: Attributes) -> Result<(Vec<u8>, DataType), AppError> {
Expand Down
15 changes: 6 additions & 9 deletions src/votable/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
cmp,
io::{self, ErrorKind, Write},
mem,
};
use std::cmp;
use std::io::{self, ErrorKind, Write};
use std::mem;

use bitvec::prelude::*;
use byteorder::{BigEndian, WriteBytesExt};
use quick_xml::{
events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event},
Writer,
};
use quick_xml::events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event};
use quick_xml::Writer;

use super::{FieldGetter, FieldInfo};

use crate::error::AppError;

pub struct VotableWriter<W: Write> {
Expand Down
15 changes: 6 additions & 9 deletions src/xmatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

use std::{
collections::{hash_map::Entry, HashMap},
io::{Read, Write},
};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::io::{Read, Write};

use lazy_static::lazy_static;

use crate::{
astro::{GaiaId, HipId, ProperMotion, SkyCoords, Squarable, TycId, MAS_TO_DEG},
error::AppError,
votable::{FieldInfo, RecordAccessor, VotableReader, VotableWriter},
};
use crate::astro::{GaiaId, HipId, ProperMotion, SkyCoords, Squarable, TycId, MAS_TO_DEG};
use crate::error::AppError;
use crate::votable::{FieldInfo, RecordAccessor, VotableReader, VotableWriter};

#[derive(Debug)]
struct GaiaOrdinals {
Expand Down

0 comments on commit db04260

Please sign in to comment.