Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point sources in oversampled images are MUCH more centrally-concentrated than the model PSF #142

Closed
benw1 opened this issue Sep 7, 2021 · 222 comments · Fixed by #156
Closed
Assignees
Milestone

Comments

@benw1
Copy link
Collaborator

benw1 commented Sep 7, 2021

For example, if we compare an oversample=10 image to the output model PSF file:

  • The F062 model PSF shows an average central brightness of about 0.32, and average of 0.08 at +/- 1 pixel in X or Y, for a ratio of ~4:1 peak to adjacent pixels. The simulated image with oversample=10 nearest chip center shows a central pixel brightness of 161000 counts above background, while the four adjacent pixels have an average brightness of 12000 counts above background, for a ratio of ~13:1. This is vastly more centrally concentrated than the model.
  • The F184 model PSF shows a central brightness of about 0.18, and average of 0.07 at +/- 1 pixel in X or Y, for a ratio of ~2.5:1 peak to adjacent pixels. The simulated image with oversample=10 nearest chip center shows a central pixel brightness of 22000 counts above background, while the four adjacent pixels have an average brightness of 3000 counts above background, for a ratio of ~7:1. The extreme central concentration seen in the oversample=10 examples shown here are seen in all six filters.

Thus, there appears to be a problem in the routines that are adding the PSF to the pixel grid when oversampling.

@york-stsci
Copy link
Collaborator

There is currently active PSF development happening on a branch of my fork of STIPS. Note that this development is happening under the 2.x.y version line because it will be making substantial changes to the way that STIPS works in general. If you would like to see how things are going there, or test that work in development, please look at the psf_dev branch at https://github.com/york-stsci/STScI-STIPS-1/tree/psf_dev.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 9, 2021

Glad to know you're working on this. Thanks! I'll try that version and see if it looks better.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 9, 2021

When I run python setup.py install, at the end I get
Finished processing dependencies for stips==1.0.8
Is there a way to be sure I've got the correct version?

@benw1
Copy link
Collaborator Author

benw1 commented Sep 9, 2021

I'm also getting an error on import

import stips
WARNING: LOCAL JWST PRD VERSION PRDOPSSOC-034 DOESN'T MATCH THE CURRENT ONLINE VERSION PRDOPSSOC-036
Please consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf
Traceback (most recent call last):
File "", line 1, in
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/init.py", line 10, in
from .observation_module import ObservationModule
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/observation_module/init.py", line 3, in
from .observation_module import ObservationModule
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/observation_module/observation_module.py", line 7, in
from ..astro_image import AstroImage
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/astro_image/init.py", line 4, in
from .astro_image import AstroImage
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/astro_image/astro_image.py", line 30, in
from ..utilities import apply_ipc
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/utilities/init.py", line 4, in
from .utilities import StipsEnvironment
File "/nobackupp11/bwilli24/STScI-STIPS-1/stips/utilities/utilities.py", line 651
elif use_cwd and (conf := GetConfigFile("cwd")) is not None:
^
SyntaxError: invalid syntax

@york-stsci
Copy link
Collaborator

That's my mistake. I forgot to update the required python version to 3.8. I should have an updated version of STIPS ready later this afternoon, but meanwhile if you install it on python 3.8 or higher it will work fine. I've also fixed that the version was being reported as 1.0.8 in setup.py and 2.0.0 in version.py, which is helpful to no one.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 14, 2021

Thanks! When I attempt to update to 3.8, I get the following:
The following packages will be REMOVED:

esutil-0.6.4-py37hb3f55d8_0
healpy-1.13.0-py37hf476568_1
imagecodecs-lite-2019.12.3-py37h03ebfcd_1
jwxml-0.3.0-py37_1
photutils-0.7.2-py37h516909a_1
poppy-0.9.0-py37_0
pyfftw-0.12.0-py37hc3ef4f8_1
pysiaf-0.11.0-py37_0
pysynphot-0.9.14-py37_0
python_abi-3.7-1_cp37m
stsci_rtd_theme-0.0.1-py37_0
webbpsf-0.9.0-py37_1

How are you able to get stips to work without these packages? Or do you need to install them by hand after the upgrade?

@benw1
Copy link
Collaborator Author

benw1 commented Sep 15, 2021

The dependencies need to be improved greatly for install. Here's the list I needed to add by hand:
550 pip install photutils
552 pip install scipy
554 pip install webbpsf
558 pip install yaml
561 pip install pyyaml
563 pip install jwst_backgrounds
565 pip install esutil
567 pip install pandeia
570 pip install pandeia.engine

@benw1
Copy link
Collaborator Author

benw1 commented Sep 15, 2021

Also, after a python setup.py install
I only can import stips if I'm in the directory where I ran the install, so something about the install script seems to not be working right:
Finished processing dependencies for stips==1.0.8
Now if I launch python and import stips it works:
(stips2) -bash-4.3$ python
Python 3.8.11 (default, Aug 3 2021, 15:09:35)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

import stips
WARNING: LOCAL JWST PRD VERSION PRDOPSSOC-034 DOESN'T MATCH THE CURRENT ONLINE VERSION PRDOPSSOC-036
Please consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf

Now if I change directories and do the same thing, it doesn't work:
(stips2) -bash-4.3$ cd ..
(stips2) -bash-4.3$ python
Python 3.8.11 (default, Aug 3 2021, 15:09:35)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

import stips
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'stips'

@benw1
Copy link
Collaborator Author

benw1 commented Sep 15, 2021

Looks like it is not properly installing for several reasons:

(stips2) -bash-4.3$ python setup.py install
running install
running bdist_egg
running egg_info
writing stips.egg-info/PKG-INFO
writing dependency_links to stips.egg-info/dependency_links.txt
writing requirements to stips.egg-info/requires.txt
writing top-level names to stips.egg-info/top_level.txt
reading manifest file 'stips.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files found matching '.pyc'
warning: no previously-included files found matching '
.pyo'
warning: no files found matching 'README.rst'
warning: no files found matching 'stips/tests/coveragerc'
warning: no files found matching '.pyx' under directory 'stips'
warning: no files found matching '
.c' under directory 'stips'
warning: no files found matching '.pxd' under directory 'stips'
warning: no files found matching '
' under directory 'cextern'
warning: no files found matching '' under directory 'scripts'
no previously-included directories found matching 'build'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'docs/api'
warning: no previously-included files matching '
.o' found anywhere in distribution
writing manifest file 'stips.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

@york-stsci
Copy link
Collaborator

Okay, it looks like there are two issues here. The first is that I didn't have setup.py actually installing STIPS itself, just its dependencies. I've fixed that. The second issue looks like you're not installing the psf_dev version. After you clone the repository, and before you run setup.py, did you remember to do "git checkout psf_dev" in the cloned directory?

@benw1
Copy link
Collaborator Author

benw1 commented Sep 15, 2021

Thanks!
Looks like I was on the right branch:
(stips2) -bash-4.3$ git checkout psf_dev
Already on 'psf_dev'
Your branch is up to date with 'origin/psf_dev'.
(stips2) -bash-4.3$
But I was behind:
(stips2) -bash-4.3$ git pull
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 29 (delta 16), reused 29 (delta 16), pack-reused 0
Unpacking objects: 100% (29/29), 4.28 KiB | 20.00 KiB/s, done.
From https://github.com/york-stsci/STScI-STIPS-1
de98fae..d4b004a psf_dev -> origin/psf_dev
Updating de98fae..d4b004a
Fast-forward
.github/workflows/ci_workflows.yml | 10 +---------
.gitignore | 3 +++
environment.yml | 2 +-
environment_dev.yml | 2 +-
setup.cfg | 28 +++++++++++++++++++++-------
setup.py | 18 +-----------------
stips/astro_image/astro_image.py | 9 ++++++++-
stips/instruments/instrument.py | 5 ++++-
8 files changed, 40 insertions(+), 37 deletions(-)
(stips2) -bash-4.3$

After updating to the latest version of the branch, it seems to be installing properly!

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

Also, after a python setup.py install
I only can import stips if I'm in the directory where I ran the install, so something about the install script seems to not be working right:
Finished processing dependencies for stips==1.0.8
Now if I launch python and import stips it works:
(stips2) -bash-4.3$ python
Python 3.8.11 (default, Aug 3 2021, 15:09:35)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

import stips
WARNING: LOCAL JWST PRD VERSION PRDOPSSOC-034 DOESN'T MATCH THE CURRENT ONLINE VERSION PRDOPSSOC-036
Please consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf

Now if I change directories and do the same thing, it doesn't work:
(stips2) -bash-4.3$ cd ..
(stips2) -bash-4.3$ python
Python 3.8.11 (default, Aug 3 2021, 15:09:35)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

import stips
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'stips'

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

git pull
12:36
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 29 (delta 16), reused 29 (delta 16), pack-reused 0
Unpacking objects: 100% (29/29), 4.28 KiB | 20.00 KiB/s, done.
From https://github.com/york-stsci/STScI-STIPS-1
de98fae..d4b004a psf_dev -> origin/psf_dev
Updating de98fae..d4b004a
Fast-forward
.github/workflows/ci_workflows.yml | 10 +---------
.gitignore | 3 +++
environment.yml | 2 +-
environment_dev.yml | 2 +-
setup.cfg | 28 +++++++++++++++++++++-------
setup.py | 18 +-----------------
stips/astro_image/astro_image.py | 9 ++++++++-
stips/instruments/instrument.py | 5 ++++-
8 files changed, 40 insertions(+), 37 deletions(-)

Now it installs!

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

However, it is not yet working, because it looks like I need a newer version of pandeia and webbpsf data than linked to the the installation instructions. Can you please point me to the version I need?

If I use the versions of the data files that work with the released version of STIPS, then I get:
pandeia.engine.custom_exceptions.EngineInputError: Missing JSON file: /nobackup/bwilli24/STScI-STIPS/stips_data/pandeia_data-1.5.2rc2_roman/roman/wfi/config.json

@york-stsci
Copy link
Collaborator

I will need to look it up. Meanwhile, try, in python:

from stips.utilities import DownloadReferenceData
DownloadReferenceData()

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

Slick! Thanks for the help. That worked for getting beyond the stips_data error, but now I'm getting something a bit more cryptic about missing a keyword:

File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/observation_module/observation_module.py", line 228, in nextObservation
self.instrument.reset(ra, dec, pa, filter, self.obs_count)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 178, in reset
self.resetDetectors(psf=psf)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 203, in resetDetectors
detector = AstroImage(parent=self, ra=ra, dec=dec, pa=pa, psf=psf,
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 79, in init
self.zeropoint = self.parent.zeropoint
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 1114, in zeropoint
return self.zeropoint_unit.value
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 1131, in zeropoint_unit
bp = self.bandpass
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 1054, in bandpass
i = self.pandeia_instrument
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 1109, in pandeia_instrument
self._instrument = InstrumentFactory(config=conf)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument_factory.py", line 50, in InstrumentFactory
cls = inst_map[instrument](mode=mode, config=config, webapp=webapp, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/roman.py", line 32, in init
Instrument.init(self, telescope=telescope, mode=mode, config=config, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument.py", line 124, in init
self.exposure_spec = self.get_exposure_pars()
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument.py", line 792, in get_exposure_pars
ndrop2 = self.readout_pattern_config[readout_pattern]["ndrop2"]
KeyError: 'ndrop2'

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

My guess is that this may be because it is using pandeia 1.6, but the data from DownloadReferenceData() are pandeia 1.5.2
pandeia_refdata=/nobackup/bwilli24/STScI-STIPS-1/stips_data/pandeia_data-1.5.2rc2_roman

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

Found a promising candidate at:
https://stsci.app.box.com/v/pandeia-refdata-v1p6p2-roman

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

With those data, I now get a new, very similar, error:
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 1109, in pandeia_instrument
self._instrument = InstrumentFactory(config=conf)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument_factory.py", line 50, in InstrumentFactory
cls = inst_map[instrument](mode=mode, config=config, webapp=webapp, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/roman.py", line 32, in init
Instrument.init(self, telescope=telescope, mode=mode, config=config, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument.py", line 124, in init
self.exposure_spec = self.get_exposure_pars()
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/pandeia/engine/instrument.py", line 792, in get_exposure_pars
nskip = self.readout_pattern_config[readout_pattern]["nskip"]
KeyError: 'nskip'

@benw1
Copy link
Collaborator Author

benw1 commented Sep 16, 2021

Ah... It looks like I had pandeia 1.6.2 installed, but STIPS only works with pandeia 1.6.
Now I have pandeia.engine==1.6 installed and the data from
https://stsci.app.box.com/v/pandeia-refdata-v1p6-roman
and it no error yet!

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

Now I'm getting a STIPS error, related to sampling the PSF perhaps...:

2021-09-16 18:20:25,190 WARNING poppy CAUTION: Just interpolating rather than integrating filter profile, over 40 steps
2021-09-16 18:27:25,910 INFO: Calculating PSF at (4092.0,4092.0)
2021-09-16 18:27:25,910 INFO stips Calculating PSF at (4092.0,4092.0)
2021-09-16 18:27:25,910 WARNING poppy Pysynphot unavailable (or invalid source supplied)! Assuming flat # of counts versus wavelength.
2021-09-16 18:27:25,915 WARNING poppy CAUTION: Just interpolating rather than integrating filter profile, over 40 steps
2021-09-16 18:34:23,159 INFO: SCA01: (RA, DEC, PA) := (149.4, 69.2, 0.0), detected as (149.4, 69.2, 0.0)
2021-09-16 18:34:23,159 INFO stips SCA01: (RA, DEC, PA) := (149.4, 69.2, 0.0), detected as (149.4, 69.2, 0.0)
2021-09-16 18:34:23,161 INFO: Detector SCA01 created
2021-09-16 18:34:23,161 INFO stips Detector SCA01 created
2021-09-16 18:34:23,162 INFO: Reset Instrument
2021-09-16 18:34:23,162 INFO stips Reset Instrument
2021-09-16 18:34:23,162 INFO: Running catalogue /nobackupp11/bwilli24/Wpipes2/testgrid92/data/grid.cat/proc_grid_1psf/Mixed_grid_F062.tbl
2021-09-16 18:34:23,162 INFO stips Running catalogue /nobackupp11/bwilli24/Wpipes2/testgrid92/data/grid.cat/proc_grid_1psf/Mixed_grid_F062.tbl
2021-09-16 18:34:23,162 INFO: Adding catalogue /nobackupp11/bwilli24/Wpipes2/testgrid92/data/grid.cat/proc_grid_1psf/Mixed_grid_F062.tbl
2021-09-16 18:34:23,162 INFO stips Adding catalogue /nobackupp11/bwilli24/Wpipes2/testgrid92/data/grid.cat/proc_grid_1psf/Mixed_grid_F062.tbl
2021-09-16 18:34:23,270 INFO: Finished converting catalogue to internal format
2021-09-16 18:34:23,270 INFO stips Finished converting catalogue to internal format
2021-09-16 18:34:23,270 INFO: Adding catalogue to detector SCA01
2021-09-16 18:34:23,270 INFO stips Adding catalogue to detector SCA01
2021-09-16 18:34:23,271 INFO: Adding catalogue Mixed_grid_F062.tbl to AstroImage SCA01
2021-09-16 18:34:23,271 INFO stips Adding catalogue Mixed_grid_F062.tbl to AstroImage SCA01
2021-09-16 18:34:24,785 INFO: Determining pixel co-ordinates
2021-09-16 18:34:24,785 INFO stips Determining pixel co-ordinates
2021-09-16 18:34:24,816 INFO: Keeping 0 items
2021-09-16 18:34:24,816 INFO stips Keeping 0 items
2021-09-16 18:34:25,191 INFO: Determining pixel co-ordinates
2021-09-16 18:34:25,191 INFO stips Determining pixel co-ordinates
2021-09-16 18:34:25,223 INFO: Keeping 5872 items
2021-09-16 18:34:25,223 INFO stips Keeping 5872 items
2021-09-16 18:34:25,297 INFO: Writing 5872 stars
2021-09-16 18:34:25,297 INFO stips Writing 5872 stars
2021-09-16 18:34:25,297 INFO: Adding 5872 point sources to AstroImage SCA01
2021-09-16 18:34:25,297 INFO stips Adding 5872 point sources to AstroImage SCA01
Traceback (most recent call last):
File "build/run_stips.py", line 83, in
run_stips(this_event_id, this_dp_id, float(ra_dither), float(dec_dither))
File "build/run_stips.py", line 55, in run_stips
source_count_catalogues = obm.addCatalogue(str(filename))
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/observation_module/observation_module.py", line 254, in addCatalogue
cats = self.instrument.addCatalogue(catalogue, self.id, *args, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 286, in addCatalogue
cats.append(detector.addCatalogue(cat, dist=self.distortion, *args, **kwargs))
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 595, in addCatalogue
out_chunk = self.addTable(current_chunk, dist, *args, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 532, in addTable
self.addPoints(ids[stars_idx], xs[stars_idx], ys[stars_idx],
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 653, in addPoints
img,ix,iy = self.makePoint(*values, psf_params, self.overrides, self.logger)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 612, in makePoint
psf_img = getReducedPsf(psf_params, x, y)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/utilities/utilities.py", line 953, in getReducedPsf
psf_img = psf_img.reshape(psf_y//os, os, psf_x//os, os).sum(axis=(1, 3))[1:-1,1:-1]
ValueError: cannot reshape array of size 72900 into shape (67,4,67,4)

@york-stsci
Copy link
Collaborator

Okay, I think there are a number of things going on here.

First, DownloadReferenceData() does a few things:

  • It sets up environment variables if they haven't been yet (for all the reference data directories)
  • It looks at the existing reference data directories to see if they exist
  • If they don't exist, it downloads the appropriate data

However, if the directory already exists, it leaves it alone. I'm making a fix so that it will, if possible, look for the version of the data directory, and make sure that it matches the installed data version.

With respect to the other error you ran into, can you please let me know what input parameters you used to get that error?

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

Makes sense. It also only seems to work with pandeia 1.6, not 1.6.2, which is the default that gets installed by pip, so one must install pandeia.engine==1.6.
Here is the code I used to set the parameters:

scene_general = {'ra': 149.4, 'dec': 69.2, 'pa': 0, 'seed': 123}
obs = {'instrument': 'WFI', 'filters': F062, 'detectors': 1, 'distortion': False, 'pupil_mask': '', 'background': 'avg', 'observations_id': 35, 'exptime': 3600, 'offsets': [{'offset_id': 999, 'offset_centre': False, 'offset_ra': 0.0, 'offset_dec': 0.0, 'offset_pa': 0.0}]}
obm = ObservationModule(obs, scene_general=scene_general, psf_grid_size=5, oversample=6)
obm.nextObservation()
source_count_catalogues = obm.addCatalogue('/nobackupp11/bwilli24/Wpipes2/testgrid92/data/grid.cat/proc_grid_1psf/Mixed_grid_F062.tbl')
psf_file = obm.addError()
fits_file, mosaic_file, params = obm.finalize(mosaic=False)

@york-stsci
Copy link
Collaborator

Note that the setup.cfg file specifies that pandeia must be version 1.6, as later versions are not compatible with Roman. I'm not sure how you ended up with a higher version installed if you did setup.py on a clean environment.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

Ah. I was trying all kinds of things to get past that error. I re-installed pandeia several times when I was doing all that, so it may have had the correct version initially, but just the wrong data file. Either way, it does work (other than my current psf error) when both the version and the data are 1.6.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

Interestingly, even though I specified oversample=6, it seems to have produced a psf at oversample 4:
psf_v2.0.0dev_roman_wfi_sca01_f062_over4_grid5_epsf.fits

@york-stsci
Copy link
Collaborator

As far as I can tell, this is a result of the "oversample" keyword being changed to "psf_oversample", because oversampling now applies only to PSF creation, but some parts of the code accepting either 'oversample' or 'psf_oversample'. As a result, when the PSF was created, its oversample was set to the default (4.0), because it didn't recognize the keyword. However, when evaluated, the evaluation function saw 'oversample=6' and tried to bin the generated PSF from an oversample of 6 to 1, which naturally didn't work because the provided PSF wasn't at that binning to begin with.

I think that, if you do a "git pull", you will get revised code that fixes the issue. My tests are still ongoing, but have worked so far. Let me know.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

Thanks! OK, it is now making an oversample=6 psf file:
2021-09-17 12:09:03,380 INFO: PSF File is /nobackup/bwilli24/STScI-STIPS1/stips_data/psf_cache/psf_v2.0.0dev_roman_wfi_sca01_f062_over6_grid5_epsf.fits

However, when it imports I'm getting strange warnings:

import stips
WARNING: LOCAL JWST PRD VERSION PRDOPSSOC-034 DOESN'T MATCH THE CURRENT ONLINE VERSION PRDOPSSOC-039
Please consider updating pysiaf, e.g. pip install --upgrade pysiaf or conda update pysiaf
WARNING: stips: data directory not found.
WARNING: synphot: data directory not found.
WARNING: webbpsf: data directory not found.
WARNING: pandeia: data directory not found.

These are odd because I didn't get them before and those data directories are defined in my environment:

stips_data=/nobackup/bwilli24/STScI-STIPS-1/stips_data
PYSYN_CDBS=/nobackup/bwilli24/STScI-STIPS-1/stips_data/grp/hst/cdbs
WEBBPSF_PATH=/nobackup/bwilli24/STScI-STIPS-1/stips_data/webbpsf-data
pandeia_refdata=/nobackup/bwilli24/STScI-STIPS-1/stips_data/pandeia_data-1.6_roman

In any case, it is running, so we'll see if it generates proper images soon.

@york-stsci
Copy link
Collaborator

So, those reports are, in fact, incorrect, and are caused by a bug in the SetupDataPaths() function that was sometimes reporting directories as not being found even if they existed (this only happened if the environment variable was present, but the configuration file entry for the environment variable had a different name. In any case, there's now a fixed version, but the only effect should be the incorrect warnings being printed out.

@benw1
Copy link
Collaborator Author

benw1 commented Sep 17, 2021

STIPS completes now; however, the image has no background, and the PSF is again far too sharp. Effectively all of the flux of the point sources is contained in a single pixel. Thus, this issue is still present on the psf_dev branch.

I'm guessing the background problem is another missing data issue of some sort, but not sure because the log doesn't mention where it is looking for the background info:
2021-09-17 15:09:01,273 INFO: Adding Error
2021-09-17 15:09:01,273 INFO stips Adding Error
2021-09-17 15:09:01,273 INFO: Adding residual error
2021-09-17 15:09:01,273 INFO stips Adding residual error
2021-09-17 15:09:01,470 INFO: SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:01,470 INFO stips SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:02,338 INFO: SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:02,338 INFO stips SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:02,338 INFO: Created AstroImage SCA01 and imported data from FITS file err_flat_wfi.fits
2021-09-17 15:09:02,338 INFO stips Created AstroImage SCA01 and imported data from FITS file err_flat_wfi.fits
2021-09-17 15:09:02,571 INFO: SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:02,571 INFO stips SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:03,569 INFO: SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:03,569 INFO stips SCA01: (RA, DEC, PA) := (0.0, 0.0, 0.0), detected as (0.0, 0.0, 0.0)
2021-09-17 15:09:03,569 INFO: Created AstroImage SCA01 and imported data from FITS file err_rdrk_wfi.fits
2021-09-17 15:09:03,569 INFO stips Created AstroImage SCA01 and imported data from FITS file err_rdrk_wfi.fits
2021-09-17 15:09:03,585 INFO: Adding error to detector SCA01
2021-09-17 15:09:03,585 INFO stips Adding error to detector SCA01
2021-09-17 15:09:03,585 INFO: Adding background
2021-09-17 15:09:03,585 INFO stips Adding background
2021-09-17 15:09:03,585 INFO: Returning background 0.0.
2021-09-17 15:09:03,585 INFO stips Returning background 0.0.
2021-09-17 15:09:03,585 INFO: Background is 0.0 counts/s/pixel
2021-09-17 15:09:03,585 INFO stips Background is 0.0 counts/s/pixel
2021-09-17 15:09:03,586 INFO: Returning background 0.0.
2021-09-17 15:09:03,586 INFO stips Returning background 0.0.
2021-09-17 15:09:03,586 INFO: Added background of 0.0 counts/s/pixel
2021-09-17 15:09:03,586 INFO stips Added background of 0.0 counts/s/pixel
2021-09-17 15:09:03,610 INFO: Inserting correct exposure time
2021-09-17 15:09:03,610 INFO stips Inserting correct exposure time

@york-stsci
Copy link
Collaborator

I'm not sure what's going on there. I'm going to try a thing where I use GriddedPSFModel for generating a single PSF interpolated from the grid, but then continue to use my existing code for doing the sub-pixel fit.

@york-stsci
Copy link
Collaborator

Try it now.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 21, 2021

I updated, re-installed, and re-ran. The results were nearly identical to the previous version. Center in essentially the same place (within a couple of hundredths of a pixel, probably due to the different noise).

@york-stsci
Copy link
Collaborator

Thank you.

Is there any chance that I could be doing one or more of flipping this array (horizontally or vertically), or transposing the axes, or something like that? The main reason I'm asking is that when I feed in the array of input points I get out a 1d array of values, and I have to reshape it myself. I'm obviously not doing it completely incorrectly, but it's entirely possible I'm making some sort of mistake.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 21, 2021

The fact that the center appears to be near the top edge of the pixel (y=1338.3 instead of y=1338.1) makes me think something like that could be going on. It doesn't appear to be a transpose or rotation, as the diffraction spikes are the right orientation, but perhaps some kind of an indexing issue in the gridding? One hopefully quick test would be to try generating a PSF in a pixel corner (e.g. 15.6, 24.6) or edge and ensure that the resulting PSF has quite a bit of flux in the central 4 pixels (or in both pixels that border the edge). When I do this by shifting and binning the model PSF, I get the neighboring pixels to be about half the flux of the central pixel.

@york-stsci
Copy link
Collaborator

Try now? I'm building a 2D list, which might have helped?

@benw1
Copy link
Collaborator Author

benw1 commented Oct 22, 2021

Retested... Still essentially the same answer. Have you been able to get an evaluated PSF to come back with the flux of a neighboring pixel only a factor of 2 less than that of the brightest pixel (by putting a star next to a pixel edge)?

@york-stsci
Copy link
Collaborator

I have not. I have very little time to spend on STIPS at all at the moment, and I'm devoting the time I have to trying fixes. That's something that's probably worth working on from your end.

@york-stsci
Copy link
Collaborator

Okay, for testing I've now made it into a parameter. If you add the keyword argument "psf_method", you can choose between psf_method=photutils (which uses GriddedPSFModel.evaluate(), but now also just scales the output PSF so that it always has the same flux as is specified in the input), or psf_method='grid', which uses the RegularGridInterpolator.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 26, 2021

This seems to work reasonably with with psf_method=photutils. My initial test looks good. Working on a full test.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 26, 2021

A question has come up in discussing the latest version with my team PSF photometry expert. The new oversample=10 PSFs are 451x451 resolution, meaning that integrating across the central pixel means that we have to add up the central 9x9 region and somehow figure out how to interpolate the pixels that are half (or one quarter) inside the central pixel. In order to accurately integrate the PSF to get the central flux of a centrally phased star at 10x10 oversampling, the center of the star should be on the corner of four pixels, not centered on the central pixel (which is why previous 10x10 oversampled PSFs always had an even number of pixels on each axis). How do you get around this in your rebidding prior to adding the star to the image? Thanks for any thoughts

@york-stsci
Copy link
Collaborator

This is done entirely deliberately. As I understand it, this has to do with moving STIPS to using an ePSF, which your expert can probably explain to you better than I can. Because this is an intentional choice, it's not something that we're trying to get around. The main thing is that STIPS doesn't re-bin the PSF at all, but instead uses the oversampled PSF as a regular grid and uses interpolation to determine the PSF shape at the appropriate sub-pixel position. I hope that helps.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 28, 2021

Thanks. We can work with that..Another question, concerning the different versions; The extensions appear to have the same basic parameters and formats, but are named orig, orig_ipc, epsf, and epsf_ipc. Do you know which one we should be using to compare with STIPS data?
The EPSF ones appear to have done the pixel integration already, so instead of (for example) averaging the central 5x5 I just would use the central pixel for a center-phased PSF. If IPC also models the sub pixel physics, that would be very attractive. Assuming of course that it’s consistent with STIPS.

@york-stsci
Copy link
Collaborator

When creating PSF models, STIPS follows the following process:

  • For each grid position in the PSF grid, create an odd-parity PSF model at the appropriate oversample
    • That model becomes the "orig" model
    • Apply an IPC kernel to the "orig" model (the kernel is pixel-by-pixel, so for oversample N each pixel is modified by
      the pixels that are N away from them). That becomes the "orig_ipc" model
    • Add pixel integration to the "orig" model. That becomes the "epsf" model
    • Apply the IPC kernel to the "epsf" model. That becomes the "epsf_ipc" model

When STIPS is running, and needs a PSF, iff the "psf_type" configuration is set to "orig", STIPS uses either "orig" or "orig_ipc". If it's set to "epsf", STIPS uses either "epsf" or "epsf_ipc".

When creating a point source, if the "residual_ipc" keyword is True (which it is by default), then the appropriate IPC kernel is used directly. If it isn't, then the non-IPC kernel is used.

When creating a sersic profile, then the non-IPC kernel is always used. After the sersic profile has been generated and convolved with the PSF, if "residual_ipc" is True then the IPC kernel is applied to the entire profile.

@york-stsci
Copy link
Collaborator

I did not generate the IPC kernel, I just wrote a python version of the FORTRAN function that applies it. If there's a better way of applying IPC, I'm happy to do that.

@benw1
Copy link
Collaborator Author

benw1 commented Oct 28, 2021

Thanks! Tow follow ups. What is the default psf_type and where does the IPC kernel you are using come from?

@york-stsci
Copy link
Collaborator

The default is "orig". I'm getting the kernel from an internal simulator that's being developed to help with pipeline development. I don't know where it comes from before that, but can ask.

@benw1
Copy link
Collaborator Author

benw1 commented Nov 23, 2021

I've been working on doing some production runs with this version, and it is unfortunately slow to the point of not being usable. It is taking 2.5 hours to add 100 sersic profiles. Do you know what changed to make it so slow? Do you have suggestions for speeding it up? Here is a snippet from the log:
2021-11-22 16:59:48,299 INFO: Adding 12688 sersic profiles to AstroImage SCA01
2021-11-22 16:59:48,299 INFO stips Adding 12688 sersic profiles to AstroImage SCA01
2021-11-22 16:59:48,307 INFO: Using astropy to model Sersic profiles
2021-11-22 16:59:48,307 INFO stips Using astropy to model Sersic profiles
2021-11-22 19:39:02,969 INFO: Done 100 of 12688
2021-11-22 19:39:02,969 INFO stips Done 100 of 12688
2021-11-22 22:16:46,908 INFO: Done 200 of 12688
2021-11-22 22:16:46,908 INFO stips Done 200 of 12688
2021-11-23 00:54:37,292 INFO: Done 300 of 12688
2021-11-23 00:54:37,292 INFO stips Done 300 of 12688
2021-11-23 03:34:09,926 INFO: Done 400 of 12688
2021-11-23 03:34:09,926 INFO stips Done 400 of 12688
2021-11-23 06:12:42,791 INFO: Done 500 of 12688
2021-11-23 06:12:42,791 INFO stips Done 500 of 12688
2021-11-23 08:50:26,502 INFO: Done 600 of 12688
2021-11-23 08:50:26,502 INFO stips Done 600 of 12688
...

@york-stsci
Copy link
Collaborator

Without knowing what parameters you're using, I can't make suggestions. But yes, there is probably a way to speed it up.

@benw1
Copy link
Collaborator Author

benw1 commented Nov 30, 2021

Thanks! Here are the parameters that I set. Any others would be default.

obs = {'instrument': 'WFI', 'filters': 'F087', 'detectors': 1, 'distortion': False, 'pupil_mask': '', 'observations_id': 16814, 'exptime': 3600, 'offsets': [{'offset_id': 147638, 'offset_centre': False, 'offset_ra': 0.0, 'offset_dec': 0.0, 'offset_pa': 0.0}]}
obm = ObservationModule(obs, scene_general=scene_general, psf_grid_size=5), oversample=5, observation_default_background='avg', random_seed=4563, psf_method="photutils")

@york-stsci
Copy link
Collaborator

I think that the main thing you're running into is that the default method of generating Sersic profiles is "full", which generates each model over the full detector frame. I would recommend adding the following configuration (or keyword arguments):

  • sersic_method='re'
  • sersic_model='pandeia'
  • sersic_value=15.

That will use pandeia to model Sersic profiles (which will avoid having too much flux in the central pixel, as astropy sometimes gives you), and will model each sersic profile out to 15x re instead of over the full frame. That should result in a substantial speed increase.

@benw1
Copy link
Collaborator Author

benw1 commented Nov 30, 2021

Thanks! Is there a way to do something similar to speed up point sources? Those are slow too, so I can't put hundreds of thousands into an image in 24 hours, which means I can't complete within the supercomputer's wall time limit.

@york-stsci
Copy link
Collaborator

The main things that you can do for point sources are

  • reduce psf_fov_pixels (the default is 45)
  • turn off IPC
  • turn on parallel addition of point sources

That said, on my laptop with psf_fov_pixels=65, it takes ~2.5 minutes to add 1000 sources, so 100,000 should take ~4 hours, which seems like it ought to allow for at least a few hundred thousand within 24 hours (and I would hope that a supercomputer is faster than my laptop).

@benw1
Copy link
Collaborator Author

benw1 commented Nov 30, 2021

Thanks! Are the IPC off and parallel addition not the default? Please send the parameter names and if they are set in the obs dictionary or in the ObservationModule.

@york-stsci
Copy link
Collaborator

IPC, like all of the other error residuals, is on by default. It is unlikely to have a significant effect on point source calculation times, but it might have a slight influence. Its keyword is residual_ipc.

Parallel computation is turned off by default because I don't know, in advance, what sort of system STIPS will be run on, and non-parallel will work without side effects regardless of how many cores are present and available. The parallel_enable keyword controls whether parallel computation is enabled, and the parallel_ncores keyword indicates how many simultaneous cores are available to STIPS for a single simulation. If set to 0 (the default value), it will instead use the number of cores detected by python as its number of simultaneous cores available.

@benw1
Copy link
Collaborator Author

benw1 commented Nov 30, 2021

Thanks! I tried this:

ObservationModule(obs, scene_general=scene_general, psf_grid_size=int(my_params['psf_grid']), oversample=int(my_params['oversample']), observation_default_background='avg', random_seed=seed, psf_method="photutils", parallel=True, residual_ipc=False, sersic_method='re', sersic_model='pandeia', sersic_value=15.0)

But get an error concerning "psf_ext":

2021-11-30 13:12:16,840 INFO stips Adding 421 point sources to AstroImage SCA01
Traceback (most recent call last):
File "/nobackupp11/bwilli24/Wpipes2/M81_test8/build/run_stips.py", line 83, in
run_stips(this_event_id, this_dp_id, float(ra_dither), float(dec_dither))
File "/nobackupp11/bwilli24/Wpipes2/M81_test8/build/run_stips.py", line 55, in run_stips
source_count_catalogues = obm.addCatalogue(str(filename))
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/observation_module/observation_module.py", line 254, in addCatalogue
cats = self.instrument.addCatalogue(catalogue, self.id, *args, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/instruments/instrument.py", line 286, in addCatalogue
cats.append(detector.addCatalogue(cat, dist=self.distortion, *args, **kwargs))
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 599, in addCatalogue
out_chunk = self.addTable(current_chunk, dist, *args, **kwargs)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 534, in addTable
self.addPoints(ids[stars_idx], xs[stars_idx], ys[stars_idx],
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 659, in addPoints
img,ix,iy = self.makePoint(*values, psf_params, self.overrides, self.logger)
File "/nobackup/bwilli24/miniconda3/envs/stips2/lib/python3.8/site-packages/stips-2.0.0-py3.8.egg/stips/astro_image/astro_image.py", line 617, in makePoint
psf_params['psf_ext'],
KeyError: 'psf_ext'

Any suggestions for avoiding this error would be greatly appreciated.

@benw1
Copy link
Collaborator Author

benw1 commented Nov 30, 2021

I was able to avoid the error by removing the residual_ipc=False from the call. Since that may not be a major help, it's probably fine for now, but you may want to fix that in case someone wants to turn it off for some other reason. I'm going to try testing on a large star list now. The Sersic profiles are much faster now, completing 100 about every 15 seconds.

@york-stsci
Copy link
Collaborator

I have a local fix for that particular issue but haven't yet pushed it. Looking at the code, adding (or not adding) IPC will actually have no effect at all on the point source calculation speed, because there are two PSF images in the PSF model, one with and one without IPC, and the only effect of the IPC residual on point sources is that a different PSF is used to generate the image. For Service profiles, there's actually an effect, because the IPC kernel is either applied (or not applied) to the sersic profile as a part of the PSF convolution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants