Skip to content

Commit

Permalink
Merge pull request #162 from wastjohn/main
Browse files Browse the repository at this point in the history
Testing collect_calibration_set, avg_fits, ccd_calib, and calib_images
  • Loading branch information
WWGolay authored Mar 2, 2024
2 parents aa2832a + 4b1673f commit 2eb2577
Show file tree
Hide file tree
Showing 310 changed files with 90,523 additions and 8,483 deletions.
95 changes: 58 additions & 37 deletions _tba/reduction/crop-image
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#! /usr/bin/env python

'''
"""
crop-image: Crops FITS images in place, according to user-specified boundaries, or 1/4 original (default)
FITS filename can be wild-carded e.g. *.fts in current directory
RLM 23 Oct 2014
3 Nov 2014: Check if WCS solution exists before changing CRPIX1,CRPIX2
'''
"""

import getopt
import os
Expand All @@ -16,61 +16,82 @@ import astropy.io.fits as pyfits


def usage():
print('Usage: crop-image [-X ] [-Y] [-W] [-H] [-v verbose] [-h = help] FITS_file[s]')
print(
"Usage: crop-image [-X ] [-Y] [-W] [-H] [-v verbose] [-h = help] FITS_file[s]"
)
sys.exit(1)


def help_usage():
print('crop-image crops FITS images in place, wildcard spec allowed')
print('(X,Y) lower left corner of crop, pixels')
print('W,H = width, height of cropped image, pixels')
print('Note: Defaults to inner 1/4 of image')
print('Warning: Crop is in place (overwrites original files)')
print('Example of usage: crop-image -X 100 -Y 100 -W 512 -H 512 *.fts')
print("crop-image crops FITS images in place, wildcard spec allowed")
print("(X,Y) lower left corner of crop, pixels")
print("W,H = width, height of cropped image, pixels")
print("Note: Defaults to inner 1/4 of image")
print("Warning: Crop is in place (overwrites original files)")
print("Example of usage: crop-image -X 100 -Y 100 -W 512 -H 512 *.fts")
sys.exit(1)


def getargs():
# retrieves filenames and optional arguments from command line
try:
opts, arg = getopt.getopt(sys.argv[1:], "X:Y:W:H:vh")
except getopt.GetoptError as err:
print(str(err)) # Prints "option -a not recognized"
print(str(err)) # Prints "option -a not recognized"
usage()
if len(arg) == 0: usage()
verbose = False; fnames = arg
if len(arg) == 0:
usage()
verbose = False
fnames = arg
X = Y = W = H = 0
for opt in opts:
if opt[0] in ('-v','--verbose'):
verbose = True
elif opt[0] in ('-X','--xstart'):
X = int(opt[1])
elif opt[0] in ('-Y','--xstop'):
Y = int(opt[1])
elif opt[0] in ('-W','--ystart'):
W = int(opt[1])
elif opt[0] in ('-H','--ystop'):
H = int(opt[1])
if opt[0] in ("-v", "--verbose"):
verbose = True
elif opt[0] in ("-X", "--xstart"):
X = int(opt[1])
elif opt[0] in ("-Y", "--xstop"):
Y = int(opt[1])
elif opt[0] in ("-W", "--ystart"):
W = int(opt[1])
elif opt[0] in ("-H", "--ystop"):
H = int(opt[1])
elif opt[0] in ("-h", "--help"):
help_usage()
return verbose, X, Y, W, H, fnames


# === MAIN ===
# get params
verbose, X, Y, W, H, fnames = getargs()

# crop images, overwrite original image, fixing CRPIX1 keywords
for fn in fnames:
if verbose: print('Cropping %s' % fn)
HDU = pyfits.open(fn)
Im = HDU[0].data; Header= HDU[0].header
if W == 0:
Nx = Header['NAXIS1']; Ny = Header['NAXIS2']
X = Nx/4; Y = Ny/4; W = Nx/2; H = Nx/2
X0 = X; Y0 = Y; X1 = X0 + W -1; Y1 = Y0 + H - 1
if verbose: print('X0 = %i, YX1 = %i, Y0 = %i Y1 = %i' % (X0,X1,Y0,Y1))
Im = Im[int(X0):int(X1), int(Y0):int(Y1)]
HDU[0].data=Im
HDU[0].scale('int16',bzero = 32768)
if 'CRPIX1' in Header: Header['CRPIX1'] -= X; Header['CRPIX2'] -= Y
Header['Comment'] = 'Cropped image using crop-image'
os.remove(fn); HDU.writeto(fn)
if verbose: print('Done')
if verbose:
print("Cropping %s" % fn)
HDU = pyfits.open(fn)
Im = HDU[0].data
Header = HDU[0].header
if W == 0:
Nx = Header["NAXIS1"]
Ny = Header["NAXIS2"]
X = Nx / 4
Y = Ny / 4
W = Nx / 2
H = Nx / 2
X0 = X
Y0 = Y
X1 = X0 + W - 1
Y1 = Y0 + H - 1
if verbose:
print("X0 = %i, YX1 = %i, Y0 = %i Y1 = %i" % (X0, X1, Y0, Y1))
Im = Im[int(X0) : int(X1), int(Y0) : int(Y1)]
HDU[0].data = Im
HDU[0].scale("int16", bzero=32768)
if "CRPIX1" in Header:
Header["CRPIX1"] -= X
Header["CRPIX2"] -= Y
Header["Comment"] = "Cropped image using crop-image"
os.remove(fn)
HDU.writeto(fn)
if verbose:
print("Done")
64 changes: 34 additions & 30 deletions _tba/reduction/sort-files
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,40 @@ import sys
import astropy.io.fits as pyfits

# make list of FITS file names in current directory
fnames = glob.glob('*.fts')
fnames = glob.glob("*.fts")

# Spin through files, renaming and putting into subfolders
for fname in fnames:

# Get info from FITS header
try:
hdr = pyfits.getheader(fname)
except:
print('Could not read %s, skipping' % fname)
continue
filter = hdr['FILTER']; source = hdr['OBJECT']
date,ut = hdr['DATE-OBS'].split('T'); ut = ut[:-3]

# Clean up source name if needed (no /'s, spaces)
source = source.replace(' ','') ; source = source.replace('/','_')
date = date.replace('-','_')
filter = filter[0]
# Remove colons from UT
ut = ut.replace(':','')
folder = '%s/%s' % (source,filter)

# Create subfolder named by object and filter
if not os.path.exists(source): os.mkdir(source)
if not os.path.exists(folder): os.mkdir(folder)

# Make new filename from date,ut,filter,focus strings
fnew_name = '%s_%s_%s_%s.fts' % (source,date,ut,filter)

# Move newly named file to appropriate subfolder
print('Moving %s => %s to subfolder %s' % (fname, fnew_name, folder))
fnew = folder + '/' + fnew_name
shutil.move(fname, fnew)
# Get info from FITS header
try:
hdr = pyfits.getheader(fname)
except:
print("Could not read %s, skipping" % fname)
continue
filter = hdr["FILTER"]
source = hdr["OBJECT"]
date, ut = hdr["DATE-OBS"].split("T")
ut = ut[:-3]

# Clean up source name if needed (no /'s, spaces)
source = source.replace(" ", "")
source = source.replace("/", "_")
date = date.replace("-", "_")
filter = filter[0]
# Remove colons from UT
ut = ut.replace(":", "")
folder = "%s/%s" % (source, filter)

# Create subfolder named by object and filter
if not os.path.exists(source):
os.mkdir(source)
if not os.path.exists(folder):
os.mkdir(folder)

# Make new filename from date,ut,filter,focus strings
fnew_name = "%s_%s_%s_%s.fts" % (source, date, ut, filter)

# Move newly named file to appropriate subfolder
print("Moving %s => %s to subfolder %s" % (fname, fnew_name, folder))
fnew = folder + "/" + fnew_name
shutil.move(fname, fnew)
111 changes: 76 additions & 35 deletions _tba/telrun/get-asassn
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,103 @@ import pandas as pd
import requests as rs

url = "https://docs.google.com/spreadsheets/d/1QdWCXJ0wRlNpTK0Ux4EfAybYJKKm9EXAa_wamQisajA/export?format=csv&id=1QdWCXJ0wRlNpTK0Ux4EfAybYJKKm9EXAa_wamQisajA&gid=0"
email = 'tyler-roth@uiowa.edu'
vers = '1.0'
email = "tyler-roth@uiowa.edu"
vers = "1.0"


def get_args():
global parser
parser = OptionParser(description='%prog creates a schedule file for ASAS-SN observations', version = vers)
parser.add_option('-f', dest = 'output_filename', metavar='Output File Name' , action = 'store', default = '', help = 'output file name')
return parser.parse_args()
global parser
parser = OptionParser(
description="%prog creates a schedule file for ASAS-SN observations",
version=vers,
)
parser.add_option(
"-f",
dest="output_filename",
metavar="Output File Name",
action="store",
default="",
help="output file name",
)
return parser.parse_args()


write_file = False
(opts, args) = get_args()
output_filename = opts.output_filename
if len(output_filename) > 0:
write_file = True
write_file = True

res=rs.get(url=url)
open('/tmp/asas-sn.csv', 'wb').write(res.content)
res = rs.get(url=url)
open("/tmp/asas-sn.csv", "wb").write(res.content)
if write_file:
output = open(output_filename,'wb')
output = open(output_filename, "wb")
if write_file:
output.write('Observer = "'+email+'"\n')
print(('Observer = "'+email+'"'))
output.write('Observer = "' + email + '"\n')
print(('Observer = "' + email + '"'))
if write_file:
output.write('epoch 2000\n')
print('epoch 2000')
output.write("epoch 2000\n")
print("epoch 2000")
if write_file:
output.write('\n')
print('')
output.write("\n")
print("")

df = pd.read_csv("/tmp/asas-sn.csv", header=2)

df = pd.read_csv('/tmp/asas-sn.csv',header=2)

def calc_exp(mag):
#calculate and return an exposure time based on magnitude
dur = 300 #replace this line
# calculate and return an exposure time based on magnitude
dur = 300 # replace this line
###code here###
return str(dur)


for index, row in df.iterrows():
if not isinstance(row['Object'],str):
if not isinstance(row["Object"], str):
continue
#if row['Active'] != 'TRUE':
#continue
#create string for duration
#needs to calculate exposure time based on magnitude from row['Last Mag']
duration = ''
for i in range(0,len(row['Filters'])):
duration += calc_exp(row['Last Mag']) + ','
#trim last comma
# if row['Active'] != 'TRUE':
# continue
# create string for duration
# needs to calculate exposure time based on magnitude from row['Last Mag']
duration = ""
for i in range(0, len(row["Filters"])):
duration += calc_exp(row["Last Mag"]) + ","
# trim last comma
duration = duration[:-1]
#create string for filters
filter = ''
for i in row['Filters']:
filter += i+','
#trim last comma
# create string for filters
filter = ""
for i in row["Filters"]:
filter += i + ","
# trim last comma
filter = filter[:-1]
print(('source '+row['Object']+ ' ra '+ row['RA']+ ' dec ' +row['Dec'] + ' filter ' + filter + ' dur ' + duration + ' /'))
print(
(
"source "
+ row["Object"]
+ " ra "
+ row["RA"]
+ " dec "
+ row["Dec"]
+ " filter "
+ filter
+ " dur "
+ duration
+ " /"
)
)
if write_file:
output.write('source '+row['Object']+ ' ra '+ row['RA']+ ' dec ' +row['Dec'] + ' filter ' + filter + ' dur ' + duration + ' /\n')
output.write(
"source "
+ row["Object"]
+ " ra "
+ row["RA"]
+ " dec "
+ row["Dec"]
+ " filter "
+ filter
+ " dur "
+ duration
+ " /\n"
)
if write_file:
output.close()
Loading

0 comments on commit 2eb2577

Please sign in to comment.