webbpsf-ext


Namewebbpsf-ext JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/JarronL/webbpsf_ext
SummaryWebbPSF Extensions
upload_time2024-05-14 03:19:53
maintainerNone
docs_urlNone
authorJarron Leisenring
requires_pythonNone
licenseMIT license
keywords jwst psf nircam miri simulation
VCS
bugtrack_url
requirements astropy astroquery matplotlib numpy synphot stsynphot scipy tqdm pysiaf poppy webbpsf
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WebbPSF Extensions

## Extending JWST PSF generation

[![PyPI Version](https://img.shields.io/pypi/v/webbpsf_ext.svg)](https://pypi.python.org/pypi/webbpsf_ext)

*Authors*: Jarron Leisenring (U. of Arizona, Steward Observatory)

`webbpsf_ext` provides some enhancements to the [WebbPSF](https://webbpsf.readthedocs.io) package for PSF creation. This follows the [pyNRC](https://github.com/JarronL/pynrc) implementation for storing and retrieving JWST PSFs. In particular, this module generates and saves polynomial coefficients to quickly create unique instrument PSFs as a function of wavelength, focal plane position, and wavefront error drift from thermal distortions.

More specifically, `webbpsf_ext` uses WebbPSF to generate a series of monochromatic PSF simulations, then produces polynomial fits to each pixel. Storing the coefficients rather than a library of PSFS allows for quick creation (via matrix multiplication) of PSF images for an arbitrary number of wavelengths (subject to hardware memory limitations). The applications range from quickly creating PSFs for many different stellar types over wide bandpasses to generating a large number of monochromatic PSFs for spectral dispersion.

In addition, each science instrument PSF is dependent on the detector position due to field-dependent wavefront errors. Such changes are tracked in WebbPSF, but it becomes burdensome to generate new PSFs from scratch at each location, especially for large starfields. Instead, these changes can be stored by the fitting the residuals of the PSF coefficients across an instrument's field of view, then interpolating for an arbitrary location. A similar scheme can be achieved for coronagraphic occulters, where the PSF changes as the source position moves with respect to the mask.

JWST's thermal evolution (e.g., changing the angle of the sunshield after slewing to a new target) causes small but significant distortions to the telescope backplane. WebbPSF has tools to modify OPDs, but high-fidelity simulations take time to calculate. Since the change to the PSF coefficients varies smoothly with respect to WFE drift components, it's simple to parameterize the coefficient residuals in a fashion similar to the field-dependence.

## `webbpsf_ext` classes

Currently, only NIRCam and MIRI instrument classes are supported via the `NIRCam_ext` and `MIRI_ext` objects (although other instruments can be similarly implemented), which subclass the native `NIRCam` and `MIRI` objects found in WebbPSF. The key functions to call and generate PSF coefficients are:

1. `gen_psf_coeff`: Creates a set of coefficients that will generate simulated PSFs for any arbitrary wavelength. This function first simulates a number of evenly- spaced PSFs throughout the specified bandpass (or the full channel).  An nth-degree polynomial is then fit to each oversampled pixel using  a linear-least squares fitting routine. The final set of coefficients  for each pixel is returned as an image cube. The returned set of  coefficient are then used to produce PSF via `calc_psf_from_coeff`. Useful for quickly generated imaging and dispersed PSFs for multiple spectral types.
1. `gen_wfedrift_coeff`: This function finds a relationship between PSF coefficients in the presence of WFE drift. For a series of WFE drift values, we generate corresponding PSF coefficients and fit a polynomial relationship to the residual values. This allows us to quickly modify a nominal set of PSF image coefficients to generate a new PSF where the WFE has drifted by some amplitude.
1. `gen_wfefield_coeff`: Science instruments generally have field-dependent wavefront errors, which have been carefully measured in ground-based cryovac test campaigns ([SI WFE](https://webbpsf.readthedocs.io/en/latest/jwst.html#si-wfe)). These aberrations are expected to be static throughout the JWST mission lifetime. Similar to the above function, we generate PSF coefficients at each of the sampled positions and create a `RegularGridInterpolator` function to quickly determine new coefficient residuals at arbitrary locations.
1. `gen_wfemask_coeff`: For coronagraphic masks, slight changes in the PSF location relative to the image plane mask can substantially alter the PSF speckle pattern. This function generates a number of PSF coefficients at a variety of positions, then fits polynomials to the residuals to track how the PSF changes across the mask's field of view. Special care is taken near the 10-20mas region in order to provide accurate sampling of the SGD offsets.

## Installing with pip

Download via pip:

```bash
pip install webbpsf_ext
```

## Installing from source

To get the most up to date version of `webbpsf_ext`, install directly from the GitHub source.

In this case, you will need to clone the git repository:

```bash
git clone https://github.com/JarronL/webbpsf_ext
```

Then install the package with:

```bash
cd webbpsf_ext
pip install .
```

For development purposes, you can use editable installations:

```bash
cd webbpsf_ext
pip install -e .
```

This is useful for helping to develop the code, creating bug reports, switching between branches and submitting pull requests to GitHub. Since the code then lives in your local GitHub directory, this method makes it simple to pull the latest updates straight from the GitHub repo, which are then immediately available to python at runtime without needing to reinstall.

## Create Data Directory

You can define the directory that stores the PSF coefficients by setting the environment variable `WEBBPSF_EXT_PATH` to point to some data directory. All PSF coefficients will be saved here as they are generated to be reused later. For example, in `.bashrc` shell file, add:

```bash
export WEBBPSF_EXT_PATH='$HOME/data/webbpsf_ext_data/'
```

If this is not set, then a `psf_coeff` sub-directory is created in the already existing `WEBBPSF_PATH` directory.

## Synphot Data Directory

If you have not already done so, you will need to provide a data files for the required `synphot` and `stsynphot` packages . These are used to generate the monochromatic PSFs and to calculate the throughput of the instrument. Data files for Synphot are distributed through the
[Calibration Reference Data System](https://www.stsci.edu/hst/instrumentation/reference-data-for-calibration-and-tools). They are expected to follow a certain directory structure under the root directory, identified by the ``PYSYN_CDBS`` environment variable that *must* be
set prior to using this package.

1. Download [cdbs.tar.gz](https://arizona.box.com/shared/static/cbkxlwvokml7n1gref8nw3neg98kzcwn.gz) [approx. 900 MB] to obtain the full set of Synphot data files. Or download a minimum subset of files [here](https://arizona.box.com/shared/static/wgq7ymqsp8e7jfno8yk6o2igbnqlad8z.zip) [approx 50 MB].
2. Untar into a directory of your choosing.
3. Set the environment variable ``PYSYN_CDBS`` to point to that directory. For example, in .bashrc shell file, add:

```bash
export PYSYN_CDBS='$HOME/data/cdbs/'
```

After re-sourcing your shell, you should now be able to successfully ``import synphot, stsynphot`` in a Python session.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JarronL/webbpsf_ext",
    "name": "webbpsf-ext",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "jwst psf nircam miri simulation",
    "author": "Jarron Leisenring",
    "author_email": "jarronl@arizona.edu",
    "download_url": "https://files.pythonhosted.org/packages/b2/50/925dd60c62ebb9548567039e71d937042cfd29df4b57e0f278c7db5f474d/webbpsf_ext-1.2.1.tar.gz",
    "platform": null,
    "description": "# WebbPSF Extensions\n\n## Extending JWST PSF generation\n\n[![PyPI Version](https://img.shields.io/pypi/v/webbpsf_ext.svg)](https://pypi.python.org/pypi/webbpsf_ext)\n\n*Authors*: Jarron Leisenring (U. of Arizona, Steward Observatory)\n\n`webbpsf_ext` provides some enhancements to the [WebbPSF](https://webbpsf.readthedocs.io) package for PSF creation. This follows the [pyNRC](https://github.com/JarronL/pynrc) implementation for storing and retrieving JWST PSFs. In particular, this module generates and saves polynomial coefficients to quickly create unique instrument PSFs as a function of wavelength, focal plane position, and wavefront error drift from thermal distortions.\n\nMore specifically, `webbpsf_ext` uses WebbPSF to generate a series of monochromatic PSF simulations, then produces polynomial fits to each pixel. Storing the coefficients rather than a library of PSFS allows for quick creation (via matrix multiplication) of PSF images for an arbitrary number of wavelengths (subject to hardware memory limitations). The applications range from quickly creating PSFs for many different stellar types over wide bandpasses to generating a large number of monochromatic PSFs for spectral dispersion.\n\nIn addition, each science instrument PSF is dependent on the detector position due to field-dependent wavefront errors. Such changes are tracked in WebbPSF, but it becomes burdensome to generate new PSFs from scratch at each location, especially for large starfields. Instead, these changes can be stored by the fitting the residuals of the PSF coefficients across an instrument's field of view, then interpolating for an arbitrary location. A similar scheme can be achieved for coronagraphic occulters, where the PSF changes as the source position moves with respect to the mask.\n\nJWST's thermal evolution (e.g., changing the angle of the sunshield after slewing to a new target) causes small but significant distortions to the telescope backplane. WebbPSF has tools to modify OPDs, but high-fidelity simulations take time to calculate. Since the change to the PSF coefficients varies smoothly with respect to WFE drift components, it's simple to parameterize the coefficient residuals in a fashion similar to the field-dependence.\n\n## `webbpsf_ext` classes\n\nCurrently, only NIRCam and MIRI instrument classes are supported via the `NIRCam_ext` and `MIRI_ext` objects (although other instruments can be similarly implemented), which subclass the native `NIRCam` and `MIRI` objects found in WebbPSF. The key functions to call and generate PSF coefficients are:\n\n1. `gen_psf_coeff`: Creates a set of coefficients that will generate simulated PSFs for any arbitrary wavelength. This function first simulates a number of evenly- spaced PSFs throughout the specified bandpass (or the full channel).  An nth-degree polynomial is then fit to each oversampled pixel using  a linear-least squares fitting routine. The final set of coefficients  for each pixel is returned as an image cube. The returned set of  coefficient are then used to produce PSF via `calc_psf_from_coeff`. Useful for quickly generated imaging and dispersed PSFs for multiple spectral types.\n1. `gen_wfedrift_coeff`: This function finds a relationship between PSF coefficients in the presence of WFE drift. For a series of WFE drift values, we generate corresponding PSF coefficients and fit a polynomial relationship to the residual values. This allows us to quickly modify a nominal set of PSF image coefficients to generate a new PSF where the WFE has drifted by some amplitude.\n1. `gen_wfefield_coeff`: Science instruments generally have field-dependent wavefront errors, which have been carefully measured in ground-based cryovac test campaigns ([SI WFE](https://webbpsf.readthedocs.io/en/latest/jwst.html#si-wfe)). These aberrations are expected to be static throughout the JWST mission lifetime. Similar to the above function, we generate PSF coefficients at each of the sampled positions and create a `RegularGridInterpolator` function to quickly determine new coefficient residuals at arbitrary locations.\n1. `gen_wfemask_coeff`: For coronagraphic masks, slight changes in the PSF location relative to the image plane mask can substantially alter the PSF speckle pattern. This function generates a number of PSF coefficients at a variety of positions, then fits polynomials to the residuals to track how the PSF changes across the mask's field of view. Special care is taken near the 10-20mas region in order to provide accurate sampling of the SGD offsets.\n\n## Installing with pip\n\nDownload via pip:\n\n```bash\npip install webbpsf_ext\n```\n\n## Installing from source\n\nTo get the most up to date version of `webbpsf_ext`, install directly from the GitHub source.\n\nIn this case, you will need to clone the git repository:\n\n```bash\ngit clone https://github.com/JarronL/webbpsf_ext\n```\n\nThen install the package with:\n\n```bash\ncd webbpsf_ext\npip install .\n```\n\nFor development purposes, you can use editable installations:\n\n```bash\ncd webbpsf_ext\npip install -e .\n```\n\nThis is useful for helping to develop the code, creating bug reports, switching between branches and submitting pull requests to GitHub. Since the code then lives in your local GitHub directory, this method makes it simple to pull the latest updates straight from the GitHub repo, which are then immediately available to python at runtime without needing to reinstall.\n\n## Create Data Directory\n\nYou can define the directory that stores the PSF coefficients by setting the environment variable `WEBBPSF_EXT_PATH` to point to some data directory. All PSF coefficients will be saved here as they are generated to be reused later. For example, in `.bashrc` shell file, add:\n\n```bash\nexport WEBBPSF_EXT_PATH='$HOME/data/webbpsf_ext_data/'\n```\n\nIf this is not set, then a `psf_coeff` sub-directory is created in the already existing `WEBBPSF_PATH` directory.\n\n## Synphot Data Directory\n\nIf you have not already done so, you will need to provide a data files for the required `synphot` and `stsynphot` packages . These are used to generate the monochromatic PSFs and to calculate the throughput of the instrument. Data files for Synphot are distributed through the\n[Calibration Reference Data System](https://www.stsci.edu/hst/instrumentation/reference-data-for-calibration-and-tools). They are expected to follow a certain directory structure under the root directory, identified by the ``PYSYN_CDBS`` environment variable that *must* be\nset prior to using this package.\n\n1. Download [cdbs.tar.gz](https://arizona.box.com/shared/static/cbkxlwvokml7n1gref8nw3neg98kzcwn.gz) [approx. 900 MB] to obtain the full set of Synphot data files. Or download a minimum subset of files [here](https://arizona.box.com/shared/static/wgq7ymqsp8e7jfno8yk6o2igbnqlad8z.zip) [approx 50 MB].\n2. Untar into a directory of your choosing.\n3. Set the environment variable ``PYSYN_CDBS`` to point to that directory. For example, in .bashrc shell file, add:\n\n```bash\nexport PYSYN_CDBS='$HOME/data/cdbs/'\n```\n\nAfter re-sourcing your shell, you should now be able to successfully ``import synphot, stsynphot`` in a Python session.\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "WebbPSF Extensions",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/JarronL/webbpsf_ext"
    },
    "split_keywords": [
        "jwst",
        "psf",
        "nircam",
        "miri",
        "simulation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6bfe570ce86068018acb66d743c3358bd4422af72b2dad3911bfce0253b898b",
                "md5": "4574a14f8c750e44fd789019e7f0fdcc",
                "sha256": "d56aabc6014029e209b8602e48936c29c4febfdb32877b78ac52f4b3781b203a"
            },
            "downloads": -1,
            "filename": "webbpsf_ext-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4574a14f8c750e44fd789019e7f0fdcc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8765314,
            "upload_time": "2024-05-14T03:19:30",
            "upload_time_iso_8601": "2024-05-14T03:19:30.923316Z",
            "url": "https://files.pythonhosted.org/packages/c6/bf/e570ce86068018acb66d743c3358bd4422af72b2dad3911bfce0253b898b/webbpsf_ext-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b250925dd60c62ebb9548567039e71d937042cfd29df4b57e0f278c7db5f474d",
                "md5": "2e58051798031dac0f6434c8931a120e",
                "sha256": "9a2dbf2d9531bc0ef5987b6dc15e4c90cb4f32467f5fe2256d111d8c858f2a83"
            },
            "downloads": -1,
            "filename": "webbpsf_ext-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2e58051798031dac0f6434c8931a120e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8291543,
            "upload_time": "2024-05-14T03:19:53",
            "upload_time_iso_8601": "2024-05-14T03:19:53.147025Z",
            "url": "https://files.pythonhosted.org/packages/b2/50/925dd60c62ebb9548567039e71d937042cfd29df4b57e0f278c7db5f474d/webbpsf_ext-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 03:19:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JarronL",
    "github_project": "webbpsf_ext",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "astropy",
            "specs": []
        },
        {
            "name": "astroquery",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "3.7.1"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "synphot",
            "specs": []
        },
        {
            "name": "stsynphot",
            "specs": []
        },
        {
            "name": "scipy",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "pysiaf",
            "specs": []
        },
        {
            "name": "poppy",
            "specs": []
        },
        {
            "name": "webbpsf",
            "specs": []
        }
    ],
    "lcname": "webbpsf-ext"
}
        
Elapsed time: 0.32981s