Open kevinhainline opened 2 years ago
As an update, this also happens if you run the fitting on Object 4116 above using these templates only:
# Template definition file
#
# No blank lines allowed (for now).
#
# Column definitions:
# 1. Template number
# 2. Template file name
# 3. Lambda_conv (multiplicative factor to correct wavelength units)
# 4. Age of template model in Gyr (0 means template is always used)
# 5. Template error amplitude (for INDIVIDUAL template fits)
# 6. Comma/space separated list of template numbers to be combined
# with current template if combined fits are enabled.
#
# Sample entry:
# 1 [path_to_file]/template1.sed 1.0 14.7 0.2 2,3,5
1 templates/eazy_v1.1_sed7.sed 1.0 0 1.0
2 templates/eazy_v1.1_sed6.sed 1.0 0 1.0
3 templates/eazy_v1.1_sed5.sed 1.0 0 1.0
4 templates/eazy_v1.1_sed4.sed 1.0 0 1.0
5 templates/eazy_v1.1_sed3.sed 1.0 0 1.0
6 templates/eazy_v1.1_sed2.sed 1.0 0 1.0
7 templates/eazy_v1.1_sed1.sed 1.0 0 1.0
8 templates/ssp_25Myr_z008_withem.sed 1.0 0 1.0
9 templates/ssp_5Myr_z008_withem.sed 1.0 0 1.0
10 templates/c09_del_8.6_z_0.019_chab_age09.40_av2.0.sed 1.0 0 1.0
11 templates/erb2010_highEW.sed 1.0 0 1.0
Does it have anything to do with combining too many templates at once?
I doubt anyone is looking at this, but I think that I've discovered the issue - it has to do with the order of the template files specific, and to understand we have to look at the show_fit
function:
for i in range(self.NTEMP):
zargs = {'z':z, 'redshift_type':TEMPLATE_REDSHIFT_TYPE}
fnu = self.templates[i].flux_fnu(**zargs)*self.tempfilt.scale[i]
try:
tempflux[i, :] = fnu
except:
tempflux[i, :] = np.interp(templ.wave,
self.templates[i].wave, fnu)
Here, in order to sum the fluxes for the plot (and for the array templf
that's output as part of show_fit), the script checks to see if it can cram the template fluxes into the tempflux array, which is implicitly making an assumption that the wavelength arrays are the same, which is why they have the same lengths. If it can't do that, then the code runs an interpolation to templ.wave
, which is set a few lines earlier:
templ = self.templates[0]
As the wavelength of the first template in the list specified by the TEMPLATES_FILE
. Once things are interpolated, then the code can actually sum things. However, if your first template in the list has an especially sparse wavelength array, then this has ramifications for the final output SED, so I recommend that the first template file in the list have a pretty fine wavelength array. Notice, in the comment dated June 30th, the first template I specified was eazy_v1.1_sed7.sed
(https://github.com/gbrammer/eazy-photoz/blob/master/templates/EAZY_v1.1_lines/eazy_v1.1_sed7.dat), which has only 468 wavelength values, while the others have 2818 wavelength values. By interpolating to the wavelength array from eazy_v1.1_sed7.dat
, I was inadvertently lowering the resolution of the final output SED.
Thank you, Kelvin!!! I met with the same problem and your post saved my life :-D !!!
Thanks for your detective work on this @kevinhainline and followup @LittleLin1999 . There are a lot of hacks throughout that should be cleaned up, particularly everywhere there is crudetry/except
clause that doesn't catch specific exceptions. Would you be interested in adding a fix and PR for this particular issue with show_fit
? A few ideas:
property
that is automatically an array of the unique wavelength values of all of the templates in the listshow_fit
, rather than the simple and wrong np.interp
interpolation. Hi @gbrammer Thank you for your reply! I did a test using Hainline+23 templates (https://zenodo.org/records/8092529) and met with a new problem. There are three kinds of wavelength lengths: 468, 2818, and 6900. If I put the 2818 one as the first in the template list, the problem gets resolved. But if I put the 6900 one as the first, the same issue appears, showing extremely large emodel
values. So I guess the wavelength grid of the first template cannot be too fine? Is this caused by the same problem in show_fit
, too?
Here I attach the examples with the first template being the 6900 grid one and the 2800 one below.
When fitting some simulated HST+JWST fluxes, comparing the original EAZY to eazy-py, where I've fit the same data set with the same templates (and template error function), without using a prior. The minimum chi-square values (and the chi-square surfaces) agrees quite well between EAZY and eazy-py, and the resulting redshifts are similar (well, the redshifts corresponding to the minimum chi-square).
However, when using
self.show_fit()
, I've discovered that many of the targets have fits that do not seem to agree with the best-fit templates. For instance:The F150W and F200W template fluxes are significantly higher than the best-fit template. I've gone and pulled this template out by examining how
self.show_fit()
calculates the template from the coefficients, and passed it through the F150W and F200W filters by hand:When I fit this object with the original EAZY (and the same parameters, including the same templates), I get this fit (in green):
Notice that the best-fit photometry is almost identical between this fit and the eazy-py fit, but the template combination here leads to stronger line emission accounting for the high F150W and F200W fluxes. I don't know enough about how the coefficients are calculated within eazy-py to understand why this discrepancy occurs. The templates that I am using are the standard set of EAZY templates along with some generated from fsps:
And the simulated data that I'm using is:
with fluxes in nJy. I can provide other files, including the param file, the extra templates file, and/or the h5 file, if necessary.