imutil.imcopy.imcopy
imutil.imcopy.imcopy(
inputs,
trimsecs=None,
outputs=None,
extension=None,
return_ccd=True,
dtype=None,
update_header=True,
**kwargs,
)Copy FITS images or sections, similar to IRAF IMCOPY.
Parameters
inputs : glob pattern, path-like, CCD-like, or list-like-
Input files or CCD-like objects.
trimsecs : str or list-like of str = None-
FITS sections to extract. Bracket embraced, comma separated, XY order, 1-indexing, and including the end index. If given as array-like format of length
N, all such sections in all FITS files will be extracted. outputs : path - like or list - like = None-
Output paths. If list-like, shape must match
(n_inputs, n_sections). extension :int,str, (str,int), optional. = None-
The extension of FITS to be used. It can be given as integer (0-indexing) of the extension,
EXTNAME(singlestr), or atupleofstrandint:(EXTNAME, EXTVER). IfNone(default), the first extension with data will be used. Default:None. return_ccd : bool = True-
Whether to return CCDData objects and update
NAXIS*metadata. update_header : bool = True-
Whether to return CCDData objects and update
NAXIS*metadata. dtype : dtype - like = None-
Output/return data dtype. If
None, preserve input dtype. ****kwargs** : object = {}-
Keyword arguments passed to
CCDData.write.
Returns
:~astropy.nddata.CCDDataor list of~astropy.nddata.CCDData-
Returned only when
return_ccd=True.
Notes
To make imcopy faster, use update_header=False (2.8 ms -> 2.3 ms) and dtype=None.
All the sections will be flattened if they are higher than 1-d. I think it will only increase the complexity of the code if I accept that…?
Examples
>>> import astroimred.reduction as imred
>>> from pathlib import Path
>>>
>>> datapath = Path("./data")
>>> files = datapath.glob("*.pcr.fits")
>>> sections = ["[50:100, 50:100]", "[50:100, 50:150]"]
>>> outputs = [datapath/"test1.fits", datapath/"test2.fits"]
>>>
>>> # single file, single section
>>> trim = imred.imcopy(files[0], sections[0])
>>>
>>> # single file, multi sections
>>> trims = imred.imcopy(files[0], sections)
>>>
>>> # Save with overwrite option
>>> imred.imcopy(files[0], sections, outputs=outputs, overwrite=True)
>>>
>>> # multi file multi section
>>> trims2d = imred.imcopy(files[:2], trimsecs=sections, outputs=None)