Skip to main content

A package for managing astronomical data through a uniform interface

Project description

astrodata

Tests

A badge displaying the testing coverage percentage of this repository. Testing status badge

Building & Publishing

Documentation build status badge PyPI version badge pypi packaging status badge


Making astronomical data consistent and approachable

astrodata is a package for managing astronomical data through a uniform interface. It is designed to be used with the Astropy package. astrodata was designed by and for use as part of the DRAGONS data reduction pipeline, but it is now implemented to be useful for any astronomical data reduction or analysis project.

Unlike managing files using the astropy.io.fits package alone, astrodata is designed to be extendible to any data format, and to parse, respond to, and store metadata in a consistent, intentional way. This makes it especially useful for managing data from multiple instruments, telescopes, and data generation utilities.

Note: If you are trying to reduce Gemini data, please use DRAGONS. Interaction with this package directly is primarily suited for developers, and does not come with any tools for data reduction on any specific instrument or data.

Installation

astrodata is available on the Python Package Index and can be installed using pip:

pip install astrodata

Documentation

Documentation for astrodata is available on our GitHub pages site. This documentation includes a user and programmer's guide, as well as a full API reference.

Usage

The most basic usage of astrodata is to extend the astrodata.AstroData class, which includes some basic FITS file handling methods by default:

from astrodata import AstroData, astro_data_descriptor, factory, from_file


class MyData(AstroData):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @astro_data_descriptor
    def color(self):
        # The color filter used for our image is stored in a few different
        # ways, let's unify them.
        blue_labels = {"blue", "bl", "b"}
        green_labels = {"green", "gr", "g"}
        red_labels = {"red", "re", "r"}

        header_value = self.phu.get("COLOR", None).casefold()

        if header_value in blue_labels:
            return "BLUE"

        if header_value in green_labels:
            return "GREEN"

        if header_value in red_labels:
            return "RED"

        if header_value is None:
            raise ValueError("No color found")

        # Unrecognized color
        raise ValueError(f"Did not recognize COLOR value: {header_value}")


# Now, define our instruments with nuanced, individual data formats
class MyInstrument1(MyData):
    # These use a special method to resolve the metadata and apply the correct
    # class.
    @staticmethod
    def _matches_data(source):
        return source[0].header.get("INSTRUME", "").upper() == "MYINSTRUMENT1"


class MyInstrument2(MyData):
    @staticmethod
    def _matches_data(source):
        return source[0].header.get("INSTRUME", "").upper() == "MYINSTRUMENT2"


class MyInstrument3(MyData):
    @staticmethod
    def _matches_data(source):
        return source[0].header.get("INSTRUME", "").upper() == "MYINSTRUMENT3"


for cls in [MyInstrument1, MyInstrument2, MyInstrument3]:
    factory.add_class(cls)

# my_file.fits has some color data depending on the instrument it comes from,
# but now we can access it and handle a single value.
data = from_file("README_example.fits")

# the astrodata factory has already resolved the correct class for us.
print(f"File used to create class: {data.__class__.__name__}")
if data.color() == "BLUE":
    print("I used the blue filter!")

else:
    print("I used a red or green filter!")

# Get all the info about the astrodata object.
data.info()

This will print out the filter used as extracted from the header of the FITS file. data.info() offers a more complete look at the file's data including the filename and path of the file (as it does for astropy.io.fits objects).

astrodata is designed to be extensible, so you can add your own methods to analyze and process data based on your specific needs and use cases.

For a complete example, see the Quickstart in our documentation.

Installing development dependencies

astrodata uses Poetry for build and package management. To install development dependencies, you must clone this repository. Once you have, at the top level directory of the astrodata repository run

pip install --upgrade pip
pip install poetry
poetry install

# To install without specific development groups. Omit those you would prefer
# not be installed
poetry install --without test,docs,dev

Contributing

See our contributing guidelines for information on contributing. If you're worried about contributing, or feel intimidated, please remember that your contribution is immensly appreciated---no matter how small!

License

This project is Copyright 2024 (c) and licensed under the terms of a modified BSD 3-clause license through AURA astronomy. This package is based upon the Openastronomy packaging guide which is licensed under the standard BSD 3-clause licence. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astrodata-2.9.2.tar.gz (65.9 kB view details)

Uploaded Source

Built Distribution

astrodata-2.9.2-py3-none-any.whl (68.2 kB view details)

Uploaded Python 3

File details

Details for the file astrodata-2.9.2.tar.gz.

File metadata

  • Download URL: astrodata-2.9.2.tar.gz
  • Upload date:
  • Size: 65.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1018-azure

File hashes

Hashes for astrodata-2.9.2.tar.gz
Algorithm Hash digest
SHA256 5277c83f7fda5581b442c560b0a1ef5c45f132b154451ab50f089873988ade0c
MD5 d2aac3ca587e494d581d5e57f20b12d3
BLAKE2b-256 ddb6fa5a177a4dd3d72270b1ebbf8bb44870b50358d16c2999015edd7d93255f

See more details on using hashes here.

File details

Details for the file astrodata-2.9.2-py3-none-any.whl.

File metadata

  • Download URL: astrodata-2.9.2-py3-none-any.whl
  • Upload date:
  • Size: 68.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1018-azure

File hashes

Hashes for astrodata-2.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6a59ff1137964bf5644559cf53a42e3679f0cc2248e0d35d9f2252c42c15d0dd
MD5 0c8f92f758374ad6d11e11f13e4986ce
BLAKE2b-256 95fa696e249a70fca8137ca6558d8b581bcacc43193d58e36ca034a60773a05e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page