Last active
April 16, 2020 01:28
-
-
Save arfon/9b9ee93ff57e58cd9aef6169fecf8666 to your computer and use it in GitHub Desktop.
How to make TESS FITS cubes using Astrocut and MAST
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
# Author: Arfon Smith, Space Telescope Science Institute | |
# This script assumes the `s3://stpubdata` bucket is mounted at `/home/ubuntu/data` | |
# using the goofys tool (https://github.com/kahing/goofys) | |
import astroquery | |
from astrocut import CubeFactory | |
from astropy.io import fits | |
import numpy as np | |
import boto3 | |
import os | |
from astroquery.mast import Catalogs, Observations | |
# We (currently) have two sectors of data, there are four cameras, and four chips per-camera. | |
# We want to make files named e.g. tess-s0001-1-1-cube.fits | |
sectors = ['0001', '0002'] | |
cameras = [1,2,3,4] | |
chips = [1,2,3,4] | |
for sector in sectors: | |
for camera in cameras: | |
for chip in chips: | |
output_file = f"tess-s{sector}-{camera}-{chip}-cube.fits" | |
print(f"Working with {output_file}") | |
# Grab the observations from MAST for this given sector/camera/chip | |
obsTable = Observations.query_criteria(obs_id=f"tess-s{sector}-{camera}-{chip}") | |
# Next grab the products and filter for only the calibrated FFIs (FFIC files) | |
products = Observations.get_product_list(obsTable) | |
filtered = Observations.filter_products(products, | |
productSubGroupDescription="FFIC", | |
mrp_only=False) | |
# Turn on the S3 URLs | |
Observations.enable_cloud_dataset() | |
print(f"Grabbing S3 URLs for {output_file}") | |
s3_urls = Observations.get_cloud_uris(filtered) | |
input_files = [] | |
# Loop through each URL and replace the s3://stpubdata/ prefix with the local path to the directory | |
# mounted with goofys | |
for url in s3_urls: | |
local_file_path = url.replace("s3://stpubdata/", "/home/ubuntu/data/") | |
input_files.append(local_file_path) | |
# Initialize a CubeFactory and pass it the input files and the output filename | |
cuber = CubeFactory() | |
cube_file = cuber.make_cube(input_files, cube_file=output_file, sector=int(sector)) |
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
BSD 3-Clause License | |
Copyright (C) 2010-2018 Association of Universities for Research in Astronomy (AURA) | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, | |
this list of conditions and the following disclaimer in the documentation | |
and/or other materials provided with the distribution. | |
* Neither the name of the copyright holder nor the names of its | |
contributors may be used to endorse or promote products derived from | |
this software without specific prior written permission. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
# Launch a big instance (c5d.9xlarge) | |
# Give it ~2000GB of local storage. | |
# Start with Ubuntu 18.04 LTS (ami-0ac019f4fcb7cb7e6) | |
# Update and install software: | |
sudo apt update | |
sudo apt install python3-pip | |
sudo pip3 install scipy | |
sudo pip3 install numpy | |
sudo pip3 install astropy | |
sudo pip3 install boto3 | |
sudo pip3 install https://github.com/astropy/astroquery/archive/master.zip | |
sudo pip3 install https://github.com/spacetelescope/astrocut/archive/master.zip | |
# Set up the credentials file (this is needed by goofys and astroquery) | |
touch nano .aws/credentials | |
# This one will be picked up by Astroquery | |
[default] | |
aws_access_key_id = XXXXX | |
aws_secret_access_key = XXXXX | |
# Use this one at the end to write to the S3 stpubdata bucket with permission | |
[tess] | |
aws_access_key_id = XXXXX | |
aws_secret_access_key = XXXXX | |
Install goofys: https://gist.github.com/arfon/d93c788b4dcfd12029c8fb0d2fdeeb4c | |
# Make the files (using cube_maker.py) | |
# Finally copy the files to s3://stpubdata/tess/public/mast/... | |
# Finally regenerate the top level manifest.txt with `find . -type f > manifest.txt` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment