Skip to content
Snippets Groups Projects
Commit bd0f675c authored by Stefano Covino's avatar Stefano Covino
Browse files

190524 commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 659 additions and 0 deletions
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
dist/*
Docs/*
Misc/*
Copyright (c) 2016 The Python Packaging Authority (PyPA)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Include the README
include ./README.md
# Include the license file
include ./LICENSE.txt
# Include the data files
recursive-include SRPFITS/Data/ *
# Include all python files
recursive-include . *.py
# Exclude MacOS files
recursive-exclude . .DS_Store
# Swift Reduction Package
The Swift Reduction Package (hereafter SRP) is a packet of command line tools to solve problems (e.g. basic reduction and analysis tasks of optical/NIR astronomical data, quick cosmological computations, units conversions, etc.) often met in astronomical research activities.
SRP was originally developed in the context of the Swift follow-up activities of the Milan GRB team at the INAF/Brera Astronomical Observatory. The package is designed to be an aid to any researcher to drive further observation of a followed-up GRB counterpart and “swift” can therefore be read simply as “rapid”, “agile”, etc.
This subpackage if the SRP suite is devoted to the management of NOT data.
Metadata-Version: 2.1
Name: SRPAstro.NOT
Version: 0.2.1
Summary: Tools for the NOT telescope under SRP
Home-page: https://pypi.python.org/pypi/SRPAstro.NOT
Author: Stefano Covino
Author-email: stefano.covino@inaf.it
License: UNKNOWN
Description: # Swift Reduction Package
Background
The Swift Reduction Package (hereafter SRP) is a packet of command line tools to solve problems (e.g. basic reduction and analysis tasks of optical/NIR astronomical data, quick cosmological computations, units conversions, etc.) often met in astronomical research activities.
SRP was originally developed in the context of the Swift follow-up activities of the Milan GRB team at the INAF/Brera Astronomical Observatory. The package is designed to be an aid to any researcher to drive further observation of a followed-up GRB counterpart and “swift” can therefore be read simply as “rapid”, “agile”, etc.
This subpackage if the SRP suite is devoted to the management of NOT data.
Keywords: astronomy data analysis
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Astronomy
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3
Description-Content-Type: text/markdown
LICENSE.txt
MANIFEST.in
README.md
setup.cfg
setup.py
./setup.py
./SRPNOT/GetNOTSite.py
./SRPNOT/GetObj.py
./SRPNOT/__init__.py
./SRPNOT/ALFOSC/AverHourAngle.py
./SRPNOT/ALFOSC/AverParallacticAngle.py
./SRPNOT/ALFOSC/MuellerOffsetMatrix.py
./SRPNOT/ALFOSC/StokesOffsetVector.py
./SRPNOT/ALFOSC/__init__.py
SRPAstro.NOT.egg-info/PKG-INFO
SRPAstro.NOT.egg-info/SOURCES.txt
SRPAstro.NOT.egg-info/dependency_links.txt
SRPAstro.NOT.egg-info/requires.txt
SRPAstro.NOT.egg-info/top_level.txt
SRPNOT/GetNOTSite.py
SRPNOT/GetObj.py
SRPNOT/__init__.py
SRPNOT/ALFOSC/AverHourAngle.py
SRPNOT/ALFOSC/AverParallacticAngle.py
SRPNOT/ALFOSC/MuellerOffsetMatrix.py
SRPNOT/ALFOSC/StokesOffsetVector.py
SRPNOT/ALFOSC/__init__.py
Scripts/SRPNOTALFOSCStokes
Scripts/SRPNOTALFOSCWeDoWoSourceMatch
Scripts/SRPNOTVersion
\ No newline at end of file
scipy>=0.11
SRPAstro.FITS>=2.3
SRPAstro
SRPNOT
""" Utility functions and classes for SRP
Context : SRP
Module : PAOLO.py
Version : 1.1.0
Author : Stefano Covino
Date : 20/09/2012
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks : site and object should be valid pyephem objects.
History : (21/02/2012) First version.
: (20/09/2012) Hour angles phased.
"""
import ephem, numpy
import math
from SRP.SRPMath.PhaseAngle import PhaseAngle
from SRP.SRPSky.HourAngle import HourAngle
def AverHourAngle (object,site,expt):
sequen = numpy.linspace(0.0,expt,math.ceil(expt))
orgdate = site.date
houa = []
for i in sequen:
site.date = orgdate + i*ephem.second
object.compute(site)
houa.append(PhaseAngle(HourAngle(math.degrees(float(object.a_ra)),site),-180.0,180.0))
return numpy.array(houa).sum()/len(sequen)
""" Utility functions and classes for SRP
Context : SRP
Module : PAOLO.py
Version : 1.0.0
Author : Stefano Covino
Date : 18/02/2012
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks : site and object should be valid pyephem objects.
History : (18/02/2012) First version.
"""
import ephem, numpy
import math
from SRP.SRPSky.ParallacticAngle import ParallacticAngle
def AverParallacticAngle (object,site,expt):
sequen = numpy.linspace(0.0,expt,math.ceil(expt))
orgdate = site.date
paran = []
for i in sequen:
site.date = orgdate + i*ephem.second
object.compute(site)
paran.append(ParallacticAngle(object,site))
return numpy.array(paran).sum()/len(sequen)
\ No newline at end of file
""" Utility functions and classes for SRP
Context : SRP
Module : Polarimetry
Version : 1.0.0
Author : Stefano Covino
Date : 21/02/2012
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks :
History : (21/02/2012) First version.
"""
import math
import numpy
def MuellerOffsetMatrix (q0=0.0, u0=0.0, v0=0.0):
r1 = [1., 0., 0., 0.]
r2 = [q0, 1., 0., 0.]
r3 = [u0, 0., 1., 0.]
r4 = [v0, 0., 0., 1.]
return numpy.matrix([r1, r2, r3, r4])
""" Utility functions and classes for SRP
Context : SRP
Module : Polarimetry
Version : 1.0.0
Author : Stefano Covino
Date : 21/02/2012
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks :
History : (21/02/2012) First version.
"""
import math
import numpy
def StokesOffsetVector (q0=0.0, u0=0.0, v0=0.0):
return numpy.matrix([0.0, q0, u0, v0]).transpose()
"""
Context : SRP
Module : NOT
Version : 1.0.0
Author : Stefano Covino
Date : 24/03/2014
E-mail : stefano.covino@brera.inaf.it
URL : http://www.me.oa-brera.inaf.it/utenti/covino
Usage : to be imported
Remarks :
History : (24/03/2014) First version.
"""
__all__ = ['AverHourAngle', 'AverParallacticAngle', 'MuellerOffsetMatrix', 'StokesOffsetVector']
# Columns and headers
eFlux = 'eFlux'
Flux = 'Flux'
TotFlux = 'TotFlux'
eTotFlux = 'eTotFlux'
eMag = 'eMag'
Mag = 'Mag'
TotMag = 'TotMag'
eTotMag = 'eTotMag'
Id = 'Id'
I = 'I'
eI = 'eI'
Q = 'Q'
eQ = 'eQ'
U = 'U'
eU = 'eU'
V = 'V'
eV = 'eV'
X = 'X'
Y = 'Y'
CalQ = 'CalQ'
eCalQ = 'eCalQ'
CalU = 'CalU'
eCalU = 'eCalU'
CalV = 'CalV'
eCalV = 'eCalV'
AZ = 'AZ'
ALT = 'ALT'
DATE = 'DATE'
EXPTIME = 'EXPTIME'
FILTER = 'FILTER'
GRISM = 'GRISM'
HOURANG = 'HOURANG'
OBJECT = 'OBJECT'
PARANG = 'PARANG'
POSANG = 'POSANG'
RA = 'RA'
DEC = 'DEC'
SEQUENCE = 'SEQUENCE'
TIME = 'TIME'
WAVE = 'WAVELEN'
MJD = 'MJD'
PLATE = 'PLATE'
PLANG = 'PLANG'
DEROT = 'DEROT'
#
tempfile = '_temp.fits'
#
quad1cut = '55 790 22 1210'
quad2cut = '55 935 55 1065'
quad3cut = '55 1070 55 925'
quad4cut = '55 1215 55 785'
framecut = '85 870 330 700'
#
XCORR = 'XCORR'
""" get NOT site information
Context : NOT
Module : NOT.py
Version : 1.0.0
Author : Stefano Covino
Date : 24/03/2014
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks :
History : (24/03/2014) First version.
"""
import ephem
import SRPNOT as SN
def GetNOTSite ():
site = ephem.Observer()
site.lat = str(SN.NOTLAT)
site.long = str(SN.NOTLONG)
site.elevation = SN.NOTHEIGHT
return site
""" get TNG site information
Context : NOT
Module : NOT.py
Version : 1.0.0
Author : Stefano Covino
Date : 24/03/2014
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Usage : to be imported
Remarks :
History : (24/03/2014) First version.
"""
import ephem
from SRP.SRPMath.AstroCoordInput import AstroCoordInput
def GetObj (ra,dec):
coord = AstroCoordInput(ra,dec)
nb = ephem.readdb('SRPNOTALFOSC Object,f|M|sp,'+str(ephem.hours(ephem.degrees(str(coord.RA))))+','+str(ephem.degrees(str(coord.DEC)))+',0,'+'2000')
return nb
\ No newline at end of file
"""
Context : SRP
Module : NOT
Version : 1.1.2.
Author : Stefano Covino
Date : 21/05/2021
E-mail : stefano.covino@brera.inaf.it
URL : http://www.me.oa-brera.inaf.it/utenti/covino
Usage : to be imported
Remarks :
History : (24/03/2014) First version.
: (22/05/2014) V. 0.1.0b2.
: (15/02/2017) Python3 porting.
: (19/04/2017) SRPFITS added.
"""
__version__ = '0.3.0'
__all__ = ['GetObj', 'GetNOTSite']
# TNG Dolores header keywords
EXPTIME = 'EXPTIME'
RA = 'RA'
DEC = 'DEC'
POSANG = 'FIELD'
AZ = 'AZIMUTH'
ALT = 'TELALT'
ROTPOS = 'ROTPOS'
LST = 'ST'
DATE = 'DATE-OBS'
FILTER = 'ALFLTNM'
GRISM = 'ALFGRNM'
OBJECT = 'OBJECT'
RETPLT = 'FARETARD'
RETANG = 'FARETANG'
# NOT filters
R = 'R_Bes 650_130'
ALFOSCFiltCentrWaveDict = {R : 0.650}
# Observatory location
NOTLAT = '28:45:26'
NOTLONG = '-17:53:06'
NOTHEIGHT = 2382.0
File added
File added
#! python
""" Code to derive instrumental Stokes parameters
Context : SRP
Module : SRPNOTALFOSCStokes
Author : Stefano Covino
Date : 19/04/2017
E-mail : stefano.covino@brera.inaf.it
URL: : http://www.merate.mi.astro.it/utenti/covino
Purpose : Derive instrumental Q and U Stokes parameters
Usage : SRPNOTALFOSCStokes [-h] [-a] [-c Q eQ U eU V eV] -f file -o file
[-v] [--version] [-w wave]
-a Append data to output
-c Calibration Q, U and V values
-f Input FITS photometry file
-o Output FITS file
-w Observation wavelength (micron)
History : (25/03/2014) First version.
: (22/05/2014) Minor bug in append.
: (15/02/2017) Python3 porting.
: (19/04/2017) SRPFITS added.
"""
__version__ = '1.0.3'
import argparse, math, os, sys, warnings
import atpy, ephem, numpy
import SRPNOT as SN
import SRPNOT.ALFOSC as SNA
from SRPNOT.ALFOSC.AverHourAngle import AverHourAngle
from SRPNOT.ALFOSC.AverParallacticAngle import AverParallacticAngle
from SRPNOT.GetObj import GetObj
from SRPNOT.GetNOTSite import GetNOTSite
from SRPFITS.Photometry.Mag2Counts import Mag2Counts
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--append", action="store_true", help="Append data to output")
parser.add_argument("-c", "--calibqu", action="store", type=float, nargs=6, help="Calibration Q, U and V values", metavar=('Q', 'eQ', 'U', 'eU', 'V', 'eV'))
parser.add_argument("-f", "--fitsphotfile", action="store", help="Input FITS photometry/spectroscopy file", required=True, metavar='file')
parser.add_argument("-o", "--outfile", action="store", help="Output FITS file", required=True, metavar='file')
parser.add_argument("-v", "--verbose", action="store_true", help="Fully describe operations")
parser.add_argument("--version", action="version", version=__version__)
parser.add_argument("-w", "--wave", action="store", type=float, help="Observation wavelength (micron)", metavar='wave')
options = parser.parse_args()
#
try:
tphot = atpy.Table(options.fitsphotfile, type='fits')
except IOError:
parser.error("Invalid input FITS file.")
if options.verbose:
print("Input FITS photometry file: %s" % options.fitsphotfile)
#
try:
sequence = tphot.keywords[SNA.SEQUENCE].split()
filter = tphot.keywords[SNA.FILTER]
ra = tphot.keywords[SNA.RA]
dec = tphot.keywords[SNA.DEC]
date = tphot.keywords[SNA.DATE]
time = tphot.keywords[SNA.TIME]
expt = tphot.keywords[SNA.EXPTIME]
posang = tphot.keywords[SNA.POSANG]
object = tphot.keywords[SNA.OBJECT]
plate = tphot.keywords[SNA.PLATE]
plang = tphot.keywords[SNA.PLANG]
mjd = tphot.keywords[SNA.MJD]
except Exception:
parser.error("Invalid data in FITS table.")
#
nospec = False
nophot = False
Fl = []
eFl = []
#
for ii in sequence:
try:
Fl.append(tphot[SNA.Flux+'_'+ii])
eFl.append(tphot[SNA.eFlux+'_'+ii])
nophot = True
except ValueError:
nospec = True
if nospec:
for ii in sequence:
try:
fl, efl = Mag2Counts(tphot[SNA.Mag+'_'+ii], tphot[SNA.eMag+'_'+ii])
nospec = True
except ValueError:
nophot = True
Fl.append(numpy.array(fl))
eFl.append(numpy.array(efl))
#
if nospec and nophot:
parser.error("Invalid columns %s,%s in FITS table" % (SNA.Mag+'_'+ii, SNA.eMag+'_'+ii))
#
warnings.resetwarnings()
warnings.filterwarnings('ignore', category=RuntimeWarning, append=True)
Q = (Fl[0]-Fl[2])/(Fl[0]+Fl[2])
U = (Fl[1]-Fl[3])/(Fl[1]+Fl[3])
eQ = numpy.fabs(Q) * numpy.sqrt( ((eFl[0]**2+eFl[2]**2)/(Fl[0]-Fl[2])**2) + ((eFl[0]**2+eFl[2]**2)/(Fl[0]+Fl[2])**2) )
eU = numpy.fabs(U) * numpy.sqrt( ((eFl[1]**2+eFl[3]**2)/(Fl[1]-Fl[3])**2) + ((eFl[1]**2+eFl[3]**2)/(Fl[1]+Fl[3])**2) )
warnings.resetwarnings()
warnings.filterwarnings('always', category=RuntimeWarning, append=True)
#
QNB = numpy.where(numpy.isnan(Q) | numpy.isinf(Q), False, True)
UNB = numpy.where(numpy.isnan(U) | numpy.isinf(U), False, True)
eQNB = numpy.where(numpy.isnan(eQ) | numpy.isinf(eQ), False, True)
eUNB = numpy.where(numpy.isnan(eU) | numpy.isinf(eU), False, True)
QUflag = numpy.where(QNB & eQNB & UNB & eUNB, True, False)
#
Qf = Q[QUflag]
Uf = U[QUflag]
eQf = eQ[QUflag]
eUf = eU[QUflag]
#
tnew = atpy.Table(name=options.outfile)
tnew.add_column(SNA.Id,tphot[SNA.Id+'_'+sequence[0]][QUflag], dtype=numpy.int16)
tnew.add_column(SNA.X,tphot[SNA.X+'_'+sequence[0]][QUflag], dtype=numpy.float32)
tnew.add_column(SNA.Y,tphot[SNA.Y+'_'+sequence[0]][QUflag], dtype=numpy.float32)
tnew.add_column(SNA.OBJECT,object, dtype=numpy.dtype('|S25'))
tnew.add_column(SNA.Q,Qf, dtype=numpy.float64)
tnew.add_column(SNA.eQ,eQf, dtype=numpy.float64)
tnew.add_column(SNA.U,Uf, dtype=numpy.float64)
tnew.add_column(SNA.eU,eUf, dtype=numpy.float64)
#tnew.add_column(SNA.V,0.0)
#tnew.add_column(SNA.eV,0.0)
tnew.add_column(SNA.PLATE,plate, dtype=numpy.dtype('|S10'))
tnew.add_column(SNA.PLANG,plang, dtype=numpy.float32)
tnew.add_column(SNA.MJD,mjd, dtype=numpy.float64)
if nospec:
tnew.add_column(SNA.TotMag,tphot[SNA.TotMag][QUflag], dtype=numpy.float32)
tnew.add_column(SNA.eTotMag,tphot[SNA.eTotMag][QUflag], dtype=numpy.float32)
elif nophot:
tnew.add_column(SNA.TotFlux,tphot[SNA.TotFlux][QUflag], dtype=numpy.float32)
tnew.add_column(SNA.eTotFlux,tphot[SNA.eTotFlux][QUflag], dtype=numpy.float32)
#
warnings.resetwarnings()
warnings.filterwarnings('ignore', category=DeprecationWarning, append=True)
site = GetNOTSite()
nb = GetObj(ra,dec)
site.date = ephem.Date(date+' '+time)
warnings.resetwarnings()
warnings.filterwarnings('always', category=DeprecationWarning, append=True)
#
hourangle = AverHourAngle(nb,site,expt)
tnew.add_column(SNA.HOURANG,numpy.array(len(Qf)*[hourangle]), dtype=numpy.float32)
if options.verbose:
print("Observation hour angle: %.1f" % hourangle)
#
parangle = AverParallacticAngle(nb,site,expt)
tnew.add_column(SNA.PARANG,numpy.array(len(Qf)*[parangle]), dtype=numpy.float32)
if options.verbose:
print("Observation parallactic Angle: %.1f" % parangle)
#
if nospec:
if options.wave:
wave = options.wave
else:
try:
wave = SN.ALFOSCFiltCentrWaveDict[filter]
except KeyError:
wave = 0.55
tnew.add_column(SNA.WAVE,numpy.array(len(Qf)*[wave]), dtype=numpy.float32)
elif nophot:
if options.wave:
wave = options.wave
else:
try:
wave = tphot[SNA.WAVE]*1e-4
except KeyError:
wave = 0.55
tnew.add_column(SNA.WAVE,wave[QUflag], dtype=numpy.float32)
if options.verbose:
if nospec:
print("Observation wavelength: %.3f" % wave)
elif nophot:
print("Observayion wavelength: spectral range")
#
tnew.add_column(SNA.POSANG,posang, dtype=numpy.float32)
if options.verbose:
print("Derotator offset: %.1f" % posang)
#
if options.verbose:
print("Plate : %s" % plate)
print("PosAngle : %s" % plang)
#
if options.calibqu:
tnew.add_column(SNA.CalQ,options.calibqu[0], dtype=numpy.float64)
tnew.add_column(SNA.eCalQ,options.calibqu[1], dtype=numpy.float64)
tnew.add_column(SNA.CalU,options.calibqu[2], dtype=numpy.float64)
tnew.add_column(SNA.eCalU,options.calibqu[3], dtype=numpy.float64)
tnew.add_column(SNA.CalV,options.calibqu[4], dtype=numpy.float64)
tnew.add_column(SNA.eCalV,options.calibqu[5], dtype=numpy.float64)
if options.verbose:
print("Calibrated Stokes parameters added.")
#
if options.append and os.path.exists(options.outfile):
tnew.write(SNA.tempfile,type='fits',overwrite=True)
tnew2 = atpy.Table(SNA.tempfile,type='fits')
os.remove(SNA.tempfile)
#
try:
tapp = atpy.Table(options.outfile, type='fits')
except IOError:
parser.error("Invalid FITS file to append.")
try:
tapp.append(tnew2)
except ValueError:
parser.error("Tables to be appended are not compatible.")
tapp.write(options.outfile,type='fits',overwrite=True)
else:
tnew.write(options.outfile,type='fits',overwrite=True)
#
if options.verbose:
print("%d (new) entries saved in file %s" % (len(tnew), options.outfile))
else:
print("%d %s" % (len(tnew), options.outfile))
#
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment