Skip to content

Commit

Permalink
Merge pull request #69 from des-science/smooth-piff
Browse files Browse the repository at this point in the history
feat: use apodized Piff models
  • Loading branch information
beckermr authored Jul 16, 2024
2 parents 4010520 + b8e1c82 commit 0172959
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 487 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- main
pull_request: null

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
name: tests
Expand All @@ -25,7 +29,7 @@ jobs:

- uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8
python-version: 3.11
channels: conda-forge,defaults
channel-priority: strict
show-channel-urls: true
Expand All @@ -36,7 +40,7 @@ jobs:
- name: configure conda and install code
shell: bash -l {0}
run: |
mamba install pytest flake8
conda uninstall --force --yes piff
python -m pip install -e . -vv
- name: run cli
Expand All @@ -46,13 +50,19 @@ jobs:
eastlake-src-extractor -dd
run-eastlake-sim --help
- name: test
- name: test eastlake
shell: bash -l {0}
run: |
git clone https://github.com/beckermr/des-test-data
export TEST_DESDATA=`pwd`/des-test-data
pytest -vvs eastlake
- name: test piff
shell: bash -l {0}
run: |
cd piff_package/tests
coverage run -m pytest -v
- name: lint
shell: bash -l {0}
run: |
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ eastlake/astromatic/swarp
eastlake/astromatic/src-extractor
src/sextractor*/*
src/swarp*/*

piff_package/*
!piff_package/apodize.patch
!piff_package/README.md
!piff_package/Piff-1.3.3.tar.gz
!piff_package/LICENSE
1 change: 0 additions & 1 deletion eastlake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@

from .pipeline import register_pipeline_step # noqa
from . import des_piff # noqa
from . import des_smoothpiff # noqa
82 changes: 55 additions & 27 deletions eastlake/des_piff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,56 @@
logger = logging.getLogger(__name__)


PSF_KWARGS_COLOR_RANGES = {
"GI_COLOR": [0.0, 3.5],
"IZ_COLOR": [0.0, 0.65],
}
PSF_COLOR_DEFAULTS = {
"GI_COLOR": 1.1,
"IZ_COLOR": 0.34,
}

PSF_KWARGS = {
"g": {"GI_COLOR": 1.1},
"r": {"GI_COLOR": 1.1},
"i": {"GI_COLOR": 1.1},
"z": {"IZ_COLOR": 0.34},
"g": {"GI_COLOR": PSF_COLOR_DEFAULTS["GI_COLOR"]},
"r": {"GI_COLOR": PSF_COLOR_DEFAULTS["GI_COLOR"]},
"i": {"GI_COLOR": PSF_COLOR_DEFAULTS["GI_COLOR"]},
"z": {"IZ_COLOR": PSF_COLOR_DEFAULTS["IZ_COLOR"]},
}


def _process_color_kwargs(piff_psf, kwargs):
if "GI_COLOR" in piff_psf.interp_property_names:
kwargs.pop("IZ_COLOR", None)

if "GI_COLOR" in kwargs:
if (
kwargs["GI_COLOR"] is None or
kwargs["GI_COLOR"] == "None"
):
kwargs["GI_COLOR"] = PSF_COLOR_DEFAULTS["GI_COLOR"]

if kwargs["GI_COLOR"] < PSF_KWARGS_COLOR_RANGES["GI_COLOR"][0]:
kwargs["GI_COLOR"] = PSF_KWARGS_COLOR_RANGES["GI_COLOR"][0]
if kwargs["GI_COLOR"] > PSF_KWARGS_COLOR_RANGES["GI_COLOR"][1]:
kwargs["GI_COLOR"] = PSF_KWARGS_COLOR_RANGES["GI_COLOR"][1]

elif "IZ_COLOR" in piff_psf.interp_property_names:
kwargs.pop("GI_COLOR", None)
if "IZ_COLOR" in kwargs:
if (
kwargs["IZ_COLOR"] is None or
kwargs["IZ_COLOR"] == "None"
):
kwargs["IZ_COLOR"] = PSF_COLOR_DEFAULTS["IZ_COLOR"]

if kwargs["IZ_COLOR"] < PSF_KWARGS_COLOR_RANGES["IZ_COLOR"][0]:
kwargs["IZ_COLOR"] = PSF_KWARGS_COLOR_RANGES["IZ_COLOR"][0]
if kwargs["IZ_COLOR"] > PSF_KWARGS_COLOR_RANGES["IZ_COLOR"][1]:
kwargs["IZ_COLOR"] = PSF_KWARGS_COLOR_RANGES["IZ_COLOR"][1]

return kwargs


@functools.lru_cache(maxsize=200)
def _read_piff(file_name):
return piff.read(
Expand Down Expand Up @@ -84,26 +126,7 @@ def _draw(
# nice and big image size here cause this has been a problem
image = galsim.ImageD(ncol=n_pix, nrow=n_pix, wcs=pixel_wcs)

if "GI_COLOR" in self.getPiff().interp_property_names:
psf_kwargs.pop("IZ_COLOR", None)
if (
"GI_COLOR" in psf_kwargs and (
psf_kwargs["GI_COLOR"] is None or
psf_kwargs["GI_COLOR"] == "None"
)
):
psf_kwargs["GI_COLOR"] = 1.1

elif "IZ_COLOR" in self.getPiff().interp_property_names:
psf_kwargs.pop("GI_COLOR", None)

if (
"IZ_COLOR" in psf_kwargs and (
psf_kwargs["IZ_COLOR"] is None or
psf_kwargs["IZ_COLOR"] == "None"
)
):
psf_kwargs["IZ_COLOR"] = 0.34
psf_kwargs = _process_color_kwargs(self.getPiff(), psf_kwargs)

offset = (
image_pos.x - int(image_pos.x + 0.5),
Expand All @@ -126,8 +149,11 @@ def getPiff(self):
return self._piff

def getPSF(
self, image_pos, wcs=None,
n_pix=None, depixelize=False,
self,
image_pos,
wcs=None,
n_pix=None,
depixelize=False,
gsparams=None,
**kwargs
):
Expand Down Expand Up @@ -175,7 +201,9 @@ def getPSF(
return psf

def getPSFImage(
self, image_pos, wcs=None,
self,
image_pos,
wcs=None,
n_pix=None,
gsparams=None,
**kwargs
Expand Down
Loading

0 comments on commit 0172959

Please sign in to comment.