Crates.io | astrors |
lib.rs | astrors |
version | 0.1.9 |
source | src |
created_at | 2020-07-17 13:54:22.361222 |
updated_at | 2024-10-24 01:54:25.688783 |
description | Astronomical package to deal with FITS (compressed also) and WCS, still in development. |
homepage | |
repository | https://github.com/schwarzam/astrors |
max_upload_size | |
id | 266240 |
size | 405,978 |
A package for astronomical image processing and analysis. We aim to provide a simple interface for common tasks like opening fits files, including images and tables.
This guide provides an overview of the astrors
library, a Rust-based tool for handling FITS files used in astronomical data. With astrors
, you can read, write, and manipulate FITS files, enabling efficient processing and analysis of astronomical datasets. This guide covers common use cases, including reading FITS files, writing data back to FITS format, and manipulating image and table data within FITS files.
Before you start, ensure you have Rust installed on your machine. You'll also need the astrors
. This guide assumes basic familiarity with Rust programming.
To use astrors
in your project, add it to your Cargo.toml
file:
[dependencies]
astrors = ""
To read a FITS file and access its HDUs (Header/Data Units), you can use the following approach:
use astrors::fits;
let testfile = common::get_testdata_path("your_file.fits");
let mut hdu_list = fits::fromfile(testfile.to_str().unwrap()).unwrap();
println!("HDU List Length: {:?}", hdu_list.hdus.len());
This code snippet opens a FITS file, reads its contents into an HDUList
structure, and prints the number of HDUs found in the file.
After reading and optionally modifying HDUs, you can write them back to a new FITS file:
let outfile = common::get_outtestdata_path("modified_file.fits");
hdu_list.write_to(outfile.to_str().unwrap()).unwrap();
To read the primary HDU, modify its data, and write it back to a file:
use astrors::io::hdus::primaryhdu::PrimaryHDU;
use std::fs::File;
use ndarray::ArrayD;
use astrors::io::hdulist::HDUList;
use astrors::io::hdus::image::ImageData;
use ndarray::IxDyn;
let testfile = common::get_testdata_path("your_primary_hdu_file.fits");
let mut f: File = File::open(testfile)?;
let mut primary_hdu = PrimaryHDU::read_from_file(&mut f)?;
// Modify the primary HDU's data
primary_hdu.data = ImageData::F32(ArrayD::from_elem(IxDyn(&[100, 100]), 1.0));
// Write the modified primary HDU to a new file
let outfile = common::get_outtestdata_path("modified_primary_hdu.fits");
let mut f_out: File = File::create(outfile)?;
let mut hdus = HDUList::new();
hdus.add_hdu(HDU::Primary(primary_hdu));
hdus.write_to(outfile.to_str().unwrap())?;
To create a binary table HDU from a DataFrame
and add it to an HDUList
:
use polars::prelude::*;
use astrors::io::hdus::bintable::bintablehdu::BinTableHDU;
let df = DataFrame::new(vec![
Series::new("RA", vec![1, 2, 3, 4, 5]),
Series::new("DEC", vec![1, 2, 3, 4, 5]),
Series::new("MAG", vec![1, 2, 3, 4, 5]),
]).unwrap();
let mut bintable = BinTableHDU::new_data(df);
hdus.add_hdu(HDU::BinTable(bintable));
This snippet creates a DataFrame
with astronomical data, converts it to a binary table HDU, and adds it to an HDUList
for writing to a FITS file.
We welcome contributions from the community to help further develop and improve this library. Whether you're fixing bugs, adding new features, or improving documentation, your help is invaluable. Please feel free to submit pull requests or open issues on our GitHub repository. For major changes, please open an issue first to discuss what you would like to change.
If you find this library useful and would like to support its development, consider sponsoring the project. Your sponsorship can help with the maintenance of the project, the development of new features, and the improvement of the existing ones. For more information on how to sponsor, please visit our GitHub repository or contact us directly.
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details. The BSD 3-Clause License is a permissive license that allows for redistribution and use in source and binary forms, with or without modification, under certain conditions. This license is business-friendly and compatible with open source and commercial projects.