Metadata-Version: 2.1
Name: pulse_deadtime_fix
Version: 0.1
Summary: Fix dead time distortion of pulse profiles
Author-email: Matteo B <matteo@matteobachetti.it>
License: Copyright (c) 2024, Matteo B
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without modification,
        are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright notice, this
          list of conditions and the following disclaimer in the documentation and/or
          other materials provided with the distribution.
        * Neither the name of the Astropy Team nor the names of its contributors may be
          used to endorse or promote products derived from this software without
          specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
        ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
        ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
        SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: repository, https://github.com/matteobachetti/pulse_deadtime_fix
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
Requires-Dist: numpy
Requires-Dist: astropy
Requires-Dist: stingray
Requires-Dist: numba
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-doctestplus; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-automodapi; extra == "docs"

Fix dead time distortion of pulse profiles
------------------------------------------

.. image:: docs/images/simulate_corr.jpg

Installation
------------

.. code-block::

    pip install pulse_deadtime_fix

Or, to install the development version

.. code-block::

    pip install git+https://github.com/matteobachetti/pulse_deadtime_fix.git

Usage
-----

Here is a simple example of how to correct the dead time distortion of a pulse profile.
The data in the example are from the Crab pulsar, observed with NuSTAR (ObsID 10302001004).

Note: **This technique will not work if the FITS event list does not have a PRIOR column indicating the livetime since the last event**.

The following ephemeris from the Jodrell Bank Observatory is used to fold the data:

.. code-block::

    PSRJ            J0534+2200
    RAJ             05:34:31.973
    DECJ            +22:00:52.06
    PEPOCH           58011.000000379725
    F0               29.6384226073
    F1               -3.6865813e-10
    F2               9.171123484933526e-21
    TZRMJD           58012.000000349
    TZRSITE          0
    TZRFRQ          0
    EPHEM           DE200
    UNITS           TDB
    CLK             TT(TAI)


At this point, it is sufficient to calculate the folded profile as follows:

.. code-block::python

    from pulse_deadtime_fix.core import fold_and_correct_profile
    from stingray import EventList

    ev = EventList.read("nu10302001004A01_bary.evt", additional_columns=["prior"], fmt="hea")
    phas, prof_raw, prof_corr = fold_and_correct_profile(
        ev.time,
        ev.prior,
        (58011.000000379725 - ev.mjdref) * 86400,
        [29.6384226073, -3.6865813e-10, 9.171123484933526e-21]
    )

And the comparison between the raw and the corrected profile (in arbitrary units) is:

.. image:: docs/images/crab_deadtime_corr.jpg


License
-------

This project is Copyright (c) Matteo B and licensed under
the terms of the BSD 3-Clause license. This package is based upon
the `Openastronomy packaging guide <https://github.com/OpenAstronomy/packaging-guide>`_
which is licensed under the BSD 3-clause licence. See the licenses folder for
more information.

Contributing
------------

We love contributions! pulse_deadtime_fix is open source,
built on open source, and we'd love to have you hang out in our community.

**Imposter syndrome disclaimer**: We want your help. No, really.

There may be a little voice inside your head that is telling you that you're not
ready to be an open source contributor; that your skills aren't nearly good
enough to contribute. What could you possibly offer a project like this one?

We assure you - the little voice in your head is wrong. If you can write code at
all, you can contribute code to open source. Contributing to open source
projects is a fantastic way to advance one's coding skills. Writing perfect code
isn't the measure of a good developer (that would disqualify all of us!); it's
trying to create something, making mistakes, and learning from those
mistakes. That's how we all improve, and we are happy to help others learn.

Being an open source contributor doesn't just mean writing code, either. You can
help out by writing documentation, tests, or even giving feedback about the
project (and yes - that includes giving feedback about the contribution
process). Some of these contributions may be the most valuable to the project as
a whole, because you're coming to the project with fresh eyes, so you can see
the errors and assumptions that seasoned contributors have glossed over.

Note: This disclaimer was originally written by
`Adrienne Lowe <https://github.com/adriennefriend>`_ for a
`PyCon talk <https://www.youtube.com/watch?v=6Uj746j9Heo>`_, and was adapted by
pulse_deadtime_fix based on its use in the README file for the
`MetPy project <https://github.com/Unidata/MetPy>`_.
