Skip to content

Commit

Permalink
add example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
robelgeda committed Oct 30, 2024
1 parent ecfe310 commit 5bfe5b4
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,77 @@ for installation instructions and a guide to the ``petrofit`` module.

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

You can install PetroFit using ``pip install petrofit``. Please see
the `petrofit documentation <https://petrofit.readthedocs.io/en/latest/>`_ for detailed installation instructions.

Examples
--------

Please see the `petrofit documentation <https://petrofit.readthedocs.io/en/latest/>`_
for detailed examples, a quick stat guide and instructions.

**Photometry and Petrosian**:

Given a 2D image (`image`) the following code snippet demonstrates how to create a Petrosian profile:

.. code-block:: python
import petrofit as pf
# Make a segmentation map and catalog using Photutils wrapper
cat, segm, segm_deblend = pf.make_catalog(
image,
threshold=image.std()*3,
wcs=None, deblend=True,
npixels=npixels, nlevels=30, contrast=0.001,
)
# Photomerty on first source in catalog
r_list = pf.make_radius_list(max_pix=50, n=50)
flux_arr, area_arr, error_arr = pf.source_photometry(
cat[0], # Source (`photutils.segmentation.catalog.SourceCatalog`)
image, # Image as 2D array
segm_deblend, # Deblended segmentation map of image
r_list, # list of aperture radii
cutout_size=max(r_list)*2, # Cutout out size, set to double the max radius
)
# Make a Petrosian profile
p = pf.Petrosian(r_list, area_arr, flux_arr)
print("{:0.4f} pix".format(p.r_half_light))
**Image Fitting**:

PetroFit can be used with ``astropy`` models to fit psf convolved galaxy light profiles. Given a 2D image (``image``) and a psf (``PSF``), the following code snippet demonstrates how to fit a Sérsic model to the image:

.. code-block:: python
import petrofit as pf
from astropy.modeling import models
sersic_model = models.Sersic2D(
amplitude=1,
r_eff=10,
n=4,
x_0=0, y_0=0,
ellip=0.2,
theta=25,
bounds = pf.get_default_sersic_bounds(),
)
psf_sersic_model = pf.PSFConvolvedModel2D(
sersic_model, psf=PSF, oversample=4, psf_oversample=1
)
fitted_model, fit_info = pf.fit_model(
image, psf_sersic_model,
)
Citation
--------

Please see the `petrofit documentation <https://petrofit.readthedocs.io/en/latest/>`_
for citation instructions. This information is also available in the `CITATION.rst``
file in the PetroFit repo.
Expand Down

0 comments on commit 5bfe5b4

Please sign in to comment.