<pre><code>T=5772  # surface temperature of the sun
r1=1 # unit: in solar radius

r2=r1*(6.957e8)       # unit: radius in meter
k = 1.381e-23         # Boltzmann
h = 6.626e-34         # Planck
c = 3e8               # light speed
d = 3.086e17          # 10pc, in meter, absolute magnitude

def pk(t, l): # l: wavelength in meter
    x = (h*c)/(k*t*l)
    c1 = 8*(np.pi)*h*(c**2)/(l**5)   #l: wavelength in meter
    p1 = c1 / (np.exp(x)-1)          #   j/s/m2/m
    p2=(1e-7)*p1                     #   erg/s/cm2/angstron
    return(p2)


eff = np.genfromtxt('2MASS_2MASS.J.dat', comments='#')  #[1]
a1,b1=eff[:,0],eff[:,1]  # lambda and its transmission; Suppose dat's lambda has a step of 1 Angstron


bbf=[] #wavelength--&gt; Planck 
for i in np.arange(a1[0],a1[-1]+1): #i in Angstron
    j=i*(1e-10) #j in meter
    bbf=bbf+[pk(T,j)]  #j in meter
    
f1,f2=sum([o*p*q for o,p,q in zip(bbf,a1,b1)]),sum([p*q for p,q in zip(a1,b1)])
mag=-2.5*np.log10(f1/f2/r2*r2/d/d)-23.75 #A11 of [2]
print(&quot;J mag:&quot;,mag)
</code></pre>
<p>Sun's absolute Vega magnitude in the J band is about 3.67 mag.
The code above presents a very deviate result. <strong>So where is the mistake?</strong></p>
<p>The sun should NOT have a large deviation in the J band.</p>
<ol>
<li><a href="http://svo2.cab.inta-csic.es/theory/fps/getdata.php?format=ascii&amp;id=2MASS/2MASS.J" rel="nofollow noreferrer">http://svo2.cab.inta-csic.es/theory/fps/getdata.php?format=ascii&amp;id=2MASS/2MASS.J</a></li>
<li><a href="https://doi.org/10.1086/664083" rel="nofollow noreferrer">https://doi.org/10.1086/664083</a></li>
</ol>

CC BY-SA 4.0
2024-03-28T19:51:45.450Z
Can you explain a bit more how you are putting the integrated flux onto a magnitude system?
ProfRob
CC BY-SA 4.0
2024-03-29T02:04:41.160Z
That is the original definition of magnitude.  See  reference 1 or https://www.stsci.edu/hst/instrumentation/acs/data-analysis/zeropoints  .The integration is based on A(11) of reference 1.  When bin size is small enough, summation can replace integration. The bin size is 1 Angstron.
questionhang
CC BY-SA 4.0
2024-03-29T07:17:05.637Z
@ProfRob   Are there any errors in the formula or the code?
questionhang
CC BY-SA 4.0
2024-04-01T02:11:40.170Z
@questionhang if there is a question of whether the issue is in a formula or the code that uses it, we always provide the formula explicitly using [MathJax](https://math.meta.stackexchange.com/q/5020/284619). We never ask readers to reverse engineer code to try to guess the matheatical formulae it depends upon. Please write out all your math in MathJax first, then show your code. It is possible that in doing so, you may find errors yourself! (In that case, you may also writge your own answer post) *Thanks!*
uhoh
<mathematics><python><photometry><black-body><filter>
calculating Sun's J band mag via integrating the Planck’s law
questionhang
# calculating Sun's J band mag via integrating the Planck’s law

(Asked by: username_0 on 2024-03-28)

T=5772  # surface temperature of the sun
r1=1 # unit: in solar radius

r2=r1*(6.957e8)       # unit: radius in meter
k = 1.381e-23         # Boltzmann
h = 6.626e-34         # Planck
c = 3e8               # light speed
d = 3.086e17          # 10pc, in meter, absolute magnitude

def pk(t, l): # l: wavelength in meter
    x = (h*c)/(k*t*l)
    c1 = 8*(np.pi)*h*(c**2)/(l**5)   #l: wavelength in meter
    p1 = c1 / (np.exp(x)-1)          #   j/s/m2/m
    p2=(1e-7)*p1                     #   erg/s/cm2/angstron
    return(p2)


eff = np.genfromtxt('2MASS_2MASS.J.dat', comments='#')  #[1]
a1,b1=eff[:,0],eff[:,1]  # lambda and its transmission; Suppose dat's lambda has a step of 1 Angstron


bbf=[] #wavelength--> Planck 
for i in np.arange(a1[0],a1[-1]+1): #i in Angstron
    j=i*(1e-10) #j in meter
    bbf=bbf+[pk(T,j)]  #j in meter
    
f1,f2=sum([o*p*q for o,p,q in zip(bbf,a1,b1)]),sum([p*q for p,q in zip(a1,b1)])
mag=-2.5*np.log10(f1/f2/r2*r2/d/d)-23.75 #A11 of [2]
print("J mag:",mag)

Sun's absolute Vega magnitude in the J band is about 3.67 mag.
The code above presents a very deviate result. So where is the mistake?
The sun should NOT have a large deviation in the J band.

http://svo2.cab.inta-csic.es/theory/fps/getdata.php?format=ascii&id=2MASS/2MASS.J
https://doi.org/10.1086/664083

**Tags:** mathematics, python, photometry, black-body, filter
> **Comments:**
> **username_1**: Can you explain a bit more how you are putting the integrated flux onto a magnitude system?  
> **username_0**: That is the original definition of magnitude.  See  reference 1 or https://www.stsci.edu/hst/instrumentation/acs/data-analysis/zeropoints  .The integration is based on A(11) of reference 1.  When bin size is small enough, summation can replace integration. The bin size is 1 Angstron.  
> **username_0**: @ProfRob   Are there any errors in the formula or the code?  
> **username_2**: @questionhang if there is a question of whether the issue is in a formula or the code that uses it, we always provide the formula explicitly using [MathJax](https://math.meta.stackexchange.com/q/5020/284619). We never ask readers to reverse engineer code to try to guess the matheatical formulae it depends upon. Please write out all your math in MathJax first, then show your code. It is possible that in doing so, you may find errors yourself! (In that case, you may also writge your own answer post) *Thanks!*  

---

## 0 answers

