# Reproducing a coadd DP0.2 galaxy image

**URL:** <https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693>\
**Category:** Support\
**Tags:** dp0\
**Created:** [June 7, 2024, 8:39pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693 "2024-06-07T20:39:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 7, 2024, 8:39pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/1 "2024-06-07T20:39:45Z")

</div>

Hi all,

I am trying to reproduce a coadd DP0 galaxy image using SLSim, an LSST-desc strong lensing simulation software. However, to reproduce a DP0 galaxy image, I need to rotate the SLSim coordinate system by a certain angle, and this angle is different for each galaxy. This indicates that the orientation difference I am observing is not due to a fixed coordinate rotation. Rather, it seems like each galaxy has its own sky rotation (though this might not be correct). If this is the case, how can I get this rotation angle? If this is not the case, what might be the issue?

I would appreciate any suggestions for this. Thank you!

---

<div class="post-metadata">

**Author:** ![MelissaGraham](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/melissagraham/32/2549_2.png) [@MelissaGraham](https://www.rubin.community/u/MelissaGraham)\
**Post date:** [June 7, 2024, 9:25pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/2 "2024-06-07T21:25:34Z")

</div>

Hi @nkhadka, thanks for posting this question. I don’t have the answer but I’d like to help.

Could you clarify what is meant by “coadd DP0 galaxy image”? Within Data Preview 0, `deepCoadd` is one of the image types, and they’re oriented north-up east-left (which makes me think you’re not attempting to reproduce a DP0 `deepCoadd` image, but rather something else). The individual processed visit images (`calexp` image types) do have a camera rotation, though.

I am unfamiliar with SLSim, or how it is being applied here, but there are no strong lensing sources in the simulation on which DP0 is based. There were some in the [LSST DESC DC2 simulation](https://arxiv.org/pdf/2010.05926), but as I understand it (from Table 1 of that paper) they were in the deep drilling fields, and DP0 is based only on the wide-fast-deep fields.

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 7, 2024, 9:52pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/3 "2024-06-07T21:52:07Z")

</div>

Hi @MelissaGraham ,

Thank you very much for your reply!  
A coadd DP0 galaxy image refers to a DP0 deepCoadd galaxy image. For a DP0.2 galaxy, if we use the given Sersic profiles, ellipticity, and deepCoadd image properties (background noise, Poisson noise, PSF) for a DP0 galaxy, we should be able to produce an image that is very close to the DP0 deepCoadd galaxy image. However, I am noticing an orientation difference between the SLSim-generated galaxy image and the DP0 deepCoadd image of the same galaxy.

---

<div class="post-metadata">

**Author:** ![sibirrer](https://avatars.discourse-cdn.com/v4/letter/s/e9a140/32.png) [@sibirrer](https://www.rubin.community/u/sibirrer)\
**Post date:** [June 7, 2024, 11:12pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/4 "2024-06-07T23:12:51Z")

</div>

Hi @MelissaGraham the issue is not just with SLSim, even when using Galsim with the ellipticity orientations in the catalogue, the images are not aligned and require DIFFERENT relative rotations from image to image. Just wanted to add this here. Correct me if I am wrong @nkhadka

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 7, 2024, 11:36pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/5 "2024-06-07T23:36:51Z")

</div>

Thanks @sibirrer for adding this information! You are correct.

---

<div class="post-metadata">

**Author:** ![mwv](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mwv](https://www.rubin.community/u/mwv)\
**Post date:** [June 10, 2024, 4:15pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/6 "2024-06-10T16:15:26Z")

</div>

Each LSST simulated image has a different orientation with respect to the sky. I.e., a different translation+rotation matrix from x, y on the detector to RA, Dec on the sky. This means that position angle in detector coordinates is different than position angle on the sky. I would thus expect that for each image a galaxy requires a different relative rotation in detector coordinates to place correctly on a given calexp.

Could you perhaps post some pseudo code illustrating the problem? I’m not sure we’re yet sharing a common understanding of the terms and the problem, and the more concrete we can make the example, the more helpful we can be.

---

<div class="post-metadata">

**Author:** ![MelissaGraham](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/melissagraham/32/2549_2.png) [@MelissaGraham](https://www.rubin.community/u/MelissaGraham)\
**Post date:** [June 10, 2024, 5:23pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/7 "2024-06-10T17:23:22Z")

</div>

Based on @nkhadka’s reply, it sounds like we’ve established that you’re using the DP0.2 deepCoadd images (i.e., accessible either via the butler or TAP services provided by the Rubin Science Platform).

@nkhadka and @sibirrer, could you clarify when you say “if we use the given Sersic profiles, ellipticity …” and “the ellipticity orientations in the catalogue”, exactly what catalog and columns you are using. The DP0.2 Object table contains photometry and shape measurements on those deepCoadd images, but the [DP0.2 Object table schema](https://dm.lsst.org/sdm_schemas/browser/dp02.html) does not explicitly have a column for “Sersic profile” (but does have ellipse parameters). Where are “the given Sersic profiles” coming from?

Thanks @mwv, I agree. A bit of code that demonstrates which data you’re accessing, and what the expectation is vs. the issue you’re reporting, would be helpful.

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 10, 2024, 6:26pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/8 "2024-06-10T18:26:13Z")

</div>

Thank you very much @mwv for your reply!

@MelissaGraham , you are correct, we are using deepCoadd image. We got all the parameters of a selected galaxy from the DC2 catalog. Screen shots of some of the parameters of a selected galaxy are given below:

 ![Screenshot 2024-06-10 at 1.47.13 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/0/0f6df5809c044c69cb13e72329035de9fa2458ec.png)  
 ![Screenshot 2024-06-10 at 1.47.51 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/1/18cf12044f668d01b2508b1e01ddba20805c9b5b.png)  
 ![Screenshot 2024-06-10 at 1.48.43 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/9/9dddee6bc506377d98a5c9663e4f17ba545c6408.png)

 ![Screenshot 2024-06-10 at 1.49.10 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/d/d4f2d7aa03829a974f8fd60e09c297be205ab935.png)

As @mwv aksed, here is a piece of code that I have used to generate these images:

I made a cutout (35\*35 pixel) image of a galaxy at ra=61.999855458880795 and dec=-36.99883611551307. This cutout is from the deepCoadd image.

Then, I used following information of this galaxy from the DC2 catalog to generate an image using slsim:

# position angle

position\_angle=np.pi\*dc2\_galaxies[2][“position\_angle\_true”]/180

## axis ratios of disk dominated galaxy

q\_disk=dc2\_galaxies[2][‘size\_minor\_disk\_true’]/dc2\_galaxies[2][‘size\_disk\_true’]  
q\_bulge=dc2\_galaxies[2][‘size\_minor\_bulge\_true’]/dc2\_galaxies[2][‘size\_bulge\_true’]  
q = dc2\_galaxies[2][‘size\_minor\_true’]/dc2\_galaxies[2][‘size\_true’]

## Disk dominated galaxy

epsilon\_disk=(1-q\_disk)/(1+q\_disk)  
epsilon\_bulge=(1-q\_bulge)/(1+q\_bulge)  
epsilon = (1-q)/(1+q)

## disk dominated

e1\_disk = epsilon\_disk \* np.cos(2 \* position\_angle)  
e2\_disk = epsilon\_disk \* np.sin(2 \* position\_angle)  
e1\_bulge = epsilon\_bulge \* np.cos(2 \* position\_angle)  
e2\_bulge = epsilon\_bulge \* np.sin(2 \* position\_angle)  
e1 = epsilon \* np.cos(2 \* position\_angle)  
e2 = epsilon \* np.sin(2 \* position\_angle)

#SLSim kwargs for a disk dominated galaxy. Here, we use  
kwargs\_lens\_1 = [{‘theta\_E’: 1,  
‘gamma’: 2,  
‘e1’: e1,  
‘e2’: e2,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1},  
{‘gamma1’: dc2\_galaxies[2][“shear\_1”],  
‘gamma2’: dc2\_galaxies[2][“shear\_2”],  
‘ra\_0’: 0,  
‘dec\_0’: 0},  
{‘kappa’: dc2\_galaxies[2][“convergence”], ‘ra\_0’: 0, ‘dec\_0’: 0}]  
kwargs\_source\_1= None  
flux\_i\_1 = 10 \*\* (-dc2\_galaxies[2][“mag\_true\_i\_lsst”] / 2.5)  
mag\_bulge\_i\_1 = -2.5 \* np.log10(dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”] \* flux\_i\_1)  
mag\_disk\_i\_1 = -2.5 \* np.log10((1-dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”]) \* flux\_i\_1)  
kwargs\_lens\_light\_i\_1 = [{‘magnitude’: mag\_bulge\_i\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_bulge\_true”],  
‘n\_sersic’: 4.0,  
‘e1’: e1\_bulge,  
‘e2’: e2\_bulge,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1},  
{‘magnitude’: mag\_disk\_i\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_disk\_true”],  
‘n\_sersic’: 1.0,  
‘e1’: e1\_disk,  
‘e2’: e2\_disk,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1}]  
flux\_r\_1 = 10 \*\* (-dc2\_galaxies[2][“mag\_true\_r\_lsst”] / 2.5)  
mag\_bulge\_r\_1 = -2.5 \* np.log10(dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”] \* flux\_r\_1)  
mag\_disk\_r\_1 = -2.5 \* np.log10((1-dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”]) \* flux\_r\_1)  
kwargs\_lens\_light\_r\_1 = [{‘magnitude’: mag\_bulge\_r\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_bulge\_true”],  
‘n\_sersic’: 4.0,  
‘e1’: e1\_bulge,  
‘e2’: e2\_bulge,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1},  
{‘magnitude’: mag\_disk\_r\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_disk\_true”],  
‘n\_sersic’: 1.0,  
‘e1’: e1\_disk,  
‘e2’: e2\_disk,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1}]  
flux\_g\_1 = 10 \*\* (-dc2\_galaxies[2][“mag\_true\_g\_lsst”] / 2.5)  
mag\_bulge\_g\_1 = -2.5 \* np.log10(dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”] \* flux\_g\_1)  
mag\_disk\_g\_1 = -2.5 \* np.log10((1-dc2\_galaxies[2][“bulge\_to\_total\_ratio\_i”]) \* flux\_g\_1)  
kwargs\_lens\_light\_g\_1 = [{‘magnitude’: mag\_bulge\_g\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_bulge\_true”],  
‘n\_sersic’: 4.0,  
‘e1’: e1\_bulge,  
‘e2’: e2\_bulge,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1},  
{‘magnitude’: mag\_disk\_g\_1,  
‘R\_sersic’: dc2\_galaxies[2][“size\_disk\_true”],  
‘n\_sersic’: 1.0,  
‘e1’: e1\_disk,  
‘e2’: e2\_disk,  
‘center\_x’: center\_cood\_x\_1,  
‘center\_y’: center\_coord\_y\_1}]  
kwargs\_ps\_1 = None

Then we generate an image using lens\_image() function in slsim: [slsim/slsim/image\_simulation.py at 68adf909194f9114f0692764f7d4361c5001cc6e · LSST-strong-lensing/slsim · GitHub](https://github.com/LSST-strong-lensing/slsim/blob/68adf909194f9114f0692764f7d4361c5001cc6e/slsim/image_simulation.py#L497)

Variance map, psf, and zeropoint are used from the deepCoadd cutout image.  
Image comparision with the actual position angle:

 ![image_comparision_with_actual_postion_angle_from_catalog](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/8/8cb81978ae5fcb4899f593c92f541758e4ce4cb8.png)  
image comparision with the position angle rotated by 140 degree:  
 ![dc2_2_comp_variance_2](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/b/b0c7bc932d15147b5438ffd65dc2b138529131f7.png)

For full tutorial, please see: [https://app.reviewnb.com/LSST-strong-lensing/slsim/pull/163/](https://app.reviewnb.com/LSST-strong-lensing/slsim/pull/163/)

Thank you!

---

<div class="post-metadata">

**Author:** ![MelissaGraham](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/melissagraham/32/2549_2.png) [@MelissaGraham](https://www.rubin.community/u/MelissaGraham)\
**Post date:** [June 10, 2024, 10:41pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/9 "2024-06-10T22:41:49Z")

</div>

Hi @nkhadka,

If I use the Portal Aspect of the Rubin Science Platform (RSP) to find your galaxy, and display the i-band deeply coadded image with north up, east left, it does match the orientation you expect.

Screenshot:

 ![Screen Shot 2024-06-10 at 3.16.56 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/0/0f468a929fa7249d9a0bb57759e52d5de40bc950.jpeg)

Looking at the linked tutorial, it appears that the image labeled “Galaxy image from DP0” are being loaded from `.npy` files? Somewhere along the line I’d guess the image orientations are being rotated (or perhaps just flipped or transposed), maybe when those files are read or written?

If you might instead like to use the RSP’s image cutout service, which returns DP0 stamps with WCS, there is a [tutorial for that](https://github.com/rubin-dp0/tutorial-notebooks/blob/main/DP02_13a_Image_Cutout_SciDemo.ipynb). It is designed to be run from within the RSP but can be adapted (e.g., with use of an authorization token) to run from elsewhere. Let me know if that might be useful?

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 10, 2024, 11:11pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/10 "2024-06-10T23:11:57Z")

</div>

Hi @MelissaGraham , thanks for doing this! I apologize for giving incorrect ra and dec. These images are for the galaxy given in screen shot. For this galaxy, ra, dec = 61.99284796403353, -36.9900209621661. Yes, I loaded Galaxy image from DP0 from a saved file. This image is obtained from the deepCoadd images using butler. It would be great if you could query this galaxy and see if orientation matches.

---

<div class="post-metadata">

**Author:** ![MelissaGraham](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/melissagraham/32/2549_2.png) [@MelissaGraham](https://www.rubin.community/u/MelissaGraham)\
**Post date:** [June 10, 2024, 11:56pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/11 "2024-06-10T23:56:15Z")

</div>

OK yes, with coordinates ra, dec = 61.99284796403353, -36.9900209621661 instead, the image does match yours labeled “Galaxy image from DP0”.

 ![Screen Shot 2024-06-10 at 4.46.44 PM](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/e/e705a28a8f96f8aa4ff688d1b587c10f61607a2f.jpeg)

I can see in the table of truth parameters that the disk of this galaxy had E1 = 0.176 and E2 = -0.393, which should lead to an orientation like you show in the “Galaxy image from slsim” (like [in this plot](https://www.researchgate.net/figure/The-parameterisation-of-generalised-ellipticity-as-two-quantities-e1-and-e2-showing-the_fig6_1910339), right?).

Since this seems to be a question about the simulation (DC2, by DESC) and not the processing (DP0, by Rubin), I’ll try to find someone who can answer your question.

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 11, 2024, 12:47am UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/12 "2024-06-11T00:47:44Z")

</div>

Thanks, @MelissaGraham. Yes, the orientation of the DP0 image should match the SLSim image or be rotated by a fixed angle (e.g., 90 or 180 degrees) if there is a difference in the coordinate convention, but this is not the case. This might also be related with the deepCoadd processing pipeline. I hope someone will be able to point out the solution.

---

<div class="post-metadata">

**Author:** ![jchiang](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jchiang/32/614_2.png) [@jchiang](https://www.rubin.community/u/jchiang)\
**Post date:** [June 11, 2024, 2:46am UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/13 "2024-06-11T02:46:12Z")

</div>

Are the various relative rotation angles that you are finding consistent with a flip in the sign convention for the position angle? For the DC2 image sims, we used a position angle convention that was used by the phosim code, whereas codes like treecorr define the sign of the PA wrt Celestial North in the opposite sense. Here’s [the PR](https://github.com/LSSTDESC/gcr-catalogs/pull/608) in GCRCatalogs where we switched conventions (well after the DC2 sims).

---

<div class="post-metadata">

**Author:** ![nkhadka](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/nkhadka/32/2611_2.png) [@nkhadka](https://www.rubin.community/u/nkhadka)\
**Post date:** [June 11, 2024, 4:53pm UTC](https://www.rubin.community/t/reproducing-a-coadd-dp0-2-galaxy-image/8693/14 "2024-06-11T16:53:21Z")

</div>

Thank you very much @jchiang for your suggestion! After your suggestion, I explored DC2 catalog. DC2 catalog has 3 different position angles. One is position\_angle\_true. I think this one is in galsim convention. Another one is position\_angle\_true\_posim. This is -ve of position\_angle\_true and I believe this is the convenstion for posim. The last one is position\_angle\_true\_dc2. I am not sure how this angle is derived. I used this angle and found match with DP0 images. So, position angle used in DP0 images is position\_angle\_true\_dc2.

Thanks all for your help. I have attached some cmparisions.

 ![7b9ceab4-5098-40f5-ad5b-84d83a012796](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/1/137056958820704472b0a4b208abc9454363b516.png)  
 ![ec69eae6-e69b-4dfc-b724-b59e8cb83deb](https://us1.discourse-cdn.com/flex002/uploads/rubin/original/2X/c/c2b23840aefb0666b177aa1fa446d0184cedefb9.png)
