nifits.io package¶
Submodules¶
nifits.io.oifits module¶
A module for reading/writing NIFITS files and handling the data.
To open an existing NIFITS file, use nifits.from_nifits
constructor.
To save an NIFITS object to a file, use nifits.to_nifits
method.
A summary of the information in the oifits object can be obtained by using the info() method:
> import oifits > oifitsobj = oifits.open(‘foo.fits’) > oifitsobj.info()
For further information, contact R. Laugier
- class nifits.io.oifits.NI_CATM(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION_CPX_ARRAY
The complex amplitude transfre function
Generic class for NIFITS array extensions.
The array is kept locally as complex valued, but it is stored to and loaded from a real-valued array with an extra first dimension of length 2 for (real, imaginary) parts.
- property M¶
- name = 'NI_CATM'¶
- class nifits.io.oifits.NI_DSAMP(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION_ARRAY
The matrix that defines linear combinations of output wavelengths. It is meant to be used to down-sample the wavelengths of the forward model. The number of columns should match the number of channels described by
NI_OSWAVELENGTH
and the number of rows should match the number of channels described in OI_WAVELENGTH.If
NI_DSAMP
orNI_OSWAVELENGTH
are missing, then assume the identity matrix and possibly skip the computation step.The linear combination is defined by a real-valued matrix. It is recommended that the matrix be semi-unitary on the left, so that a flux conservation is observed, and both input and outputs can be described in the same units.
Generic class for NIFITS array extensions
- Parameters:
data_array (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property D¶
- name = 'NI_DSAMP'¶
- class nifits.io.oifits.NI_EXTENSION(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
object
NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table (
Table
) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
-
data_table:
Table
¶
- classmethod from_hdu(hdu)[source]¶
Create the data object from the HDU extension of an opened fits file.
- Parameters:
hdu (
type
) – TableHDU object containing the relevant data
-
header:
Header
¶
-
unit:
Unit
= None¶
- class nifits.io.oifits.NI_EXTENSION_ARRAY(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION
Generic class for NIFITS array extensions
- Parameters:
data_array (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
-
data_array:
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]¶
- classmethod from_hdu(hdu)[source]¶
Create the data object from the HDU extension of an opened fits file.
-
header:
Header
¶
- property shape¶
- to_hdu()[source]¶
Returns and hdu object to save into fits
Note
This also updates the header if dimension changes
-
unit:
Unit
= None¶
- class nifits.io.oifits.NI_EXTENSION_CPX_ARRAY(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION
Generic class for NIFITS array extensions.
The array is kept locally as complex valued, but it is stored to and loaded from a real-valued array with an extra first dimension of length 2 for (real, imaginary) parts.
-
data_array:
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]¶
- classmethod from_hdu(hdu)[source]¶
Create the data object from the HDU extension of an opened fits file.
-
header:
Header
¶
- property shape¶
-
data_array:
- class nifits.io.oifits.NI_FOV(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
The
NI_FOV
data containing information of the field of view (vigneting) function as a function of wavelength.This can be interpreted in different ways depending on the value of the header keyword
NIFITS FOV_MODE
.diameter_gaussian_radial
: A simple gaussian radial falloff function based on a size of \(\lambda/D\) and a chromatic offset defined for each spectral bin. Thesimple_from_header()
constructor can help create a simple extension with 0 offset.More options will come.
NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table (
Table
) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- get_fov_function(lamb, n)[source]¶
Returns the function to get the chromatic phasor given by injection for a the index n of the time series
This method will move to the backend
- Parameters:
lamb (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – The array of wavelength bins [m]n (
int
) – The index of the time series to compute for
- name = 'NI_FOV'¶
- classmethod simple_from_header(header=None, lamb=None, n=0)[source]¶
Constructor for a simple
NIFITS NI_FOV
object with chromatic gaussian profile and no offset.- Parameters:
header – (astropy.io.fits.Header) Header containing the required information such as
NIFITS FOV_TELDIAM
andNIFITS FOV_TELDIAM_UNIT
which are used to create the gaussian profiles of radius \(\lambda/D\)
- nifits.io.oifits.NI_FOV_DEFAULT_HEADER = HIERARCH NIFITS FOV_MODE = 'diameter_gaussian_radial' / Type of FOV definition HIERARCH NIFITS FOV_offset = HIERARCH NIFITS FOV_TELDIAM = 8.0 / diameter of a collecting aperture for FOV HIERARCH NIFITS FOV_TELDIAM_UNIT = 'm ' HIERARCH NIFITS WL_SHIFT_MODE = '' ¶
Obtaining the goecentric location of observatories. (unchecked)
`python from astroplan import Observer import astropy.coordinates as coords myobs = Observer.at_site("CHARA") print([acoord.value for acoord in myobs.location.to_geocentric()]) `
VLTI: 1946404.3410388362, -5467644.290798524, -2642728.2014442487 CHARA: -2484228.6029109913, -4660044.467216573, 3567867.961141405
- class nifits.io.oifits.NI_IOTAGS(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
Contains information on the inputs and outputs.
-
data_table:
Table
¶
-
header:
Header
¶
- property inpola¶
The polarization of inputs.
- name = 'NI_MOD'¶
- property outbright¶
The flags of photometric outputs
- property outdark¶
The flags of dark outputs
- property outpola¶
The polarization of outputs.
-
data_table:
- class nifits.io.oifits.NI_IOUT(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
NI_IOUT
: a recording of the output values, given in intensity, flux, counts or arbitrary units. Providing unit is mandatory since 0.2.NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table (
Table
) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property iout¶
- name = 'NI_IOUT'¶
- class nifits.io.oifits.NI_KCOV(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION_ARRAY
- The covariance matrix for the processed data contained in KIOUT.
Providing unit is mandatory since 0.2. The unit should be
the unit of NI_KIOUT ^2.
Generic class for NIFITS array extensions
- Parameters:
data_array (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property kcov¶
- name = 'NI_KCOV'¶
-
unit:
Unit
= Unit("ph2 / s2")¶
- class nifits.io.oifits.NI_KIOUT(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
NI_KIOUT
: a recording of the processed output values using the the post-processing matrix given byNI_KMAT
. Typically differential null or kernel-null. Providing unit is mandatory since 0.2. The unit should match NI_IOUT.Generic class for NIFITS array extensions
- Parameters:
data_array – [ArrayLike] The data to stored
header (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property kiout¶
- name = 'NI_KIOUT'¶
- property shape¶
-
unit:
Unit
= Unit("ph / s")¶
- class nifits.io.oifits.NI_KMAT(data_table=<factory>, header=<factory>, unit=None, data_array=<factory>)[source]¶
Bases:
NI_EXTENSION_ARRAY
The kernel matrix that defines the post-processing operation between outputs. The linear combination is defined by a real-valued matrix.
Generic class for NIFITS array extensions
- Parameters:
data_array (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property K¶
- name = 'NI_KMAT'¶
- class nifits.io.oifits.NI_MOD(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
Contains input modulation vector for the given observation. The format is a complex phasor representing the alteration applied by the instrument to the light at its inputs. Either an intended modulation, or an estimated instrumental error. the dimenstions are (n_ch, n_in)
The effects modeled in NI_MOD must cumulate with some that may be modeled in NI_CATM. It is recommended to include in CATM the static effects and in NI_MOD any affect that may vary throughout the observµng run.
\(n_a \times \lambda\)
information.
Item
format
unit
comment
APP_INDEX
int
NA
Indices of subaperture (starts at 0)
TARGET_ID
int
d
Index of target in
OI_TARGET
TIME
float
s
Backwards compatibility
MJD
float
day
INT_TIME
float
s
Exposure time
MOD_PHAS
n_{wl},n_a
float
Complex phasor of modulation for all collectors
APPXY
n_a,2
float
m
Projected location of subapertures in the plane orthogonal to the line of sight and oriented as
( \alpha, \delta)
ARRCOL
n_a
float
\mathrm{m}^2
Collecting area of the subaperture
FOV_INDEX
n_a
int
NA
The entry of the
NI_FOV
to use for this subaperture.- property all_phasors¶
- property appxy¶
Shape n_frames x n_a x 2
- property arrcol¶
The collecting area of the telescopes
-
data_table:
Table
¶
- property dateobs¶
Get the dateobs from the weighted mean of the observation time from each of the observation times given in the rows of
NI_MOD
table.
-
header:
Header
¶
- property int_time¶
Conveniently retrieve the integration time.
- property n_series¶
- name = 'NI_MOD'¶
- class nifits.io.oifits.NI_OSWAVELENGTH(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
An object storing the wavelength before a downsampling. This must have the wavelength for each of the slice of the CATM matrix, each of the
NI_MOD
phasors and each column of theNI_DSAMP
matrix.If
NI_OOSWAVELENGTH
is absent, assume that there is no over or down- sampling and take the values directly fromOI_WAVELENGTH
.Shorthands:
self.lambs
:ArrayLike
[m] returns an array containing the center of each spectral channel.self.dlmabs
:ArrayLike
[m] an array containing the spectral bin widths.self.nus
:ArrayLike
[Hz] an array containing central frequencies of the spectral channels.self.dnus
:ArrayLike
[Hz] an array containing the frequency bin widths.
NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table (
Table
) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property dlambs¶
- property dnus¶
- property lambs¶
- name = 'OI_WAVELENGTH'¶
- property nus¶
- class nifits.io.oifits.OI_ARRAY(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
OI_ARRAY
definition- Parameters:
data_table (
Table
) – The data to holdheader (
Header
) – The associated fits header
NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table – [ArrayLike] The data to stored
header – [fits.Header] A fits header (optional)
unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- name = 'OI_ARRAY'¶
- class nifits.io.oifits.OI_STATION(tel_name=None, sta_name=None, diameter=None, staxyz=[None, None, None], fov=None, fovtype=None, revision=1)[source]¶
Bases:
object
This class corresponds to a single row (i.e. single station/telescope) of an OI_ARRAY table.
- class nifits.io.oifits.OI_TARGET(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
OI_TARGET
definition.- add_target(target_id=0, target='MyTarget', raep0=0.0, decep0=0.0, equinox=0.0, ra_err=0.0, dec_err=0.0, sysvel=0.0, veltyp='', veldef='', pmra=0.0, pmdec=0.0, pmra_err=0.0, pmdec_err=0.0, parallax=0.0, para_err=0.0, spectyp='', category='')[source]¶
Use this method to add a row to the table of targets
- Parameters:
target_id (param) – (default: 0)
target – (default: “MyTarget”)
raep0 – (default: 0.)
decep0 – (default: 0.)
equinox – (default: 0.)
ra_err – (default: 0.)
dec_err – (default: 0.)
sysvel – (default: 0.)
veltyp – (default: “”)
veldef – (default: “”)
pmra – (default: 0.)
pmdec – (default: 0.)
pmra_err – (default: 0.)
pmdec_err – (default: 0.)
parallax – (default: 0.)
para_err – (default: 0.)
spectyp – (default: “”)
category – (default: “”)
- classmethod from_scratch()[source]¶
Creates the OI_TARGET object with an empty table.
- **Returns:
OI_TARGET: object with an empty table.
Use
add_target()
to finish the job.
- name = 'OI_TARGET'¶
- class nifits.io.oifits.OI_WAVELENGTH(data_table=<factory>, header=<factory>, unit=None)[source]¶
Bases:
NI_EXTENSION
An object storing the OI_WAVELENGTH information, in compatibility with OIFITS practices.
Shorthands:
self.lambs
:ArrayLike
[m] returns an array containing the center of each spectral channel.self.dlmabs
:ArrayLike
[m] an array containing the spectral bin widths.self.nus
:ArrayLike
[Hz] an array containing central frequencies of the spectral channels.self.dnus
:ArrayLike
[Hz] an array containing the frequency bin widths.
NI_EXTENSION
Generic class for NIFITS extensionsInherited methods:
from_hdu
: Creates the object from anastropy.io.fits.TableHDU
objectto_hdu
: Returns theTableHDU
from itself.
- Parameters:
data_table (
Table
) – [ArrayLike] The data to storedheader (
Header
) – [fits.Header] A fits header (optional)unit (
Unit
) – [astropy.units.Unit] Units of the data stored (mandatory of NI_IOUT, NI_KIOUT and NI_KCOV)
- property dlambs¶
- property dnus¶
- property lambs¶
- name = 'OI_WAVELENGTH'¶
- property nus¶
- nifits.io.oifits.array_eq(a, b)[source]¶
Test whether all the elements of two arrays are equal.
- Parameters:
a (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – one input.b (
Union
[Buffer
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – another input.
- nifits.io.oifits.check_item(func)[source]¶
A decorator for the fits.Header.__getitem__. This is here to save from compatibility issues with files of standard version <= 0.2 while warning that that this version will
- nifits.io.oifits.create_basic_fov_data(D, offset, lamb, n)[source]¶
A convenience function to help define the FOV function and data model
- class nifits.io.oifits.nifits(header=None, oi_array=None, ni_catm=None, ni_fov=None, ni_kmat=None, oi_wavelength=None, oi_target=None, ni_mod=None, ni_iout=None, ni_kiout=None, ni_kcov=None, ni_dsamp=None, ni_oswavelength=None, ni_iotags=None)[source]¶
Bases:
object
Class representation of the nifits object.
- check_unit_coherence()[source]¶
Check the coherence of the units of and prints the result
NI_IOUT, NI_KCOV, and NI_KIOUT if they exist.
Otherwise, does nothing.
- classmethod from_nifits(filename)[source]¶
Create the nifits object from the HDU extension of an opened fits file.
-
header:
Header
= None¶
-
ni_oswavelength:
NI_OSWAVELENGTH
= None¶
-
oi_wavelength:
OI_WAVELENGTH
= None¶
- to_nifits(filename='', static_only=False, dynamic_only=False, static_hash='', writefile=True, overwrite=False)[source]¶
Write the extension objects to a nifits file.
- Parameters:
static_only (
bool
) – (bool) only save the extensions corresponding to static parameters of the model (NI_CATM and NI_FOV). Default: Falsedynamic_only (
bool
) – (bool) only save the dynamic extensions. If true, the hash of the static file should be passed as static_hash. Defaultult: Falsestatic_hash (
str
) – (str) The hash of the static file. Default: “”