Reference#

iop4lib is the module at the core of IOP4.


iop4lib.config#

Configuration and initialization of iop4lib.

class iop4lib.config.Config(*args, **kwargs)[source]#

Configuration class for IOP4.

This class is a singleton, that is, it always returns the same instance of the class.

configure_logging()#

Adds the ‘%(proc_memory)’ field in the log record.

copy() a shallow copy of D#
is_valid()#

Checks that the configuration file is correct by comparing it with the default one.

Returns:
bool

True if the configuration file is correct, False otherwise.

iop4lib.db#

Models for the database.

class iop4lib.db.epoch.Epoch(*args, **kwargs)[source]#

A class representing an epoch.

Identified by the telescope and date of the night. Provides method for fetching the data from the telescope archives and reducing the data.

Parameters:
  • id (BigAutoField) – ID

  • telescope (CharField) – telescope

  • night (DateField) – night

  • flags (FlagBitField) – flags

class FLAGS(value)#

An enumeration.

compute_relative_photometry(redf_qs=None)#

Computes the relative photometry results for this epoch.

Parameters:
redf_qsQuerySet, optional

If provided, the relative photometry will be computed only for the ReducedFit objects in the QuerySet. If not provided, the relative photometry will be computed for all ReducedFit objects in the epoch.

compute_relative_polarimetry(redf_qs=None)#

Computes the relative polarimetry results for this epoch.

Parameters:
redf_qsQuerySet, optional

If provided, the relative polarimetry will be computed only for the ReducedFit objects in the QuerySet. If not provided, the relative polarimetry will be computed for all ReducedFit objects in the epoch.

classmethod create(telescope=None, night=None, epochname=None, auto_link_rawfits=True, check_remote_list=False, force_redownload=False, fallback_to_local=True, auto_merge_to_db=True, rawfits_kwargs={})#

Create an Epoch object for the given telescope and night, reusing an existing DB entry if it exists.

Parameters:
epochnamestr

TEL/YYYY-MM-DD, TEL/YYYYMMDD or TEL/YYMMDD ot (converted to TEL/20YYMMDD)

static epochname_to_tel_night(epochname: str) tuple[str, date]#

Parses an epochname to a telescope and night.

get_summary_rawfits_status()#

Returns list of flags present in the rawfits of this epoch.

has_flags(flags)#

Return True if all flags given are set.

has_not_flags(flags)#

Return True if all flags given are NOT set.

Links rawfits to this epoch.

list_remote_raw_fnames()#

Checks remote file list and builds self.rawfits from them.

make_polarimetry_groups(redf_qs=None)#

To reduce the polarimetry data, we need to group the reduced fits corresponding to rotated polarization angles.

To group the reduced fits, we make sure they are close (<10min from the julian date field), and that they correspond to the same object, band and exposure time.

To make sure the correspond to the make object we make use of the OBJECT keyword in the FITS header; in OSN these are the object names (not necessarily the name we use in IOP4 catalog) and in CAHA these are the object name + the angle of the polarizer (e.g. “1652+398 0.0 deg”). So we just split the string by ‘ ‘ and use the first element. TODO: might be better to use the sources_in_field but right now the catalog is pretty incomplete.

reduce(force_rebuild=False)#

Reduces all (LIGHT) rawfits of this epoch.

If force_rebuild is False, only rawfits that have not been reduced yet (that do not have the BUILT_REDUCED flag) will be reduced, else all rawfits of this epoch of type LIGHT be reduced.

If iop4conf.nthreads > 1, the reduction will be done in parallel processes.

static reduce_rawfits(rawfits, force_rebuild=False, epoch=None)#

Bulk reduces a list of RawFit in a multiprocessing pool. rawfits can be an iterable such as a QuerySet.

If force_rebuild is False, only rawfits that have not been reduced yet (that do not have the BUILT_REDUCED flag) will be reduced, else all rawfits in the list will be reduced.

If iop4conf.nthreads > 1, the reduction will be done in parallel processes.

Parameters:
rawfitsiterable

An iterable of RawFit objects to be reduced.

Other Parameters:
epochEpoch, optional

If provided, it is used only to print the epoch in the log messages of the main thread.

static reduce_reducedfits(reduced_L, epoch=None)#

Bulk reduces a list of ReducedFit in a multiprocessing pool.

If iop4conf.nthreads > 1, the reduction will be done in parallel processes.

Parameters:
reduced_Llist

A list of ReducedFit objects to be reduced. The .build_file() method of each object is always called, independently of the value of the BUILT_REDUCED flag.

Other Parameters:
epochEpoch, optional

If provided, it is used only to print the epoch in the log messages of the main thread.

property calibrationdir#

Returns the path to the directory where the calibration files of this epoch are stored.

property epochname#

Returns a human readable string that uniquely identifies the epoch, as an alternative to the id.

property flag_labels#

List of labels for the flags set.

property flag_list#

List of flags set, as enum choices (value, label).

property flag_values#

list of values for the flags set.

property jyear#

Returns the jyear of the epoch at noon (before the night).

property masterbiasdir#

Returns the path to the directory where the masterbias files of this epoch are stored.

property masterdarkdir#

Returns the path to the directory where the masterdark files of this epoch are stored.

property masterflatdir#

Returns the path to the directory where the masterflat files of this epoch are stored.

property rawfitsdir#

Returns the path to the directory where the raw fits of this epoch are stored.

property yymmdd#

Returns the date of the epoch in the format YYMMDD.

property yyyymmdd#

Returns the date of the epoch in the format YYYYMMDD.

iop4lib.db.epoch.epoch_bulkreduce_onebyone(reduced_L: Sequence[ReducedFit], epoch: Epoch | None = None) None[source]#

Reduces a list of ReducedFit instances one by one.

class iop4lib.db.rawfit.RawFit(id, epoch, filename, flags, instrument, obsmode, juliandate, imgsize, imgtype, band, rotangle, exptime)[source]#
Parameters:
  • id (BigAutoField) – ID

  • epoch_id (ForeignKey) – epoch

  • filename (CharField) – filename

  • flags (FlagBitField) – flags

  • instrument (CharField) – Instrument used for the observation.

  • obsmode (CharField) – Whether the observation was photometry or polarimetry.

  • juliandate (FloatField) – Julian date of observation, from the date and time indicated in the FITS header.

  • imgsize (CharField) – String with the format _width_x_height_ for the image, as in 1024x1024.

  • imgtype (CharField) – Whether the raw image is a bias (BIAS), flat (FLAT), or science (LIGHT).

  • band (CharField) – Band of the observation, as in the filter used (R, V, etc).

  • rotangle (FloatField) – Rotation angle of the polarizer in degrees.

  • exptime (FloatField) – Exposure time in seconds.

class FLAGS(value)#

An enumeration.

classify()#

Get some parameters from the fit file to the DB entry.

classmethod create(epoch=None, filename=None, fileloc=None, auto_procure_local=True, reset_flags=False, auto_classify=True, force_redownload=False, auto_merge_to_db=True)#

Create a RawFit object from fileloc or epoch and filename.

Flags are cleared when .create() is called.

Parameters:
filelocstr

File location in the format TELESCOPE/YYYYMMDD/FILENAME.

epochEpoch

Epoch object.

filenamestr

Filename.

auto_procure_localbool

Whether automatically procure the local file (linking it to a local file).

auto_classifybool

If auto_procure_local is True, whether to automatically classify the file.

force_redownloadbool

If auto_procure_local is True, whether to force redownload of the file even if it already exists.

auto_merge_to_dbbool

Whether automatically merge the object to the DB when making any changes, including creation.

static fileloc_to_tel_night_filename(fileloc)#

Parses a fileloc to telescope, night and filename.

has_flags(flags)#

Return True if all flags given are set.

has_not_flags(flags)#

Return True if all flags given are NOT set.

property filedpropdir#

Returns the full path to the directory where related files are stored. The directory is in the calibrationdir of the epoch, different from the rawfitsfit, to keep a clean archive of raw data (see the Epoch class). Reduced FITS files will be stored here also, see the ReducedFit class.

property fileloc#

Returns an human readable string which uniquely identifies the file, as an alternative to the id.

property filepath#

Returns the full path to the FITS file. The raw FITS file are stored in the rawfitsdir of the epoch.

property flag_labels#

List of labels for the flags set.

property flag_list#

List of flags set, as enum choices (value, label).

property flag_values#

list of values for the flags set.

property header_hintcoord#

Returns a SkyCoord according to the headers of the FITS file.

property header_hintobject#

Returns the AstroSource according to the OBJECT keyword in the header of the FITS file.

class iop4lib.db.masterbias.MasterBias(*args, **kwargs)[source]#

A class representing a master bias for an epoch.

Parameters:
  • id (BigAutoField) – ID

  • flags (FlagBitField) – flags

  • epoch_id (ForeignKey) – epoch

  • instrument (CharField) – instrument

  • imgsize (CharField) – imgsize

class FLAGS(value)#

An enumeration.

classmethod create(rawfits=None, auto_merge_to_db=True, force_rebuild=False, **kwargs)#

Create a MasterBias object for the given epoch, reusing an existing DB entry if it exists.

It will overwrite any existing MasterBias for that epoch, or create a new one if it doesn’t exist.

Parameters:
rawfitslist of RawFit, optional

List of RawFit objects used to build the MasterBias.

auto_merge_to_dbbool, optional

If True, automatically merge the created MasterBias object to the database.

force_rebuildbool, optional

If True, force rebuilding the MasterBias even if it already exists.

Other Parameters:
`**kwargs`

Keyword arguments passed to the constructor.

has_flags(flags)#

Return True if all flags given are set.

has_not_flags(flags)#

Return True if all flags given are NOT set.

classmethod margs2str(margs)#

Class method to build a nice string rep of the arguments of a MasterFlat.

property flag_labels#

List of labels for the flags set.

property flag_list#

List of flags set, as enum choices (value, label).

property flag_values#

list of values for the flags set.

property margs#

Return a dict of the arguments used to build this MasterFlat.

class iop4lib.db.masterflat.MasterFlat(*args, **kwargs)[source]#

A class representing a master flat for an epoch.

Parameters:
  • id (BigAutoField) – ID

  • flags (FlagBitField) – flags

  • epoch_id (ForeignKey) – epoch

  • instrument (CharField) – instrument

  • imgsize (CharField) – imgsize

  • band (CharField) – band

  • obsmode (CharField) – obsmode

  • rotangle (FloatField) – rotangle

  • exptime (FloatField) – exptime

  • masterbias_id (ForeignKey) – masterbias

  • masterdark_id (ForeignKey) – masterdark

class FLAGS(value)#

An enumeration.

classmethod create(rawfits=None, masterbias=None, masterdark=None, auto_merge_to_db=True, force_rebuild=True, **kwargs)#

Create a MasterFlat object for Epoch epoch.

Parameters:
epoch: Epoch
instrument: str
imgsize: “WidthxHeight” str
band: str
obsmode: str
rotangle: float
exptime: flat
Other Parameters:
rawfits: list of RawFit (optional)
masterbias: MasterBias (optional)
auto_merge_to_db: bool (optional) Default: True
has_flags(flags)#

Return True if all flags given are set.

has_not_flags(flags)#

Return True if all flags given are NOT set.

classmethod margs2str(margs)#

Class method to build a nice string rep of the arguments of a MasterFlat.

property flag_labels#

List of labels for the flags set.

property flag_list#

List of flags set, as enum choices (value, label).

property flag_values#

list of values for the flags set.

property margs#

Return a dict of the arguments used to build this MasterFlat.

class iop4lib.db.reducedfit.ReducedFit(*args, **kwargs)[source]#

Reduced fits (bias and flat corrected, with wcs coordinates, etc, source list, etc).

Parameters:
  • id (BigAutoField) – ID

  • epoch_id (ForeignKey) – epoch

  • filename (CharField) – filename

  • flags (FlagBitField) – flags

  • instrument (CharField) – Instrument used for the observation.

  • obsmode (CharField) – Whether the observation was photometry or polarimetry.

  • juliandate (FloatField) – Julian date of observation, from the date and time indicated in the FITS header.

  • imgsize (CharField) – String with the format _width_x_height_ for the image, as in 1024x1024.

  • imgtype (CharField) – Whether the raw image is a bias (BIAS), flat (FLAT), or science (LIGHT).

  • band (CharField) – Band of the observation, as in the filter used (R, V, etc).

  • rotangle (FloatField) – Rotation angle of the polarizer in degrees.

  • exptime (FloatField) – Exposure time in seconds.

  • rawfit_id (OneToOneField) – RawFit of this ReducedFit.

  • masterbias_id (ForeignKey) – MasterBias to be used for the reduction.

  • masterflat_id (ForeignKey) – MasterFlat to be used for the reduction.

  • masterdark_id (ForeignKey) – MasterDark to be used for the reduction.

  • modified (DateTimeField) – Last time this entry was modified.

compute_aperture_photometry(*args, **kwargs)#

Delegated to the instrument.

compute_relative_photometry(*args, **kwargs)#

Delegated to the instrument.

classmethod compute_relative_polarimetry(polarimetry_group, *args, **kwargs)#

Delegated to the instrument.

classmethod create(rawfit, masterbias=None, masterflat=None, masterdark=None, auto_build=False, force_rebuild=False, auto_merge_to_db=True)#

Creates a new instance of ReducedFit from a RawFit, updates existing entry if it exists.

Parameters:
rawfitRawFit

The RawFit to be reduced.

masterbiasMasterBias, optional

The MasterBias to be used for the reduction. If None, an appropiate MasterBias will be found.

masterflatMasterFlat, optional

The MasterFlat to be used for the reduction. If None, an appropiate MasterFlat will be found.

Returns:
None
Other Parameters:
auto_buildbool, optional

If auto_build is True, the file will be built if it does not exist.

force_rebuildbool, optional

If force_rebuild is True, the file will be built regardless of whether it exists or not; this takes precedence over auto_build.

Notes

See ReducedFit.build_file for more information about how the file is build.

property filepath#

Returns the path to the file. The reduced FITS files are stored in the .filedpropdir directory (the same .filedpropdir as the corresponding RawFit).

property has_pairs#

Indicates whether both ordinary and extraordinary sources are present in the file.

property header_hintcoord#

Returns a SkyCoord according to the headers of the FITS file.

property header_hintobject#

Returns the AstroSource according to the OBJECT keyword in the header of the FITS file.

property pixscale#

Pixel scale of the reduced fit, in units of deg/pix (it returns the mean of x and y scales so it is strictly correct only for square pixels).

property pixscale_equiv#

Returns an equivalencies between pixels and angles for this reduced fit.

property pixscales#

Pixel scales of the reduced fit as quantities (deg/pix) (it returns both the x and y scales).

property wcs#

Returns the WCS of the reduced fit.

property wcs1#

Returns the WCS of the first extension of the reduced fit.

property wcs2#

Returns the WCS of the second extension of the reduced fit.

class iop4lib.db.astrosource.AstroSource(id, name, other_names, ra_hms, dec_dms, srctype, comment, redshift, mag_R, mag_R_err, mag_B, mag_B_err, mag_V, mag_V_err, mag_I, mag_I_err, mag_U, mag_U_err)[source]#
Parameters:
  • id (BigAutoField) – ID

  • name (CharField) – Name of the source (must be unique)

  • other_names (CharField) – Alternative names for the source, separated by a semicolon ‘;’. It might be needed to correctly identify the target source of observations if observers used a different name.

  • ra_hms (CharField) – Right ascension in hh:mm:ss format

  • dec_dms (CharField) – Declination in dd:mm:ss format

  • srctype (CharField) – Source type

  • comment (TextField) – Any comment about the source (in Markdown format)

  • redshift (FloatField) – Redshift of the source

  • mag_R (FloatField) – Literature magnitude in R band (for calibrators only)

  • mag_R_err (FloatField) – Literature magnitude error in R band (for calibrators only)

  • mag_B (FloatField) – Literature magnitude in B band (for calibrators only)

  • mag_B_err (FloatField) – Literature magnitude error in B band (for calibrators only)

  • mag_V (FloatField) – Literature magnitude in V band (for calibrators only)

  • mag_V_err (FloatField) – Literature magnitude error in V band (for calibrators only)

  • mag_I (FloatField) – Literature magnitude in I band (for calibrators only)

  • mag_I_err (FloatField) – Literature magnitude error in I band (for calibrators only)

  • mag_U (FloatField) – Literature magnitude in U band (for calibrators only)

  • mag_U_err (FloatField) – Literature magnitude error in U band (for calibrators only)

class SRCTYPES(value)#

Enum for possible types of sources

classmethod get_sources_in_field(wcs=None, width=None, height=None, fit=None, qs=None)#

Get the sources in the field of view of the image.

It accepts either a fit image or a wcs, height and width. If no query set is given, it will search the whole catalog, otherwise it will search the given query set.

class iop4lib.db.astrosource.AstroSourceQuerySet(model=None, query=None, using=None, hints=None)[source]#
class iop4lib.db.photopolresult.PhotoPolResult(*args, **kwargs)[source]#

Model for Photo-Polarimetric results, from a set of ReducedFits and for a given AstroSource, produced by a reduction method.

Note

A Photo Polarimetric will be uniquely identified by the reduced fits it had been built from, the source for which the result is, and the reduction method used. Since the reducedfits are a ManyToManyField, we can not add a unique_together constraint to the combination of fields that is enforced in the DB level (Django does not support this); instead we specify a custom m2m relationship and enforce the constraints there.

Note

Some fields like ‘juliandate’, ‘band’, ‘exptime’, etc are automatically derived from the reducedfits. This is done in two ways: - Every time an instance is saved, in PhotoPolResult.save(), through PhotoPolResult.clean(). - Evert time a reducedfit is added or removed from the reducedfits ManyToManyField, through the m2m_changed signal handler in PhotoPolResult.

These fields could perhaps be better implemented as properties, but having them as real fields simplifies things a lot in the admin or when filtering.

The fields ‘astrosource’ and ‘reduction’ are derived from the m2m relationship PhotoPolResultReducedFitRelation also.

None of these fields should be set manually, as they are automatically computed on save.

Parameters:
  • id (BigAutoField) – ID

  • astrosource_id (ForeignKey) – astrosource

  • reduction (CharField) – Reduction method used.

  • juliandate (FloatField) – Julian date of observation (mean of julian dates of all reducedfits). Automaticaly computed on save, do not edit.

  • juliandate_min (FloatField) – Minimum julian date of observation (min of julian dates of all reducedfits). Automaticaly computed on save, do not edit.

  • juliandate_max (FloatField) – Maximum julian date of observation (max of julian dates of all reducedfits). Automaticaly computed on save, do not edit.

  • epoch_id (ForeignKey) – Epoch of the observation.

  • instrument (CharField) – Instrument used for the observation.

  • obsmode (CharField) – Whether the observation was photometry or polarimetry.

  • band (CharField) – Band of the observation, as in the filter used (R, V, etc).

  • exptime (FloatField) – Exposure time in seconds.

  • aperpix (FloatField) – Aperture radius in pixels.

  • bkg_flux_counts (FloatField) – Background flux in counts from aperture photometry.

  • bkg_flux_counts_err (FloatField) – Error for bkg_flux_counts.

  • flux_counts (FloatField) – Flux in counts from aperture photometry (background-substracted).

  • flux_counts_err (FloatField) – Error for flux_counts.

  • mag_inst (FloatField) – Instrumental magnitude, computed directly from the flux counts.

  • mag_inst_err (FloatField) – Error for mag_inst.

  • mag_zp (FloatField) – Magnitude zero point (if it is a calibrator with known magnitude, it is the computed zero point from it, if it is not a calibrator, it is the zero point used to compute the magnitude of the source

  • mag_zp_err (FloatField) – Error for mag_zp.

  • _x_px (FloatField) – pixel position of the source in the image, x coordinate.

  • _y_px (FloatField) – pixel position of the source in the image, y coordinate.

  • _q_nocorr (FloatField) – value without correction for instrumental polarization!

  • _u_nocorr (FloatField) – value without correction for instrumental polarization!

  • _p_nocorr (FloatField) – value without correction for instrumental polarization!

  • _chi_nocorr (FloatField) – value without correction for instrumental polarization!

  • mag (FloatField) – Magnitude of the source, result of the reduction.

  • mag_err (FloatField) – Error for mag.

  • p (FloatField) – Polarization of the source [0-1], result of the reduction.

  • p_err (FloatField) – Error for p.

  • chi (FloatField) – Polarization angle of the source [deg], result of the reduction.

  • chi_err (FloatField) – Error for chi.

  • aperas (FloatField) – Aperture radius in arcseconds.

  • mag_corr (FloatField) – Magnitude corrected for host galaxy.

  • mag_corr_err (FloatField) – Error for mag_corr.

  • p_corr (FloatField) – Polarization corrected for host galaxy.

  • p_corr_err (FloatField) – Error for p_corr.

  • used_mag_for_corr (FloatField) – Magnitude used for host galaxy correction (when mag is not available).

  • used_mag_err_for_corr (FloatField) – Error for used_mag_for_corr.

  • flags (FlagBitField) – Flags for the quality of the result.

  • modified (DateTimeField) – modified

exception NoHostCorrectionAvailable#
class FLAGS(value)#

An enumeration.

clean()#

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

compute_host_galaxy_correction()#

Computes the host galaxy correction and stores it in the appropriate fields in the DB.

See [1] and the docstring of iop4lib.utils.get_host_correction for more info.

References

[1] Nilsson, K., “Host galaxy subtraction of TeV candidate BL Lacertae objects”

Astronomy and Astrophysics, vol. 475, no. 1, pp. 199-207, 2007. doi:10.1051/0004-6361:20077624. URL: https://ui.adsabs.harvard.edu/abs/2007A%26A…475..199N/abstract

classmethod create(reducedfits, astrosource, reduction, **kwargs)#

Creates a new instance of PhotoPolResult, for a set of ReducedFit objects, an AstroSource and a reduction method, or updates an existing one.

Parameters:
reducedfitslist of ReducedFit

List of ReducedFit objects to be associated with the PhotoPolResult. They will be stored on the ManyToMany field ‘reducedfits’.

astrosourceAstroSource

AstroSource object to be associated with the PhotoPolResult. It will be stored as additional information on the ManyToMany relationship with the ‘reducedfits’.

reductionstr

Reduction method used. It will be stored as additional information on the ManyToMany relationship with the ‘reducedfits’.

Other Parameters:
Any other keyword argument will be set on the instance created, and saved.
has_flags(flags)#

Return True if all flags given are set.

has_not_flags(flags)#

Return True if all flags given are NOT set.

classmethod qs_exact_reducedfits(reducedfits)#

Returns a queryset of PhotoPolResult with exactly the same set of reducedfits as the ones provided.

save(*args, **kwargs)#

Overriden to enforce clean() before saving. See PhotoPolResult.__docstring__ for more info.

property flag_labels#

List of labels for the flags set.

property flag_list#

List of flags set, as enum choices (value, label).

property flag_values#

list of values for the flags set.

class iop4lib.db.photopolresult.PhotoPolResultReducedFitRelation(id, photopolresult, reducedfit, astrosource, reduction)[source]#
Parameters:
  • id (BigAutoField) – ID

  • photopolresult_id (ForeignKey) – photopolresult

  • reducedfit_id (ForeignKey) – reducedfit

  • astrosource_id (ForeignKey) – astrosource

  • reduction (CharField) – Reduction method used.

iop4lib.db.photopolresult.reducedfits_on_change(sender, instance, action, **kwargs)[source]#

Updates automatically filled fields when -after- reducedfits are altered.

class iop4lib.db.aperphotresult.AperPhotResult(*args, **kwargs)[source]#

Aperture photometry results for an AstroSource in a ReducedFit, either the Ordinary or Extraordinary pair.

Parameters:
  • id (BigAutoField) – ID

  • reducedfit_id (ForeignKey) – The ReducedFit this AperPhotResult has been computed for.

  • astrosource_id (ForeignKey) – The AstroSource this AperPhotResult has been computed for.

  • aperpix (FloatField) – aperpix

  • r_in (FloatField) – r in

  • r_out (FloatField) – r out

  • pairs (TextField) – Whether this AperPhotResult is for the Ordinary or Extraordinary pair.

  • bkg_flux_counts (FloatField) – bkg flux counts

  • bkg_flux_counts_err (FloatField) – bkg flux counts err

  • flux_counts (FloatField) – flux counts

  • flux_counts_err (FloatField) – flux counts err

  • x_px (FloatField) – used pixel position of the source in the image, x coordinate.

  • y_px (FloatField) – used pixel position of the source in the image, y coordinate.

  • fwhm (FloatField) – fwhm

  • modified (DateTimeField) – modified

iop4lib.utils#

Utility functions, used thoughout the code.

iop4lib.utils.sourcedetection.get_bkg(imgdata, box_size=(16, 16), filter_size=(11, 11), mask=None)[source]#

Returns the 2D background for a given box_size and filter_size. Optionally, a mask can be provided (to mask sources or bad pixels).

iop4lib.utils.sourcedetection.get_cat_sources_from_segment_map(segment_map, imgdata_bkg_substracted, convolved_data)[source]#

From a segmentation map, return a cataloge and the positions ((x1,y1), (x2,y2), …).

Needs also the bkg-substracted image and the convolved map to find the centroids from the segement map.

iop4lib.utils.sourcedetection.get_segmentation(imgdata_bkg_substracted, threshold, fwhm=1.0, kernel_size=None, npixels=64, deblend=True, mask=None)[source]#

Given the image with the background substracted, convolve it with a kernel (smooth it) and find the segmentation map.

Return the segemented map and the convolved image.

iop4lib.utils.sourcedetection.get_sources_daofind(data, threshold=None, fwhm=8.0, n_threshold=5.0, brightest=100, exclude_border=True)[source]#

data needs not but should be bkg-substracted and smoothed (that is, convolved with a kernel), threshold should be set depending on the brackground noise.

iop4lib.utils.sourcedetection.select_points(points, n, brightness=None)[source]#

returns n points approximately uniformly distributed over the image, selecting the closes one to each cluster or the brightest one if brightness is provided.

iop4lib.utils.sourcepairing.get_best_pairs(list1, list2, disp_sign, dist_err=None, disp_sign_err=None)[source]#

From two lists which correspond to paired points, if there are points participating in more than one pair, return only the best pair according to displacement disp_sign.

If dist_err (scalar) or disp_sign_err are given, only pairs whose points are displace by disp_sign within a distance of dist_err (1d) or within disp_sign_err (2d) are considered.

Parameters:
list1, list2list, list

paired lists of points

disp_sign: (float, float)

the displacement between points

Returns:
list1, list2list, list

paired list of points

d0_newfloat

recomputed points

disp_sign_new

recomputed displacement

iop4lib.utils.sourcepairing.get_pairs_d(pos, d0=None, d_eps=None, d_min=None, d_max=None, bins=None, hist_range=None, redf=None, doplot=False, ax=None)[source]#

From a list of positions, finds the most common distance between them (d0), and pairs the points that are at such distance. If d0 is given, it is used instead of computing it.

The pairs are ordered such that for pair (p1, p2), p1 is always to the left (smaller x value) than p2.

iop4lib.utils.sourcepairing.get_pairs_dxy(pos, disp=None, dx_eps=None, dy_eps=None, d_eps=None, dx_min=None, dx_max=None, dy_min=None, dy_max=None, d_min=None, bins=None, hist_range=None, redf=None, doplot=False, axs=None, fig=None)[source]#

From a list of positions, finds the most common distances between them in both x and y axes (disp), and pairs the points that are at such distances.

If disp is given, it is used as the most common distance in both axes instead of computing it.

The pairs are ordered such that for pair (p1, p2), p1 is always to the left (smaller x value) than p2.

Note: this function is similar to get_pairs_d(), but finds the most common distances both in x and y axes.

class iop4lib.utils.astrometry.BuildWCSResult(success: bool, wcslist: list[~astropy.wcs.wcs.WCS] = <factory>, info: dict = <factory>)[source]#
‘success’: bool

whether the appropiate WCSs was built successfully

‘wcslist’: list

list of WCS objects built (usually one, two if there are extraordinary sources in the image)

‘info’: dict or None

dict with extra information about the process

Boolean evaluation of this object returns the value of ‘success’.

iop4lib.utils.astrometry.build_wcs_params_shotgun(redf: ReducedFit, shotgun_params_kwargs: dict = None, hard: bool = False, summary_kwargs: dict = {'build_summary_images': True, 'with_simbad': True}) BuildWCSResult[source]#

Build the appropiate WCSs for a ReducedFit image, trying different parameters. See build_wcs for more info.

Note: at the moment, this function tries source extraction with different combination of parameters and thresholds for source extraction by calling a helper func (_build_wcs_detect_and_try_solve) with these parameters, which detects the sources with photutils image segmentation and tries to solve the WCS with the astrometry.net python wrapper. The parameter combinations are chosen depending on the exposure time and the presence of pairs in the image.

TODO:

  • Implement a more robust way to choose the parameters for source extraction such that the astrometry solver works with less attempts.

  • Explore other detectors and solvers if necessary to improve speed, sucess rate and accuracy.

  • Use pre-computed pair distances.

iop4lib.utils.astrometry.solve_astrometry(stars, size_hint=None, position_hint=None, output_logodds_threshold=21, sip=False, positional_noise_pixels=1)[source]#

Actually run Astrometry solver with the given stars and position and size hints.

iop4lib.utils.parallel.epoch_bulkreduce_multiprocesing(reduced_L, epoch=None)[source]#

Reduces a list of ReducedFit instances in a multiprocessing pool.

Invokes the reduction of a list of ReducedFit instances in a multiprocessing pool, with a maximum number of concurrent processes defined by iop4conf.nthreads. It can be invoked with a list of ReducedFit from different epochs.

Parameters:
reduced_Llist of ReducedFit

List of ReducedFit instances to be reduced.

Other Parameters:
epochEpoch, optional

If provided, it is used only to print the epoch in the log messages of the main thread.

iop4lib.telescopes#

Telescope specific code.

class iop4lib.telescopes.telescope.Telescope[source]#

Base class for telescopes.

Inherit this class to provide telescope specific functionality (e.g. discovering and downloading new data, classification of instruments, etc).

Attributes and methods that must be implemented are marked as abstract (they will give error if the class is inherited and the method is not implemented in the subclass).

Other methods can be implemented in the subclass but are not required just raise NotImplementedError.

Some classmethods are already defined since they are telescope independent; we should not need to override them (but it can be done).

Note

This class is abstract, it should not be instantiated.

Note

To add a new telescope, inherit this class and add it to the list of known telescopes in the get_known() method and the TelescopeEnum.

classmethod by_name(name: str) Telescope#

Try to get telescope by name, then abbreviation, else raise Exception.

classmethod check_telescop_kw(rawfit)#

TELESCOP is an standard FITS keyword, it should not be telescope dependent.

classmethod classify_instrument_kw(rawfit)#

INSTRUME is an standard FITS keyword, it should not be telescope dependent.

classmethod classify_rawfit(rawfit: RawFit)#

Try to classify a RawFit object.

This method will first check that the rawfit belongs to this telescope, classify the instrument, then hand off classification to the instrument class.

classmethod is_known(name)#

Check if a telescope is known by name or abbreviation.

class iop4lib.telescopes.osnt090.OSNT090[source]#
classmethod check_telescop_kw(rawfit)#

Subclassed to account for DIPOL files, that may have empty TELESCOP keyword as of 2023-10-11

If it is empty, check first the instrument, and if it is DIPOL and the night is before 2023-10-11, then continue.

Otherwise just call the parent method.

class iop4lib.telescopes.cahat220.CAHAT220[source]#

CAHA T220 telescope.

CAHA has a per-program ftp login (PI user and password in config). The file structure when you login is a list of files as: {yymmdd}_CAFOS/ where CAFOS refers to the polarimeter and inside each folder there are the files for that day.

Currently only one instrument, CAFOS.

iop4lib.instruments#

Instrument specific code.