-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added prototype code for reading FITS data from S3
- Loading branch information
1 parent
628aa05
commit 3903f26
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters