sweverett / Balrog-GalSim

Modules for GalSim that will be useful for DES images in conjunction with Balrog.
MIT License
5 stars 5 forks source link

Allow COSMOS galaxies as inputs #32

Open sweverett opened 6 years ago

sweverett commented 6 years ago

For the TAMU run, it would be better to use a deeper input catalog like the COSMOS catalog that ships with GalSim (or the DES mof catalog).

mcclearyj commented 6 years ago

So interestingly this* is something that I was trying to do separately, and am trying to get back to now. If someone figures this out before I do, lmk.

*feeding COSMOS galaxies as inputs

sweverett commented 6 years ago

This has been put on the backburner as we are likely not using COSMOS inputs for our next test run. The latest version of balrog_injection.py has some helpful changes in load_input_catalogs() that starts this process but I haven't followed through with the rest of the code. If you run into any issues, feel free to post them here and I can try to help out!

sweverett commented 6 years ago

@mcclearyj: The latest set of commits solves the majority of this issue. I think there may still be a consistency issue between the zeropoints for COSMOS / bandpass / DES nullweight images that I'm working on but the infrastructure is now all in place and I've successfully run a few tests.

The update is a bit complicated. balrog_injection.py works by building a multi-output yaml file that the galsim executable calls and then does it's standard config processing. However, ChromaticObject's are not yet supported for config use. To get around this, I've added a custom chromatic version of the relevant GalSim COSMOS files scene_chromatic.py and input_cosmos_chromatic.py, as well as a custom stamp builder cosmos_chromatic_stamp.py. The new example config file cosmos_test.yaml shows how to use these new classes and what inputs you'll want to pass.

Unfortunately all this is not enough. There are a few low-level code changes that must be done to the GalSim source code and then rebuilt using scons install. I can send you my modified chromatic.py and wcs.py files, but the two changes you need to make are:

chromatic.py:

diff --git a/galsim/chromatic.py b/galsim/chromatic.py
@@ -2205,7 +2205,10 @@ class ChromaticConvolution(ChromaticObject):
         # Condition for being able to propagate noise:
         # Exactly one of the convolutants has a .covspec attribute.
         covspecs = [ obj.covspec for obj in self.obj_list if hasattr(obj, 'covspec') ]
-        if len(covspecs) != 1:
+        # NOTE: ADDED BY ME:
+        if len(covspecs) == 0:
+            return None
+        elif len(covspecs) != 1:

wcs.py:

diff --git a/galsim/wcs.py b/galsim/wcs.py
@@ -1154,8 +1159,15 @@ class PixelScale(LocalWCS):
                                  flux_ratio=self._scale**-2)
     def _profileToImage(self, world_profile):
-        return galsim._Transform(world_profile, 1./self._scale, 0., 0., 1./self._scale,
-                                 flux_ratio=self._scale**2)
+        # NOTE: ADDED BY ME
+        if isinstance(world_profile, galsim.GSObject):
+            return galsim._Transform(world_profile, 1./self._scale, 0., 0., 1./self._scale,
+                                    flux_ratio=self._scale**2)
+        elif isinstance(world_profile, galsim.ChromaticObject):
+            return galsim.Transform(world_profile, jac=(1./self._scale, 0., 0., 1./self._scale),
+                                    flux_ratio=self._scale**2)

Another tricky part is how the bandpasses are constructed. Relevant filter information has to be set in _setup_bandpass_config() in balrog/filters.py. If you want to use a lookup table for the filter transmission for a non-COSMOS filter, then you need to to: (1) Set use_filter_tables : True and filter_dir : {FILTER_PATH} in the cosmos_chromatic_catalog section of the config file, (2) Place the lookup table files (.dat, .ascii, etc.) at {FILTER_PATH}. The examples I've tested come from here, (3) Set the filter lookup table filenames in transmission_table_ name at the bottom of filters.py. I've already done these steps for ugrizY (and uploaded the filter files to the repo in inputs/filters/), but you'll have to repeat them for any other filters you might want.

Let me now if you have any troubles getting this to work!

mcclearyj commented 6 years ago

Hey Spencer!

At first, I didn't realize that your missive was actually, personally directed at me and my issue, so apologies for the late reply. I started modifying balrog_injection.py to work with the DECam data that I have, but now I see that this was redudant! As a first step, I should change both the input type and the galaxy type to cosmos_chromatic_catalog in the bal_config.py, right? I also modified some low-level things so that the WCS information of the stacked fits file I'm using as a geom_file can be read.

I also just want to clarify that the two changes to wcs.py and chromatic.py that you suggested above are to be made to my local fork, correct?

Finally, I have a question: right now, my version is chocking on the self._load_zeropoints(config) function, namely that there are no files that look like e.g. /lists/A2029_g_nullwt-flist-testy.dat'. Is it safe to comment out this function if the zeropoints were manually adjusted by me?

Also, will the code work if there are only a few images in one directory, or does it expect matching chips in every filter?

Thanks! --Jacqueline