Skip to content

Commit

Permalink
Added prototype code for reading FITS data from S3
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel3834 committed Dec 13, 2024
1 parent 628aa05 commit 3903f26
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions prototypes/cloud_io_trial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Cloud IO Trial Code

# The purpose of this code is to prototype accessing data stored in AWS S3 buckets
# rather than local disk.
# This is based on the Astropy tutorial:
# https://docs.astropy.org/en/stable/io/fits/usage/cloud.html

from os import environ, path
from astropy.io import fits

# User AWS credentials need to be provided; for security these
# are served as environment variables
fsspec_kwargs = {"key": environ['AWS_SECRET_KEY_ID'],
"secret": environ['AWS_SECRET']}

# Load an image file
s3_uri = path.join(environ['AWS_BUCKET'],
'software', 'test_images', 'AT2024kwu_ip',
'tfn1m001-fa11-20240930-0341-e91.fits')
with fits.open(s3_uri, fsspec_kwargs=fsspec_kwargs) as hdul:

# Access the image header
print(hdul[0].header)

# Summarize the FITS extensions
for i,hdu in enumerate(hdul):
print('Extension ' + str(i) + ' ' + hdu.name)

# Show image data
print(hdul[0].data)

# Show source catalog
print(hdul[1].data)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ packages = []

[tool.poetry.dependencies]
python = "^3.9"
astropy = "7.0.0"
fsspec = "2024.10.0"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 3903f26

Please sign in to comment.