Calculating k-correct in kcorrect.kcorrect.kcorrectGST
Hello! There's a issue when I use the Galex-SDSS-2MASS script. The error message is "coeffs must be 2-dimensional if redshift is 1-dimensional" or others errors like this one. When I use the same script but using now kcorrect.kcorrect.kcorrectSDSS the code runs normaly.
Can you be more specific about which script you are trying to run? and send the traceback?
This one runs normaly calculating k:
def calc_kcorrectionSDSS(redshift):
responses = ['sdss_r0', 'sdss_g0', 'sdss_u0', 'sdss_i0', 'sdss_z0']
kc = kcorrect.kcorrect.KcorrectSDSS(responses=responses, abcorrect = True)
redshift = redshift
maggies = [Amostrapequenateste['cModelFlux_r'],Amostrapequenateste['cModelFlux_g'],Amostrapequenateste['cModelFlux_u'],Amostrapequenateste['cModelFlux_i'],Amostrapequenateste['cModelFlux_z']]
ivar = [Amostrapequenateste['cModelFluxIvar_r'],Amostrapequenateste['cModelFluxIvar_g'],Amostrapequenateste['cModelFluxIvar_u'],Amostrapequenateste['cModelFluxIvar_i'],Amostrapequenateste['cModelFluxIvar_z']]
# "coeffs" is a [2,5]-array coefficients multiplying each template
coeffs = kc.fit_coeffs(redshift=redshift, maggies=maggies,ivar=ivar)
# "k" is a [2,4]-array with the K-corrections in magnitude units
k = kc.kcorrect(redshift=redshift, coeffs=coeffs,band_shift=0.1)
tabela_kcorr = pd.DataFrame(k, columns = ['K-corr (r)','K-corr (g)','K-corr (u)','K-corr (i)','K-corr (z)'])
return print(k)
But this one, pretty much the same but now using GST and "galex_NUV" doesn't run:
responsesGST = ['galex_NUV','sdss_r0']
kcGST = kcorrect.kcorrect.KcorrectGST(responses=responsesGST, abcorrect = True)
lista_redshift = Amostrapequenateste['z']
redshiftGST = lista_redshift
maggiesGST = [Amostrapequenateste['nuv_flux (maggies)'].to_numpy(dtype=np.float32),Amostrapequenateste['cModelFlux_r'].to_numpy(dtype=np.float32)]
ivarGST = [Amostrapequenateste['NUV Ivar'].to_numpy(dtype=np.float32), Amostrapequenateste['cModelFluxIvar_r'].to_numpy(dtype=np.float32)]
# "coeffs" is a [2,5]-array coefficients multiplying each template
coeffsGST = kcGST.fit_coeffs(redshift=redshiftGST, maggies=maggiesGST,ivar=ivarGST)
# "k" is a [2,4]-array with the K-corrections in magnitude units
kGST = kcGST.kcorrect(redshift=redshiftGST, coeffs=coeffsGST,band_shift=0.1)
tabela_kcorrGST = pd.DataFrame(kGST, columns = ['K-corr (NUV)','K-corr (r)'])
With this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[54], line 11
8 coeffsGST = kcGST._fit_coeffs(redshift=redshiftGST, maggies=maggiesGST,ivar=ivarGST)
10 # "k" is a [2,4]-array with the K-corrections in magnitude units
---> 11 kGST = kcGST.kcorrect(redshift=redshiftGST, coeffs=coeffsGST,band_shift=0.1)
12 print(k)
File ~/anaconda3/lib/python3.10/site-packages/kcorrect/kcorrect.py:423, in Kcorrect.kcorrect(self, redshift, coeffs, band_shift)
401 def kcorrect(self, redshift=None, coeffs=None, band_shift=0.):
402 """Return K-correction in all bands
403
404 Parameters
(...)
420 K-correction from input to output magnitudes
421 """
422 (array, n, redshift, d1,
--> 423 d2, coeffs) = self._process_inputs(redshift=redshift, maggies=None,
424 ivar=None, coeffs=coeffs)
426 # maggies associated with bandpass R at observed z
427 maggies_in = self.reconstruct(redshift=redshift, coeffs=coeffs)
File ~/anaconda3/lib/python3.10/site-packages/kcorrect/fitter.py:314, in Fitter._process_inputs(self, redshift, maggies, ivar, coeffs)
312 if(array):
313 if(len(coeffs.shape) != 2):
--> 314 raise ValueError("coeffs must be 2-dimensional if redshift is 1-dimensional")
315 if(coeffs.shape[0] != n):
316 raise ValueError("ivar must have values for each redshift")
ValueError: coeffs must be 2-dimensional if redshift is 1-dimensional
Where "Amostrapequenateste" is the dataframe of my sample.
Just a question first: You are using KcorrectGST but you are specifying the responses?
If you are specifying the responses, just use the base Kcorrect class.
On Fri, Oct 20, 2023 at 11:21 AM Raphael Gomes Sousa < @.***> wrote:
This one runs normaly calculating k:
def calc_kcorrectionSDSS(redshift): responses = ['sdss_r0', 'sdss_g0', 'sdss_u0', 'sdss_i0', 'sdss_z0'] kc = kcorrect.kcorrect.KcorrectSDSS(responses=responses, abcorrect = True)
redshift = redshift maggies = [Amostrapequenateste['cModelFlux_r'],Amostrapequenateste['cModelFlux_g'],Amostrapequenateste['cModelFlux_u'],Amostrapequenateste['cModelFlux_i'],Amostrapequenateste['cModelFlux_z']] ivar = [Amostrapequenateste['cModelFluxIvar_r'],Amostrapequenateste['cModelFluxIvar_g'],Amostrapequenateste['cModelFluxIvar_u'],Amostrapequenateste['cModelFluxIvar_i'],Amostrapequenateste['cModelFluxIvar_z']] # "coeffs" is a [2,5]-array coefficients multiplying each template coeffs = kc.fit_coeffs(redshift=redshift, maggies=maggies,ivar=ivar) # "k" is a [2,4]-array with the K-corrections in magnitude units k = kc.kcorrect(redshift=redshift, coeffs=coeffs,band_shift=0.1) tabela_kcorr = pd.DataFrame(k, columns = ['K-corr (r)','K-corr (g)','K-corr (u)','K-corr (i)','K-corr (z)']) return print(k)But this one, pretty much the same but now using GST and "galex_NUV" doesn't run:
responsesGST = ['galex_NUV','sdss_r0']kcGST = kcorrect.kcorrect.KcorrectGST(responses=responsesGST, abcorrect = True)lista_redshift = Amostrapequenateste['z']redshiftGST = lista_redshiftmaggiesGST = [Amostrapequenateste['nuv_flux (maggies)'].to_numpy(dtype=np.float32),Amostrapequenateste['cModelFlux_r'].to_numpy(dtype=np.float32)]ivarGST = [Amostrapequenateste['NUV Ivar'].to_numpy(dtype=np.float32), Amostrapequenateste['cModelFluxIvar_r'].to_numpy(dtype=np.float32)]
"coeffs" is a [2,5]-array coefficients multiplying each templatecoeffsGST = kcGST.fit_coeffs(redshift=redshiftGST, maggies=maggiesGST,ivar=ivarGST)
"k" is a [2,4]-array with the K-corrections in magnitude unitskGST = kcGST.kcorrect(redshift=redshiftGST, coeffs=coeffsGST,band_shift=0.1)tabela_kcorrGST = pd.DataFrame(kGST, columns = ['K-corr (NUV)','K-corr (r)'])
With this error:
---------------------------------------------------------------------------ValueError Traceback (most recent call last)Cell In[54], line 11 8 coeffsGST = kcGST._fit_coeffs(redshift=redshiftGST, maggies=maggiesGST,ivar=ivarGST) 10 # "k" is a [2,4]-array with the K-corrections in magnitude units---> 11 kGST = kcGST.kcorrect(redshift=redshiftGST, coeffs=coeffsGST,band_shift=0.1) 12 print(k) File ~/anaconda3/lib/python3.10/site-packages/kcorrect/kcorrect.py:423, in Kcorrect.kcorrect(self, redshift, coeffs, band_shift) 401 def kcorrect(self, redshift=None, coeffs=None, band_shift=0.): 402 """Return K-correction in all bands 403 404 Parameters (...) 420 K-correction from input to output magnitudes 421 """ 422 (array, n, redshift, d1,--> 423 d2, coeffs) = self._process_inputs(redshift=redshift, maggies=None, 424 ivar=None, coeffs=coeffs) 426 # maggies associated with bandpass R at observed z 427 maggies_in = self.reconstruct(redshift=redshift, coeffs=coeffs) File ~/anaconda3/lib/python3.10/site-packages/kcorrect/fitter.py:314, in Fitter._process_inputs(self, redshift, maggies, ivar, coeffs) 312 if(array): 313 if(len(coeffs.shape) != 2):--> 314 raise ValueError("coeffs must be 2-dimensional if redshift is 1-dimensional") 315 if(coeffs.shape[0] != n): 316 raise ValueError("ivar must have values for each redshift") ValueError: coeffs must be 2-dimensional if redshift is 1-dimensional
Where "Amostrapequenateste" is the dataframe of my sample.
— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_blanton144_kcorrect_issues_5-23issuecomment-2D1772940636&d=DwMFaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=2nqg0fcNitaQTtJ4c9MSjg&m=ynBkDWFpderlldQVgRw-3q4OrTL0-sj0u44-xDWEy__BBFmQySsuBc7hzp7roiS9&s=mc58aCovZBbC9ezubl6wqwz_88HWBOIfTqZNzgvxWVw&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AAODDFQV2RR5W2D2ADQSHVDYAKJHLAVCNFSM6AAAAAA6HJA5WKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZSHE2DANRTGY&d=DwMFaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=2nqg0fcNitaQTtJ4c9MSjg&m=ynBkDWFpderlldQVgRw-3q4OrTL0-sj0u44-xDWEy__BBFmQySsuBc7hzp7roiS9&s=hc1N66fRI2jQPyoWe5DGnHt9BzmpInXkDmQaas2Je04&e= . You are receiving this because you commented.Message ID: @.***>
-- Michael Blanton, Professor Department of Physics New York University
Also, can you verify that the behavior is really different in the two cases? You are giving "redshift" in one case, whose nature I can't tell, and "lista_redshift" in the other. Try making sure you are passing EXACTLY the same structures in.
In particular, look at the shape of the redshift, maggies, and ivar arrays for fit_coeffs() and coeffs arrays you are sending the kcorrect() method call. If you can just send me those for the two cases I could try to figure it out.