# contbin_python
This is a python re-implementation of the Jeremy Sanders contour binning algorithm, which was originally in c++. You can install it with `pip install pycontbin`, or upgrade it with `pip install --upgrade pycontbin`. Please note that this python build is under development and is subject to updates.
You can see the original C++ files here: https://github.com/jeremysanders/contbin
Original Copyright Jeremy Sanders <jeremy@jeremysanders.net> (2002-2016)
The reference paper is Sanders (2006), MNRAS, 371, 829,
http://adsabs.harvard.edu/abs/2006MNRAS.371..829S
This version was translated to python by me, and might still contain some minor bugs, although the current implementation results seem to reproduce the original code results.
I have additionally added a routine that automatically produces and outputs polygon region files for each bin in sexagesimal coordinates, this is an improvement on the previous work that output many box regions instead.
Update 17/Feb/2025 - I have added a new routine that takes a 'psf_arcsec' parameter as input. Using the WCS header information, it calculates how many pixels corresponds to this psf, then uses it as a constraint to increase the size of bins that fall underneath the psf size. For bins which are smaller than the psf, the routine goes pixel by pixel and reassigns the pixels to neighboring bins that have a similar smoothed flux. If psf_arcsec is equal to or less than 0, the routine skips this additional psf constraint on the bin size and returns the default map.
The jupyter notebook contains the testing code, also an example use case.
This software is licensed under the GNU Public License.
To do:
- Instead of a static PSF, it would be nice to feed a psf map and have more adaptive psf constraints for each bin.
- Adding GPU optimization would be wonderful.
Done:
- An static PSF constraint has been added to the code. Regions with height and width smaller than the given psf will be merged with neighboring bins until all bins are larger than the psf.
- Added polygon regions as output in sexagesimal coordinates, however this requires ciao and pyds9 installed.
- Created pip package
## Requirements
- numpy
- astropy
- ciao
- pyds9
## Code use case example:
```
# from contour_binning import *
from pycontbin import ContourBin
os.chdir("/Users/jpbreuer/Scripts/contbin-python")
inputfile = "scaled_fluxed_sps_filth_fov.fits"
sn_ratio = 50
smooth = 30
constrain_val = 1.5
reg_bin = 1
psf_arcsec = 10
ContourBin(inputfile, sn_ratio, smooth, constrain_val, reg_bin, make_region_files=True, psf=psf_arcsec)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/jpbreuer/contbin_python",
"name": "pycontbin",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Jean-Paul Breuer",
"author_email": "jeanpaul.breuer@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/bc/d7/d7cc8384a5841f8947ff242fbdd2ae54d0baed858b528dcee4599a19bbe3/pycontbin-0.3.0.tar.gz",
"platform": null,
"description": "# contbin_python\n\nThis is a python re-implementation of the Jeremy Sanders contour binning algorithm, which was originally in c++. You can install it with `pip install pycontbin`, or upgrade it with `pip install --upgrade pycontbin`. Please note that this python build is under development and is subject to updates.\n\nYou can see the original C++ files here: https://github.com/jeremysanders/contbin\n\nOriginal Copyright Jeremy Sanders <jeremy@jeremysanders.net> (2002-2016)\nThe reference paper is Sanders (2006), MNRAS, 371, 829,\nhttp://adsabs.harvard.edu/abs/2006MNRAS.371..829S\n\nThis version was translated to python by me, and might still contain some minor bugs, although the current implementation results seem to reproduce the original code results.\n\nI have additionally added a routine that automatically produces and outputs polygon region files for each bin in sexagesimal coordinates, this is an improvement on the previous work that output many box regions instead.\n\nUpdate 17/Feb/2025 - I have added a new routine that takes a 'psf_arcsec' parameter as input. Using the WCS header information, it calculates how many pixels corresponds to this psf, then uses it as a constraint to increase the size of bins that fall underneath the psf size. For bins which are smaller than the psf, the routine goes pixel by pixel and reassigns the pixels to neighboring bins that have a similar smoothed flux. If psf_arcsec is equal to or less than 0, the routine skips this additional psf constraint on the bin size and returns the default map.\n\nThe jupyter notebook contains the testing code, also an example use case.\n\nThis software is licensed under the GNU Public License.\n\nTo do:\n- Instead of a static PSF, it would be nice to feed a psf map and have more adaptive psf constraints for each bin.\n- Adding GPU optimization would be wonderful.\n\nDone:\n- An static PSF constraint has been added to the code. Regions with height and width smaller than the given psf will be merged with neighboring bins until all bins are larger than the psf.\n- Added polygon regions as output in sexagesimal coordinates, however this requires ciao and pyds9 installed.\n- Created pip package\n\n## Requirements \n- numpy\n- astropy\n- ciao\n- pyds9\n\n## Code use case example:\n```\n# from contour_binning import *\nfrom pycontbin import ContourBin\n\nos.chdir(\"/Users/jpbreuer/Scripts/contbin-python\")\ninputfile = \"scaled_fluxed_sps_filth_fov.fits\"\n\nsn_ratio = 50\nsmooth = 30\nconstrain_val = 1.5\nreg_bin = 1\npsf_arcsec = 10\n\nContourBin(inputfile, sn_ratio, smooth, constrain_val, reg_bin, make_region_files=True, psf=psf_arcsec)\n```\n",
"bugtrack_url": null,
"license": "GNU General Public License v3 (GPLv3)",
"summary": "A Python implementation of the ContBin algorithm",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/jpbreuer/contbin_python"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "71e74f1fe7b3eb9915332d472f65f510b3dbe77e61cf7dc162a824efc4c10bf1",
"md5": "e5d3c173928db6ba8ddd7288dfb2a377",
"sha256": "c05fbc788c1fcd3f8240a3b4b7300cef5628e3f1fb7390df39fc14c238a0db32"
},
"downloads": -1,
"filename": "pycontbin-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e5d3c173928db6ba8ddd7288dfb2a377",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 26927,
"upload_time": "2025-02-17T10:21:11",
"upload_time_iso_8601": "2025-02-17T10:21:11.106071Z",
"url": "https://files.pythonhosted.org/packages/71/e7/4f1fe7b3eb9915332d472f65f510b3dbe77e61cf7dc162a824efc4c10bf1/pycontbin-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "bcd7d7cc8384a5841f8947ff242fbdd2ae54d0baed858b528dcee4599a19bbe3",
"md5": "ffa6c3e71b7ee5aef8ae0ebe8ae59c2d",
"sha256": "b9c309a42daa520077c584a126ec87ca34a6ca2acef1c2583e3f70e9938e3205"
},
"downloads": -1,
"filename": "pycontbin-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "ffa6c3e71b7ee5aef8ae0ebe8ae59c2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 28003,
"upload_time": "2025-02-17T10:21:13",
"upload_time_iso_8601": "2025-02-17T10:21:13.170524Z",
"url": "https://files.pythonhosted.org/packages/bc/d7/d7cc8384a5841f8947ff242fbdd2ae54d0baed858b528dcee4599a19bbe3/pycontbin-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-17 10:21:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jpbreuer",
"github_project": "contbin_python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pycontbin"
}