<p>For a project I wrote the following python script for calculating the flux density.
My question is: If the user enters for example magV = 22 and the user selects the B filter instead of the V filter will the flux density value be correct?
Something doesn't seem ok to me. Perhaps the mag V value should be converted to mag B before the light passes through the B filter ...</p>
<p>Here is the code snippet:</p>
<pre><code># Filter selection
def band_selection(band):
    
    if band == &quot;B&quot;:
        
        wavelen = 436.258
        filterB = 79.651
        extintion_coef_filter = 0.25
        flux_density = 6.3605 * 10**-9 # 0 point value
    
    elif band == &quot;V&quot;:
        
        wavelen = 544.777
        filterB = 80.732
        extintion_coef_filter = 0.1567
        flux_density = 3.6167 * 10**-9 # 0 point value

    return [wavelen, filterB, extintion_coef_filter, flux_density]

# Flux through filter
def flux(m0, angle, band):
   
    # compute airmass
    DEG_TO_RAD = np.pi / 180
    secz = 1 / np.cos(float(angle) * DEG_TO_RAD)
    X = secz - 0.0018167 * (secz - 1) - 0.002875 * (secz - 1) ** 2 - 0.0008083 * (secz - 1) ** 3
    
    #select extinction coeff for filter
    k = band_selection(band)[2]
    
    
    # correct magnitude for airmass-extinction
    m = m0 + k * X
    
    # select 0 point flux and convert it to W/m2/nm
    # 
    
    Z = band_selection(band)[3] # this is the 0 (Vega) flux density  through a filter 
    
    Z_units = Z*u.erg/u.s/u.cm**2/u.angstrom
    Z_convert = (Z_units).to(u.watt / u.m**2 / u.nanometer, equivalencies=u.spectral_density(band_selection(band)[0] * u.nm))
    
    # Compute the flux through filter
    f = 10 ** (-.4 * m) * Z_convert.value
    return [f, np.round(X,2), np.round(m,2)]
</code></pre>

CC BY-SA 4.0
2023-08-08T07:08:57.920Z
I don't understand the question. If an object has $V=22$ and you try to calculate the flux in the V band using the parameters of the B band, you get the wrong answer.
ProfRob
CC BY-SA 4.0
2023-08-08T07:26:13.720Z
This is what I thought also. If I input the V = 22 I should use the parameters for V band. But what if I only have V =22 and need to compute the flux through B filter. I suppose I have to transform the V mag into B mag first ...
Adrian
CC BY-SA 4.0
2023-08-08T08:04:57.990Z
You have no idea what the flux in the B-band is if you haven't measured it !
ProfRob
<magnitude><astropy>
Calculating the Flux density through different photometric filters
Adrian
# Calculating the Flux density through different photometric filters

(Asked by: username_0 on 2023-08-08)

For a project I wrote the following python script for calculating the flux density.
My question is: If the user enters for example magV = 22 and the user selects the B filter instead of the V filter will the flux density value be correct?
Something doesn't seem ok to me. Perhaps the mag V value should be converted to mag B before the light passes through the B filter ...
Here is the code snippet:
# Filter selection
def band_selection(band):
    
    if band == "B":
        
        wavelen = 436.258
        filterB = 79.651
        extintion_coef_filter = 0.25
        flux_density = 6.3605 * 10**-9 # 0 point value
    
    elif band == "V":
        
        wavelen = 544.777
        filterB = 80.732
        extintion_coef_filter = 0.1567
        flux_density = 3.6167 * 10**-9 # 0 point value

    return [wavelen, filterB, extintion_coef_filter, flux_density]

# Flux through filter
def flux(m0, angle, band):
   
    # compute airmass
    DEG_TO_RAD = np.pi / 180
    secz = 1 / np.cos(float(angle) * DEG_TO_RAD)
    X = secz - 0.0018167 * (secz - 1) - 0.002875 * (secz - 1) ** 2 - 0.0008083 * (secz - 1) ** 3
    
    #select extinction coeff for filter
    k = band_selection(band)[2]
    
    
    # correct magnitude for airmass-extinction
    m = m0 + k * X
    
    # select 0 point flux and convert it to W/m2/nm
    # 
    
    Z = band_selection(band)[3] # this is the 0 (Vega) flux density  through a filter 
    
    Z_units = Z*u.erg/u.s/u.cm**2/u.angstrom
    Z_convert = (Z_units).to(u.watt / u.m**2 / u.nanometer, equivalencies=u.spectral_density(band_selection(band)[0] * u.nm))
    
    # Compute the flux through filter
    f = 10 ** (-.4 * m) * Z_convert.value
    return [f, np.round(X,2), np.round(m,2)]

**Tags:** magnitude, astropy
> **Comments:**
> **username_1**: I don't understand the question. If an object has $V=22$ and you try to calculate the flux in the V band using the parameters of the B band, you get the wrong answer.  
> **username_0**: This is what I thought also. If I input the V = 22 I should use the parameters for V band. But what if I only have V =22 and need to compute the flux through B filter. I suppose I have to transform the V mag into B mag first ...  
> **username_1**: You have no idea what the flux in the B-band is if you haven't measured it !  

---

## 0 answers

