:py:mod:`nifits.extra` ====================== .. py:module:: nifits.extra Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 extra/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: nifits.extra.NIFITSClass nifits.extra.Post Functions ~~~~~~~~~ .. autoapisummary:: nifits.extra.e2ph nifits.extra.ph2e nifits.extra.whitened_kiout nifits.extra.residual_pdet_Te Attributes ~~~~~~~~~~ .. autoapisummary:: nifits.extra.NIFITS_EXTENSIONS nifits.extra.STATIC_EXTENSIONS nifits.extra.NIFITS_EXTENSIONS nifits.extra.STATIC_EXTENSIONS nifits.extra.massq2sr nifits.extra.sr2massq .. py:data:: NIFITS_EXTENSIONS .. py:data:: STATIC_EXTENSIONS :value: [True, True, True, True, False, False, False, False, False, True, True, False] .. py:data:: NIFITS_EXTENSIONS .. py:data:: STATIC_EXTENSIONS :value: [True, True, True, True, False, False, False, False, False, True, True, False] .. py:class:: NIFITSClass Bases: :py:obj:`object` Class representation of the nifits object. .. py:attribute:: header :type: astropy.io.fits.Header .. py:attribute:: oi_array :type: OI_ARRAY .. py:attribute:: ni_catm :type: NI_CATM .. py:attribute:: ni_fov :type: NI_FOV .. py:attribute:: ni_kmat :type: NI_KMAT .. py:attribute:: oi_wavelength :type: OI_WAVELENGTH .. py:attribute:: oi_target :type: OI_TARGET .. py:attribute:: ni_mod :type: NI_MOD .. py:attribute:: ni_iout :type: NI_IOUT .. py:attribute:: ni_kiout :type: NI_KIOUT .. py:attribute:: ni_kcov :type: NI_KCOV .. py:attribute:: ni_dsamp :type: NI_DSAMP .. py:attribute:: ni_oswavelength :type: NI_OSWAVELENGTH .. py:attribute:: ni_iotags :type: NI_IOTAGS .. py:method:: from_nifits(filename: str) :classmethod: Create the nifits object from the HDU extension of an opened fits file. .. py:method:: to_nifits(filename: str = '', static_only: bool = False, dynamic_only: bool = False, static_hash: str = '', writefile: bool = True, overwrite: bool = False) Write the extension objects to a nifits file. :param static_only: (bool) only save the extensions corresponding to static parameters of the model (NI_CATM and NI_FOV). Default: False :param dynamic_only: (bool) only save the dynamic extensions. If true, the hash of the static file should be passed as `static_hash`. Defaultult: False :param static_hash: (str) The hash of the static file. Default: "" .. py:method:: check_unit_coherence() Check the coherence of the units of and prints the result NI_IOUT, NI_KCOV, and NI_KIOUT if they exist. Otherwise, does nothing. .. py:class:: Post(nifits: nifits.io.oifits.nifits = None, module=np) Bases: :py:obj:`nifits.backend.NI_Backend` This variant of the backend class offers a statistically whitened alternate forward model with directly whitened observables by calling ``w_`` prefixed methods. (Ceau et al. 2019, Laugier et al. 2023) After normal construction, use ``create_whitening_matrix()`` to update the whitening matrix based on the ``NI_KCOV`` data. Use ``w_get_all_outs`` and ``get_moving_outs`` in the same way, but they return whitened observables. Compare it to ``self.nifits.ni_kiout.w_kiout`` instead of ``self.nifits.ni_kiout.kiout``. .. py:method:: create_whitening_matrix(replace: bool = False, md: types.ModuleType = np) Updates the whitening matrix: :param replace: If true, the forward model methods are replaced by the whitened ones. The old ones get a ``old_`` prefix. :param md: A numpy-like backend module. The pile of whitening matrices is stored as ``self.Ws`` (one for each frame). .. py:method:: whiten_signal(signal) Whitens a signal so that error covariance is identity in the new axis. :param signal: The direct signal to whiten (differential observable a.k.a kernel-null) :returns: the whitened signal ($\mathbf{W}\cdot \mathbf{s}$) in the new basis. :rtype: wout_full .. py:method:: whitened_outputs(func) A decorator methods that gives applies statistical whitening to the output of the function. The whitening relies on `self.W` which is computed as by `create_whitening_matrix`. :param func: The function to decorate. :returns: The decorated function :rtype: inner .. py:method:: add_blackbody(temperature) Initializes the blackbody for a given temperature :param temperature: units.Quantity .. py:method:: get_pfa_Te(signal=None, md=np) Compute the Pfa for the energy detector test. :param signal: The raw signal (non-whitened) :returns: pfa the false alarm probability (p-value) associated to the given signal. .. py:method:: get_pfa_Tnp(alphas, betas, signal=None, model_signal=None, md=np) Compute the Pfa for the Neyman-Pearson test. .. py:method:: get_blackbody_native() :returns: in units consistent with the native units of the file $[a.sr^{-1}.m^{-2}]$ (where [a] is typically [ph/s]). :rtype: blackbody_spectrum .. py:method:: get_blackbody_collected(alphas, betas, kernels=True, whiten=True, to_si=True) Obtain the output spectra of a blackbody at the given blackbody temperature :param alphas: ArrayLike: Relative position in rad :param betas: ArrayLike: Relative position in rad :param kernels: Bool (True) Whether to work in the kernel postprocessing space (False is not implemented yet) :param whiten: Bool (True) whether to use whitening post-processing (False is not implemented yet) :param to_si: Bool (True) convert to SI units .. py:method:: get_Te() Computes the Te test statistic of the current file. This test statistic is supposed to be distributed as a chi^2 under H_0. :returns: x.T.dot(x) where x is the whitened signal. :rtype: Te .. py:method:: get_pdet_te(alphas, betas, solid_angle, kernels=True, pfa=0.046, whiten=True, temperature=None) pfa: * 1 sigma: 0.32 * 2 sigma: 0.046 * 3 sigma: 0.0027 .. py:method:: get_sensitivity_te(alphas, betas, kernels=True, temperature=None, pfa=0.046, pdet=0.9, distance=None, radius_unit=units.Rjup, md=np) .. code-block:: python from scipy.stats import ncx2 xs = np.linspace(-10, 10, 100) ys = np.linspace(1e-6, 0.999, 100) u = 1 - ncx2.cdf(xs, df=10, nc=0) v = ncx2.ppf(1 - ys, df=10, nc=0) plt.figure() plt.plot(xs, u) plt.show() plt.figure() plt.plot(ys, v) plt.plot(u, xs) plt.show() .. py:method:: get_pdet_tnp(transmission_map, pfa=0.046, pdet=0.9) .. py:method:: get_sensitivity_tnp(transmission_map, pfa=0.046, pdet=0.9) .. py:data:: massq2sr .. py:data:: sr2massq .. py:function:: e2ph(energy, wl) .. py:function:: ph2e(nphot, wl) .. py:function:: whitened_kiout(self) .. py:function:: residual_pdet_Te(lamb, xsi, rank, targ) Computes the residual of Pdet **Arguments:** * lamb : The noncentrality parameter representing the feature * targ : The target Pdet to converge to * xsi : The location of threshold * rank : The rank of observable **Returns** the Pdet difference. See *Ceau et al. 2019* for more information