<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calcfluxscale(d, imstd_med, flagfrac_med):
 """ Given state dict and noise properties, estimate flux scale at the VLA imstd and flagfrac are expected to be median (typical) values from sample in merged noise pkl. """


    # useful functions and VLA parameters
    sensitivity = lambda sefd, dt, bw, eta, nbl, npol: sefd/(eta*np.sqrt(nbl*2 * dt * bw * npol))
    nbl = lambda nant: nant*(nant-1)/2
    eta = {'L': 0.92, 'S': 0.92, 'C': 0.8, 'X': 0.8}   # correlator efficiency
    sefd = {'L': 420, 'S': 370, 'C': 310, 'X': 250}    # fixed to match exposure calculator int time to 100 microJy.

    bw = sum([d['spw_nchan_select'][i]*d['spw_chansize'][i] for i in range(len(d['spw_chansize']))])
    dt = d['inttime']
    npol = d['npol']
    nant = d['nants']
    freq = d['freq'][0]
    if (freq >= 1 and freq < 2):
        band = 'L'
    elif (freq >= 2 and freq < 4):
        band = 'S'
    elif (freq >= 4 and freq < 8):
        band = 'C'
    elif (freq >= 8 and freq < 12):
        band = 'X'
    else:
        logger.warn('first channel freq ({0}) not in bands L, S, C, or X. Assuming L band.'.format(freq))
        band = 'L'

    goodfrac = 1 - flagfrac_med # correct for flagged data
    slim_theory = sensitivity(sefd[band], dt, bw, eta[band], goodfrac*nbl(nant), npol)
    fluxscale = slim_theory/imstd_med

    return fluxscale