#![warn(missing_docs)]
pub mod cache;
pub mod cloud_mask;
pub mod io;
pub mod masks;
pub mod products;
pub mod qvf;
pub mod query;
pub mod stac;
pub mod utils;
use lazy_static::lazy_static;
use utils::{ImageryProvider, ImageryProviderType, ImagerySource};
lazy_static! {
pub static ref DEA: ImagerySource = ImagerySource::Dea(ImageryProvider {
provider_type: ImageryProviderType::Stac,
url: "https://explorer.sandbox.dea.ga.gov.au/stac/search".to_owned()
});
pub static ref APOLLO: ImagerySource = ImagerySource::Apollo(ImageryProvider {
provider_type: ImageryProviderType::Local,
url: "/apollo".to_owned()
});
pub static ref ELEMENT84: ImagerySource = ImagerySource::Element(ImageryProvider {
provider_type: ImageryProviderType::Stac,
url: "https://earth-search.aws.element84.com/v1/search".to_owned()
});
pub static ref PLANETARYCOMPUTER: ImagerySource = ImagerySource::PlanetaryComputer(ImageryProvider {
provider_type: ImageryProviderType::Stac,
url: "https://planetarycomputer.microsoft.com/api/stac/v1/search".to_owned()
});
}
#[allow(missing_docs)]
mod registry_init {
use super::products::ProductRegistry;
use lazy_static::lazy_static;
lazy_static! {
pub static ref PRODUCT_REGISTRY: ProductRegistry = {
let manifest_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/data/products");
ProductRegistry::load_from_dir(manifest_dir).expect("Failed to load product manifests")
};
}
}
pub use registry_init::PRODUCT_REGISTRY;
#[cfg(test)]
mod tests {
use std::{path::PathBuf, str::FromStr};
use chrono::NaiveDate;
use crate::qvf::{
Collection, Extension, ImageType, Instrument, Product, QvfDate, QvfFields, QvfFilename,
QvfFilenames, Satellite,
};
#[test]
fn test_qvf_from_str() {
let name = "/scratch/rsc8/hardtkel/tmp/cfmsre_t56jmr_20220104_abam6.img";
let qvf = QvfFilename::from_str(name).unwrap();
println!("{qvf}");
}
#[test]
pub(crate) fn test_parse() {
let file = "cfmsre_t55kgs_20180531_abam5.img";
let qvfn = QvfFilename::from_str(file).expect("Could not parse the file name.");
let expected = QvfFilename {
satellite: Satellite::cf,
instrument: Instrument::ms,
product: Product::re,
scene: "t55kgs".to_string(),
date: QvfDate::Date(NaiveDate::parse_from_str("20180531", "%Y%m%d").unwrap()),
stage_code: "aba".to_string(),
zone: "m5".to_string(),
extension: Extension::img,
image_type: ImageType::Scene,
collection: Collection::Sentinel2,
location: Some(PathBuf::from("")),
extra_fields: None,
};
assert_eq!(qvfn, expected);
let file = "lztmre_p093r088_m202203202205_dimm4.img";
let _qvfn = QvfFilename::from_str(file).expect("Could not parse the file name.");
}
#[test]
fn test_change_sat() {
let file = "cfmsre_t55kgs_20180531_abam5.img";
let mut qvfn = QvfFilename::from_str(file).expect("Could not parse the file name.");
qvfn = qvfn.change_satellite(Satellite::l7);
let expected = QvfFilename {
satellite: Satellite::l7,
instrument: Instrument::ms,
product: Product::re,
scene: "t55kgs".to_string(),
date: QvfDate::Date(NaiveDate::parse_from_str("20180531", "%Y%m%d").unwrap()),
stage_code: "aba".to_string(),
zone: "m5".to_string(),
extension: Extension::img,
image_type: ImageType::Scene,
collection: Collection::Sentinel2,
location: Some(PathBuf::from("")),
extra_fields: None,
};
assert_eq!(qvfn, expected);
}
#[test]
fn test_change_inst() {
let file = "cfmsre_t55kgs_20180531_abam5.img";
let mut qvfn = QvfFilename::from_str(file).expect("Could not parse the file name.");
qvfn = qvfn.change_instrument(Instrument::tm);
let expected = QvfFilename {
satellite: Satellite::cf,
instrument: Instrument::tm,
product: Product::re,
scene: "t55kgs".to_string(),
date: QvfDate::Date(NaiveDate::parse_from_str("20180531", "%Y%m%d").unwrap()),
stage_code: "aba".to_string(),
zone: "m5".to_string(),
extension: Extension::img,
image_type: ImageType::Scene,
collection: Collection::Sentinel2,
location: Some(PathBuf::from("")),
extra_fields: None,
};
assert_eq!(qvfn, expected);
}
#[test]
fn test_sort_by_dates() {
let file_1 = QvfFilename::from_str("cfmsre_t55kgs_20180531_abam5.img").unwrap();
let file_2 = QvfFilename::from_str("cfmsre_t55kgs_20180528_abam5.img").unwrap();
let file_3 = QvfFilename::from_str("cfmsre_t55kgs_20170430_abam5.img").unwrap();
let mut qvfs = QvfFilenames {
qvf_filenames: vec![file_1, file_2, file_3],
};
qvfs.sort_by(QvfFields::Date);
let file_1 = QvfFilename::from_str("cfmsre_t55kgs_20180531_abam5.img").unwrap();
let file_2 = QvfFilename::from_str("cfmsre_t55kgs_20180528_abam5.img").unwrap();
let file_3 = QvfFilename::from_str("cfmsre_t55kgs_20170430_abam5.img").unwrap();
let expected = QvfFilenames {
qvf_filenames: vec![file_3, file_2, file_1],
};
assert_eq!(qvfs, expected);
}
#[test]
fn test_change_prod() {
let file = "cfmsre_t55kgs_20180531_abam5.img";
let mut qvfn = QvfFilename::from_str(file).expect("Could not parse the file name.");
qvfn = qvfn.change_product(Product::pa);
let expected = QvfFilename {
satellite: Satellite::cf,
instrument: Instrument::ms,
product: Product::pa,
scene: "t55kgs".to_string(),
date: QvfDate::Date(NaiveDate::parse_from_str("20180531", "%Y%m%d").unwrap()),
stage_code: "aba".to_string(),
zone: "m5".to_string(),
extension: Extension::img,
image_type: ImageType::Scene,
collection: Collection::Sentinel2,
location: Some(PathBuf::from("")),
extra_fields: None,
};
assert_eq!(qvfn, expected);
}
}