procastro package
Module contents
Framework to easily handle multiple astronomy data files
- class procastro.AstroDir(*args, **kwargs)
Bases:
objectCollection of AstroFile objects.
Collection can be indexed, filtered, and has several recursive methods that are applied to each AstroFile are available
- files
Contains the list of all AstroFile that belong to this AstroDir.
- Type:
list
- props
Properties related to this object
- Type:
dict
- Parameters:
path (str or list or AstroFile) – Contains information from the file list. If str, a directory+wildcard format is assumed and parsed by glob.glob
mbias (array_like, dict or AstroFile, optional) – Master bias and flat to associate to each AstroFile (in one shared AstroCalib object)
mflat (array_like, dict or AstroFile, optional) – Master bias and flat to associate to each AstroFile (in one shared AstroCalib object)
mbias_header (astropy.io.fits.Header) – Headers for bias and flat
mflat_header (astropy.io.fits.Header) – Headers for bias and flat
calib_force (bool, optional) – If True, then force specified mbias and mflat to all files, otherwise assign it only if it doesn’t have one already.
hdu (int, optional) – default HDU
hdud (int, optional) – default HDU for data
hduh (int, optional) – default HDU for the header
See also
procastro.AstroCalibObject that holds calibration information. One of them can be shared by many AstroFile instances
procastro.AstroCalib.add_bias,procastro.AstroCalib.add_flat- add_bias(mbias)
Updates the master bias of all AstroCalib instances included on the contained AstroFile instances
- Parameters:
mbias (dict indexed by exposure time, array or AstroFile) – Master Bias to use for all frames.
See also
procastro.AstroCalib.add_biasthis function is called for each unique AstroCalib object in AstroDir
- add_flat(mflat)
Update Master Flats of all AstroCalib instances included on the contained AstroFile instances.
- Parameters:
mflat (dict indexed by filter name, array or AstroFile) – Master Flat to use for all frames.
See also
procastro.AstroCalib.add_flatThis function is called for each unique AstroCalib object in AstroDir
- sort(*args, **kwargs)
Sorts AstroFile instances inplace depending on the given header fields. After sorting the contents the method will return None to avoid problems
- Parameters:
args (str) – A header field name to be used as comparison key
- Raises:
ValueError – If the field given cannot be used to compare each AstroFile or if no header field was specified.
- stats(*args, **kwargs)
Obtains statistical data from each AstroFile stored in this instance
- Parameters:
extra_headers (list, optional) – List of header items to include on the output
verbose_heading (bool, optional) –
args (Specify the stats that want to be returned) –
- Returns:
The stat as returned by each of the AstroFiles
- Return type:
array_like
See also
procastro.AstroFile.statsfor the available statistics
- filter(*args, **kwargs)
Filter files according to those whose filter return True to the given arguments. What the filter does is type-dependent for each file.
Logical ‘and’ statements can be simulated by chaining this method multiple times.
- Parameters:
**kwargs – Keyword arguments containing the name of the item and the expected value.
- Returns:
Copy containing the files which were not discarded.
- Return type:
See also
procastro.AstroFile.filterSpecifies the syntax used by the recieved arguments.
- basename(joinchr=', ')
Obtains the basename each file contained.
- Parameters:
joinchar (str, optional) – Character used to separate the name of each file
- Returns:
Each file basename separated by the specified ‘joinchar’
- Return type:
str
- getheaderval(*args, **kwargs)
Gets the header values specified in ‘args’ from each file. A function can be specified to be used over the returned values for casting purposes.
- Parameters:
cast (function, optional) – Function output used to cas the output
- Returns:
Type depends on whether a single value or multiple tuples were given
- Return type:
List of integers or tuples
- setheader(**kwargs)
Sets the header values specified in ‘args’ from each of the files.
- get_datacube(normalize_region=None, normalize=False, verbose=False, check_unique=None, group_by=None, trim_area_warn=0.25)
Generates a data cube with the data of each AstroFile.
- Parameters:
normalize_region – Subregion to use for normalization
normalize (bool, optional) – If True, will normalize the data inside the data cube
verbose (bool, optional) –
check_unique (array_like, optional) – Receives a list of headers that need to be checked for uniqueness.
group_by (str, optional) – Datacube will be organized based on the header item given
- Returns:
Dictionary containing a data cube grouped by the given parameters, otherwise the data will be indexed to None as key
- Return type:
dict
- pixel_xy(xx, yy, normalize_region=None, normalize=False, check_unique=None, group_by=None)
Obtains the pixel value at the (‘xx’,’yy’) position for all frames.
- Parameters:
xx (int, int) –
yy (int, int) –
normalize_region – Subregion to use for normalization
group_by – If set, then group by the specified header returning an [n_unique, n_y, n_x] array
normalize (bool, optional) – Whether to Normalize
check_unique (str, optional) – Check uniqueness in header
- Returns:
Values of the pixel on each frame
- Return type:
array_like
- median(normalize_region=None, normalize=False, verbose=True, check_unique=None, group_by=None)
Calculates the median of the contained files
- Parameters:
normalize_region – Subregion to use for normalization
normalize (bool, optional) – Whether to Normalize
verbose (bool, optional) – Output progress indicator
check_unique (str, optional) – Check uniqueness in header
group_by – If set, then group by the specified header returning an [n_unique, n_y, n_x] array
- Returns:
array_like – Median between frames
dict – If group_by is set, a dictionary keyed by this group will be returned
- mean(normalize_region=None, normalize=False, verbose=True, check_unique=None, group_by=None)
Calculates the mean of the contained files
- Parameters:
normalize_region – Subregion to use for normalization
normalize (bool, optional) – Whether to Normalize
verbose (bool, optional) – Output progress indicator
check_unique (str, optional) – Check uniqueness in header
group_by – If set, then group by the specified header returning an [n_unique, n_y, n_x] array
- Returns:
ndarray – Mean between frames
dict – If group_by is set, a dictionary keyed by this group will be returned
- lin_interp(target=0, verbose=True, field='EXPTIME', check_unique=None, group_by=None)
Linear interpolate to given target value of the field ‘field’.
- Parameters:
target (int, optional) – Target value for the interpolation
verbose (bool, optional) – Output progress indicator
field (str, optional) – Name of the header item which will be used to interpolate each frame
group_by – If set, then group by the specified header returning an [n_unique, n_y, n_x] array
check_unique (str, optional) – Check uniqueness in header
- Returns:
ndarray – Linear Interpolation between frames with the specified target
dict – If group_by is set, a dictionary keyed by this group will be returned
- std(normalize_region=None, normalize=False, verbose=True, check_unique=None, group_by=None)
Get pixel by pixel standard deviation within files.
- Parameters:
normalize_region – Subregion to use for normalization
normalize (bool, optional) – Whether to Normalize
verbose (bool, optional) – Output progress indicator
check_unique (str, optional) – Check uniqueness in header
group_by – If set, then group by the specified header returning an [n_unique, n_y, n_x] array
- Returns:
ndarray – Standard deviation between frames
dict – If group_by is set, a dictionary keyed by this group will be returned
- jd_from_ut(target='jd', source='date-obs', return_only_clean=False)
Add jd in header’s cache to keyword ‘target’ using ut on keyword ‘source’
- Parameters:
target (str) – Target keyword for JD storage
source (str or list) – Location of the input value on UT format
See also
procastro.AstroFile.jd_from_utFor individual file implementation
- merger(start=1, end=None, verbose=None)
Merges HDUImage data for all files contained in this object
- Parameters:
verbose (str) – a single character to be repeated unbuffered for every AstroFile
start (int, optional) – HDU unit from which the method starts joining
int (end ;) – Last ImageHDU unit to be included, if None will stop at the last hdu found
optional – Last ImageHDU unit to be included, if None will stop at the last hdu found
See also
procastro.AstroFile.mergerFor individual file implementation
- class procastro.AstroFile(*args, **kwargs)
Bases:
objectRepresentation of an astronomical data file, contains information related to the file’s data. Currently supports usage of arrays and .fit files
- Parameters:
filename (str or procastro.AstroFile) – If AstroFile, then it does not duplicate the information, but uses that object directly.
mbias (dict indexed by exposure time, array or AstroFile, optional) – Default Master bias
mflat (dict indexed by filter name, array or AstroFile, optional) – Default Master flat
exists (boolean, optional) – Represents if the given pathname has an existing file
mbias_header (astropy.io.fits.Header) –
mflat_header (astropy.io.fits.Header) –
hdu (int, optional) – Default hdu slot used for collection, if “hduh” or “hdud” are not specified, this parameter will override them.
hduh (int, optional) – hdu slot containing the header information to be collected
hdud (int, optional) – hdu slot containing astronomical data to be collected
read_keywords (list, optional) – Read all specified keywords at creation time and store them in the header cache
auto_trim (str, optional) – Header field name which is used to cut a portion of the data. This field should contain the dimensions of the section to be cut. (i.e. TRIMSEC = ‘[1:1992,1:1708]’)
ron (float, str, astropy quantity, optional) – Read-out-noise value or header keyword. Only consulted if either mbias or mflat are not CCDData. If unit not specified, photon/ADU is used as default unit; if not set at all, uses 1.0 (with warning)
gain (float, str, astropy quantity, optional) – Gain value or header keyword. Only consulted if either mbias or mflat are not CCDData. If unit not specified, photon/ADU is used as default unit; if not set at all, uses 1.0 (with warning)
unit (astropy.unit, optional) – Specifies the unit for the data
- shape
Shape of the data contained on the file
- Type:
tuple
- header_cache
Data contained on the most recently read header
- Type:
dict
- sortkey
Header Item used when sorting this object
- Type:
str
- type
File extension
- Type:
str
- get_trims()
“Get trim limits, returning in python-style YX
- add_bias(mbias)
Includes a Master Bias to this instance
- Parameters:
mbias (dict indexed by exposure time, array or AstroFile) –
- add_flat(master_flat)
Includes a Master Bias to this instance
- Parameters:
master_flat (dict indexed by filter name time, array or AstroFile) –
- default_hdu_dh()
Returns default HDU for data and header collection
- checktype(*args, **kwargs)
Verifies if the filename given corresponds to an existing file
- Returns:
“array” : If AstroFile represents a scipy array “fits” : If AstroFile points to an existing .fits file None : Otherwise
- Return type:
str
- plot(*args, **kwargs)
Generates a 1D plot based on a cross-section of the current data.
- Parameters:
args (list) – unnamed arguments passed to procastro.plot()
kwargs (dict) – named arguments passed to procastro.plot()
- add_sortkey(key)
Sets a header item used for sorting comparisons
- Parameters:
key (str) –
- imshowz(*args, **kwargs)
Plots frame after being processed using a zscale algorithm
See also
misc_graph.imshowzFor details on what keyword arguments are available
- filter(**kwargs)
Compares if the expected value of the given header item matches the value stored in this file header.
Filtering can be customized by including one of the following options after the item name, separated by an underscore.
- Strings:
BEGIN: True if value starts with the given string
END: True if value ends with the given string
ICASE: Case unsensitive match
MATCH: Case sensitive match
- Numeric values:
LT: True if current value is lower than the given number
GT: True if current value is greater than the given number
EQUAL: True if both values are the same
- Other:
NOT: Logical Not
Its possible to include multiple options, this statements count as a logical “or” statements.
- Parameters:
kwargs (Keyword Arguments or unpacked dictionary) – item_name_option : value
- Return type:
bool
Notes
If a header item has a “-” character on its name, use two underscores to represent it.
Examples
NAME_BEGIN_ICASE_NOT = “WASP” (False if string starts with wasp) NAXIS1_GT_EQUAL = 20 (True if NAXIS1 >= 20)
- setheader(**kwargs)
Set header values from kwargs. They can be specified as tuple to add comments as in pyfits.
- Parameters:
**kwargs (Keyword argument or unpacked dict) –
Examples
setheader(item1 = data1, item2 = data2)
setheader(**{"item1" : data1, "item2" : data2})- Return type:
True if header was edited properly
Notes
Setting a header value to None will remove said item from the header
- getheaderval(*args, single_in_list=False, **kwargs)
Get header value for each of the fields specified in args.
- Parameters:
single_in_list (bool) – returns a 1 element list if given one element.
args (list, tuple) – One string per argument, or a list as a single argument: getheaderval(field1,field2,…) or getheaderval([field1,field2,…]). In addition to return headers from the file, it can return “basename” and “dirname” from the filename itself if available.
cast (function, optional) – Function to use for casting each element of the result.
hdu (int, optional) – HDU to read.
- Returns:
list – If multiple values are found
string – If only one result was found
- reader(*args, skip_calib=False, hdud=None, hdu=None, verbose=True, **kwargs)
Read astro data and return it calibrated if provided
TODO: Respond to different exposure times or filters
- Parameters:
hdu (int, optional) – hdu slot to be read
hdud (int, optional) – hdu slot to be read
skip_calib (bool, optional) – If True returns data without calibration
- has_calib()
Checks if a bias or flat has been associated with this file
- Return type:
bool
- read_headers(*args, **kwargs)
Reads header from the file
- Parameters:
hdu (int, optional) – Specific hdu slot to be read
- writer(data, *args, **kwargs)
Writes given data to file
- basename()
Obtains the file basename
- Return type:
str
- property shape
- stats(*args, **kwargs)
Calculates statistical data from the file, a request can include header keywords to be included in the response.
- Parameters:
*args (str) – Statistic to be extracted, Possible values are: min, max, mean, mean3sclip, std and median
**kwargs (str) – Options available: verbose_heading and extra_headers
- Returns:
List containing the requested data
- Return type:
list
- jd_from_ut(target='jd', source='date-obs')
Add jd in header’s cache to keyword ‘target’ using ut on keyword ‘source’
- Parameters:
target (str) – Target keyword for JD storage
source (str or list) – Input value in UT format, if a tuple is given it will join the values obtained from both keywords following the UT format (day+T+time)
- merger(start=1, end=None)
Merges multiple ImageHDU objects into a single composite image , saves the new ImageHDU into a new hdu slot.
- Parameters:
start (int, optional) – HDU slot from which the algorithm starts concatenating images
end (int, optional) – Last HDU to be merged, if None will continue until the end of the HDUList
- spplot(axes=None, title=None, xtitle=None, ytitle=None, *args, **kwargs)
Plots spectral data contained on this file
- class procastro.AstroCalib(mbias=None, mflat=None, exptime_keyword='exptime', mbias_header=None, mflat_header=None, filter_keyword='filter', auto_trim=None)
Bases:
objectObject to hold calibration frames.
Since several AstroFiles might use the same calibration frames, one AstroCalib object might be shared by more than one AstroFile. For instance, all the files initialized through AstroDir share a single calibration object.
- has_bias
- Type:
bool
- has_flat
- Type:
bool
- Parameters:
mbias (dict indexed by exposure time, array or AstroFile) – Master Bias
mflat (dict indexed by filter name, array or AstroFile) – Master Flat
exptime_keyword (str, optional) – Header item name containing the exposure time of te frames
mbias_header (astropy.io.fits.Header, optional) – Header of the master bias
mflat_header (astropy.io.fits.Header, optional) – Header of the master bias
filter_keyword (str, optional) –
auto_trim (str) – Header field name which is used to cut a portion of the data. This field should contain the dimensions of the section to be cut. (i.e. TRIMSEC = ‘[1:1992,1:1708]’)
- add_bias(mbias, mbias_header=None)
Add Master Bias to Calib object.
- Parameters:
mbias (dict indexed by exposure time, array_like or AstroFile) – Master bias to be included
mbias_header (astropy.io.fits.Header) – Header to be included
- Raises:
ValueError – If the bias type is invalid
- add_flat(mflat, mflat_header=None)
Add master flat to Calib object
- Parameters:
mflat (dict indexed by filter name, array_like, AstroFile) – Master flat to be included
mflat_header (astropy.io.fits.Header, optional) – Master flat header
- Raises:
ValueError – If the bias type is invalid
- reduce(data, exptime=None, ffilter=None, data_trim=None, verbose=True)
Process given “data” using the bias and flat contained in this instance
- Parameters:
data (array_like) – Data to be reduced
exptime (int, optional) – Exposure time for bias
ffilter (str, optional) – Filter used by the flat
header (astropy.io.fits.Header, optional) –
- Returns:
Reduced data
- Return type:
array_like