bd-j / forcepho

Generative modeling galaxy photometry for JWST
https://forcepho.readthedocs.io
19 stars 4 forks source link

Question regarding plotting the residual and model images #62

Open Gauri0002 opened 2 years ago

Gauri0002 commented 2 years ago

Hello, I am trying to perform Bulge-Disk Decomposition on generated galaxy images and am using color_plot_together.py (from demo_color) on them.

I keep getting the following plots: jwst070_444

When I print the data,ierr and delta values from the function plot_residual in the color_plot_together.py file I only get arrays of nan values, but the plots for the data seem to be coming out fine unlike the plots for residual and model plots.

Can someone help me with finding out why this is happening ?

bd-j commented 2 years ago

Hi @Gauri0002 I'm not at all sure how the arrays could be NaNs but the data plot looks ok and the residual and model plot is finite (but wrong). Are you sure the arrays are all NaN and not just NaNs in some leading or trailing elements (i.e. np.any(np.isfinite(ierr)) == False)?

I'd also note that it looks like you are using the same pixel scale and PSF for F070W and F444W, is that intended?

You might also look a little lower down in the Residuals object, e.g.

r = Residuals(patchname.replace("samples", "residuals"))
print(r.exposures)  # print the input exposure names
exp = r.exposures[0]  # get the name of the first exposure
data_flat = r.handle[exp]["data"][:]  # get data as 1d array
ierr_flat = r.handle[exp]["ierr"][:]
delta_flat = r.handle[exp]["residual"][:]
bd-j commented 2 years ago

I also suggest you look at the trace of the MCMC chain, see e.g. https://github.com/bd-j/forcepho/blob/main/demo/demo_basic/basic_plot.py#L19

(though that is for one source in one band, it needs some modifications to work on two sources in two bands)

Gauri0002 commented 2 years ago

Hi @Gauri0002 I'm not at all sure how the arrays could be NaNs but the data plot looks ok and the residual and model plot is finite (but wrong). Are you sure the arrays are all NaN and not just NaNs in some leading or trailing elements (i.e. np.any(np.isfinite(ierr)) == False)?

I'd also note that it looks like you are using the same pixel scale and PSF for F070W and F444W, is that intended?

You might also look a little lower down in the Residuals object, e.g.

r = Residuals(patchname.replace("samples", "residuals"))
print(r.exposures)  # print the input exposure names
exp = r.exposures[0]  # get the name of the first exposure
data_flat = r.handle[exp]["data"][:]  # get data as 1d array
ierr_flat = r.handle[exp]["ierr"][:]
delta_flat = r.handle[exp]["residual"][:]

So, you are correct that they are not all nan value {I kind of panicked with the incorrect plots that I forgot to run a simple check :')}.

Also yes for these images the pixel scales and psfs are the same as I just wanted to try out the code.

On printing data, i_err and the delta array directly from the residual patches gives non-nan values.

Gauri0002 commented 2 years ago

I also suggest you look at the trace of the MCMC chain, see e.g. https://github.com/bd-j/forcepho/blob/main/demo/demo_basic/basic_plot.py#L19

(though that is for one source in one band, it needs some modifications to work on two sources in two bands)

I'll take a look at it