Exemplo n.º 1
0
def PMEL_extCoeff_get_plot_save(dist_LS, fname = False, as_time_series = False):

    wavelength = [450., 525., 624.]
    n = 1.455
    # AOD_list_PMEL = []
    AOD_dict_PMEL = {}
    for w in wavelength:
        AOD = dist_LS.calculate_optical_properties(wavelength=w, n = n)
    #     calculate_AOD(wavelength=w, n = n)
    #     opt= sizedistribution.OpticalProperties(AOD, dist_LS.bins)
    #     AOD_list.append({'wavelength':w, 'opt_inst': AOD})
        AOD_dict_PMEL['%.1f'%w] = AOD

    folder = '/Users/htelg/data/20150414_Svalbard/forPMEL/'

    keys = list(AOD_dict_PMEL.keys())
    keys.sort()
    df = pd.DataFrame()
    f,a = plt.subplots()

    for e, key in enumerate(keys):
        opt_tmp = AOD_dict_PMEL[key]
        ext_coeff = opt_tmp.get_extinction_coeff_verticle_profile()
        df[key] = ext_coeff.data['ext. coeff.']
        ext_coeff.plot(ax = a, color = plt_tools.wavelength_to_rgb(key))
        g = a.get_lines()[-1]
        g.set_label(key)
    # for k in keys:
    a.legend()
    if fname:
        f.savefig(folder+fname + '_vp' + '.png', dpi = 300)
        df.to_csv(folder+fname + '_vp' + '.csv')
    
    vp = vertical_profile.VerticalProfile(df)
    
    if type(as_time_series) == bool:
        if not as_time_series:
            ts = None
    else:    
        ts = vp.convert2timeseries(as_time_series)        
        aa = ts.data.plot()
        aa.set_ylabel('Extinction coefficient (m$^{-1}$)')
        ff = aa.get_figure()    
        if fname:
            ff.savefig(folder+fname + '_ts' + '.png', dpi = 300)
            ts.data.to_csv(folder+fname + '_ts' + '.csv')        
            
    return a,aa,vp, ts
Exemplo n.º 2
0
def PMEL_extCoeff_TS_get_plot_save(dist, fname = False):
#     fname = False
    wavelength = [450., 525., 624.]
    n = 1.455
    # AOD_list_PMEL = []
    AOD_dict_PMEL = {}
    for w in wavelength:
        AOD = dist.calculate_optical_properties(wavelength=w, n = n)
    #     calculate_AOD(wavelength=w, n = n)
    #     opt= sizedistribution.OpticalProperties(AOD, dist.bins)
    #     AOD_list.append({'wavelength':w, 'opt_inst': AOD})
        AOD_dict_PMEL['%.1f'%w] = AOD



    folder = '/Users/htelg/data/20150414_Svalbard/forPMEL/'

    keys = list(AOD_dict_PMEL.keys())
    keys.sort()
    df = pd.DataFrame()
    f,a = plt.subplots()

    for e, key in enumerate(keys):
        opt_tmp = AOD_dict_PMEL[key]
        ext_coeff = opt_tmp['extCoeff_perrow']
        df[key] = ext_coeff.data['ext_coeff']

        data = ext_coeff.data
        a.plot(data.index,data.values*1e5, color = plt_tools.wavelength_to_rgb(key))
    #     ext_coeff.data.plot(ax = a, color = plt_tools.wavelength_to_rgb(key))
        g = a.get_lines()[-1]
        g.set_label(key)
    a.set_ylabel('Extinction coefficient (10$^{-5}$ m$^{-1}$)')
    a.set_xlabel('Time (UTC)')
    # for k in keys:
    f.autofmt_xdate()
    a.legend()
    df = df.sort_index()
    df.index.name = 'TimeUTC'
    if fname:
        df.to_csv(folder+fname + '_ts' + '.csv')  
        f.savefig(folder+fname + '_ts' + '.png', dpi = 300)
    return a,df
Exemplo n.º 3
0
    def plot(self,
             offset=[0, 0, 0, 0],
             airmassfct=True,
             move_max=True,
             legend=True,
             all_on_one_axis=False,
             additional_axes=False,
             errors=False,
             rayleigh=True):
        """plots ... sorry, but this is a messi function. Things should have been done different, e.g too much data
         processing whith the data not put out ... need fixn
        Arguments
        ---------
        offset: list
        airmassfct: bool.
            If the airmass factor is included or not.
            True: naturally the air-mass factor is included in the data, so this does nothing.
            False: data is corrected to correct for the slant angle
        rayleigh: bool or the aod part of the output of miniSASP.simulate_from_size_dist_LS.
            make sure there is no airmassfkt included in this!!
        all_on_one_axis: bool or axes instance
            if True all is plotted in one axes. If axes instances this axis is used.
        """

        m_size = 5
        m_ewidht = 1.5
        l_width = 2
        gridspec_kw = {'wspace': 0.05}
        no_axes = 4
        if all_on_one_axis:
            no_axes = 1
        if additional_axes:
            no_axes = no_axes + additional_axes

        if type(all_on_one_axis).__name__ == 'AxesSubplot':
            a = all_on_one_axis
            f = a.get_figure()
        else:
            f, a = plt.subplots(1, no_axes, gridspec_kw=gridspec_kw)
        columns = [
            '460.3', '460.3 max', '550.4', '550.4 max', '671.2', '671.2 max',
            '860.7', '860.7 max'
        ]
        # peaks_max = [460.3, '460.3 max', 550.4, '550.4 max', 860.7, '860.7 max', 671.2,
        #        '671.2 max']
        if not all_on_one_axis:
            f.set_figwidth(15)
        #################
        for i in range(int(len(columns) / 2)):
            col = plt_tools.wavelength_to_rgb(columns[i * 2]) * 0.8
            intens = self.data[columns[i * 2]].dropna(
            )  # .plot(ax = a, style = 'o', label = '%s nm'%colums[i*2])
            x = intens.index.get_level_values(1)
            if type(rayleigh) == bool:
                if rayleigh:
                    rayleigh_corr = 0
            else:
                # print('mach ick')
                aodt = rayleigh[float(columns[i * 2])].loc[:, ['rayleigh']]
                intenst = intens.copy()
                intenst.index = intenst.index.droplevel(
                    ['Time', 'Sunelevation'])
                aodt_sit = pd.concat([aodt,
                                      intenst]).sort_index().interpolate()
                aodt_sit = aodt_sit.groupby(aodt_sit.index).mean().reindex(
                    intenst.index)
                rayleigh_corr = aodt_sit.rayleigh.values / np.sin(
                    intens.index.get_level_values(2))
                # return aodt

            if not airmassfct:
                amf_corr = np.sin(intens.index.get_level_values(2))
            else:
                amf_corr = 1
            if not all_on_one_axis:
                atmp = a[i]
            else:
                atmp = a

            y = (offset[i] - np.log(intens) - rayleigh_corr) * amf_corr
            g, = atmp.plot(y, x)
            g.set_label('%s nm' % columns[i * 2])
            g.set_linestyle('')
            g.set_marker('o')
            #         g = a.get_lines()[-1]
            g.set_markersize(m_size)
            g.set_markeredgewidth(m_ewidht)
            g.set_markerfacecolor('None')
            g.set_markeredgecolor(col)

            if move_max:
                #             sun_intensities.data.iloc[:,i*2+1].dropna().plot(ax = a)
                intens = self.data[columns[i * 2 + 1]].dropna(
                )  # .plot(ax = a, style = 'o', label = '%s nm'%colums[i*2])
                x = intens.index.values

                g, = a[i].plot(offset[i] - np.log(intens), x)
                #             g = a.get_lines()[-1]
                g.set_color(col)
                #             g.set_solid_joinstyle('round')
                g.set_linewidth(l_width)
                g.set_label(None)

            if i != 0 and not all_on_one_axis:
                atmp.set_yticklabels([])

            if i == 4:
                break
        if all_on_one_axis:
            a.legend()
        else:
            if legend:
                for aa in a:
                    aa.legend()
        if not airmassfct:
            txt = 'OD'
        else:
            txt = 'OD * (air-mass factor)'
        if all_on_one_axis:
            atmp = a
        else:
            atmp = a[0]
        atmp.set_xlabel(txt)
        if not all_on_one_axis:
            atmp.xaxis.set_label_coords(2.05, -0.07)
        atmp.set_ylabel('Altitude (m)')
        return a
Exemplo n.º 4
0
    def plot(self, offset=[0, 0, 0, 0], airmassfct=True, move_max=True, legend=True, all_on_one_axis = False,
             additional_axes=False,
             errors = False,
             rayleigh=True):
        """plots ... sorry, but this is a messi function. Things should have been done different, e.g too much data
         processing whith the data not put out ... need fixn
        Arguments
        ---------
        offset: list
        airmassfct: bool.
            If the airmass factor is included or not.
            True: naturally the air-mass factor is included in the data, so this does nothing.
            False: data is corrected to correct for the slant angle
        rayleigh: bool or the aod part of the output of miniSASP.simulate_from_size_dist_LS.
            make sure there is no airmassfkt included in this!!
        all_on_one_axis: bool or axes instance
            if True all is plotted in one axes. If axes instances this axis is used.
        """

        m_size = 5
        m_ewidht = 1.5
        l_width = 2
        gridspec_kw = {'wspace': 0.05}
        no_axes = 4
        if all_on_one_axis:
            no_axes = 1
        if additional_axes:
            no_axes = no_axes + additional_axes

        if type(all_on_one_axis).__name__ == 'AxesSubplot':
            a = all_on_one_axis
            f = a.get_figure()
        else:
            f, a = plt.subplots(1, no_axes, gridspec_kw=gridspec_kw)
        columns = ['460.3', '460.3 max', '550.4', '550.4 max', '671.2', '671.2 max', '860.7', '860.7 max']
        # peaks_max = [460.3, '460.3 max', 550.4, '550.4 max', 860.7, '860.7 max', 671.2,
        #        '671.2 max']
        if not all_on_one_axis:
            f.set_figwidth(15)
        #################
        for i in range(int(len(columns) / 2)):
            col = plt_tools.wavelength_to_rgb(columns[i * 2]) * 0.8
            intens = self.data[columns[i * 2]].dropna()  # .plot(ax = a, style = 'o', label = '%s nm'%colums[i*2])
            x = intens.index.get_level_values(1)
            if type(rayleigh) == bool:
                if rayleigh:
                    rayleigh_corr = 0
            else:
                # print('mach ick')
                aodt = rayleigh[float(columns[i * 2])].loc[:, ['rayleigh']]
                intenst = intens.copy()
                intenst.index = intenst.index.droplevel(['Time', 'Sunelevation'])
                aodt_sit = pd.concat([aodt, intenst]).sort_index().interpolate()
                aodt_sit = aodt_sit.groupby(aodt_sit.index).mean().reindex(intenst.index)
                rayleigh_corr = aodt_sit.rayleigh.values / np.sin(intens.index.get_level_values(2))
                # return aodt

            if not airmassfct:
                amf_corr = np.sin(intens.index.get_level_values(2))
            else:
                amf_corr = 1
            if not all_on_one_axis:
                atmp = a[i]
            else:
                atmp = a


            y = (offset[i] - np.log(intens) - rayleigh_corr) * amf_corr
            g, = atmp.plot(y, x)
            g.set_label('%s nm' % columns[i * 2])
            g.set_linestyle('')
            g.set_marker('o')
            #         g = a.get_lines()[-1]
            g.set_markersize(m_size)
            g.set_markeredgewidth(m_ewidht)
            g.set_markerfacecolor('None')
            g.set_markeredgecolor(col)

            if move_max:
                #             sun_intensities.data.iloc[:,i*2+1].dropna().plot(ax = a)
                intens = self.data[
                    columns[i * 2 + 1]].dropna()  # .plot(ax = a, style = 'o', label = '%s nm'%colums[i*2])
                x = intens.index.values

                g, = a[i].plot(offset[i] - np.log(intens), x)
                #             g = a.get_lines()[-1]
                g.set_color(col)
                #             g.set_solid_joinstyle('round')
                g.set_linewidth(l_width)
                g.set_label(None)

            if i != 0 and not all_on_one_axis:
                atmp.set_yticklabels([])

            if i == 4:
                break
        if all_on_one_axis:
            a.legend()
        else:
            if legend:
                for aa in a:
                    aa.legend()
        if not airmassfct:
            txt = 'OD'
        else:
            txt = 'OD * (air-mass factor)'
        if all_on_one_axis:
            atmp = a
        else:
            atmp = a[0]
        atmp.set_xlabel(txt)
        if not all_on_one_axis:
            atmp.xaxis.set_label_coords(2.05, -0.07)
        atmp.set_ylabel('Altitude (m)')
        return a
Exemplo n.º 5
0
def plot_POPS_v_mSASP_OD_corr(sun_int_su, 
                              aods_corr, 
                              offset=[3.295,3.44,3.995,4.16], 
                              additional_axes = False,
                              rayleigh = False,
                              error = False,
                              color = False):
    """plots the OD from miniSASP versus that which we simulate from the POPS results.
    Data is corrected for airmass factor.
    Arguments
    ---------
    sun_int_su: sun_int_su instance
    aod_corr: output of miniSASP.simulate_from_size_dist_LS
    rayleigh: bool
        if rayleigh is included or not.
    color: bool, or matplotlib color
        if bool, the color of the msasp channel is used"""
    
    airmassfct = False
    if not rayleigh:
        rayleigh_corr = aods_corr
    else:
        rayleigh_corr = rayleigh
    a = sun_int_su.plot(offset=offset, airmassfct = airmassfct, move_max = False, additional_axes = additional_axes, rayleigh = rayleigh_corr)

    f = a[0].get_figure()
    f.set_figwidth(15)
    # f.set_figheight(10)
    if rayleigh:
        a[0].set_xlabel('Optical depth')
    else:
        a[0].set_xlabel('Arosol optical depth')
    colors_fill = []
    colors_l = []
    for e,aa in enumerate(a):
    #     aa.set_xlim((-0.06,0.39))
        if e > 3:
            break
        aa.set_xlim((-0.01,0.14))
        aa.set_ylim((0,3200))
        aa.grid()
        g = aa.get_lines()[-1]
        txt = g.get_label()
        aa.set_title(txt)
        rgb_l = plt_tools.wavelength_to_rgb(float(txt.strip(' nm'))) * 0.8
        hls = list(colorsys.rgb_to_hls(*rgb_l))
        hls_sum = np.array(hls).sum()
        # hls[1] *=2. # lightness ... makes it brighter
        hls[1] = 0.8 # lightness ... makes it brighter
        # hls[2] *=0.4 #saturation ... makes it more gray
        hls[2] = 0.5 #saturation ... makes it more gray
        if hls_sum == 0:
            hls[1] = 0.6
            hls[2] = 0.0
        rgb = colorsys.hls_to_rgb(*hls)
        colors_fill.append(rgb)
        colors_l.append(rgb_l)
        # print('rgb', rgb_l)
        g.set_label('miniSASP')
        aa.locator_params(axis = 'x', nbins = 6)
    # print(colors_l)
    # print(colors_fill)

    #     aa.vlines(0,0,3200)
    keys = list(aods_corr.keys())
    keys.sort()
#    ms1,ms2,ms3,ms4 = (a[0].get_lines()[-1],a[1].get_lines()[-1],a[2].get_lines()[-1],a[3].get_lines()[-1])
    for e,k in enumerate(keys):
        out = aods_corr[k]

        if not np.any(color):
            col_l = colors_l[e]

        if rayleigh:
            g, = a[e].plot(out['sum'].values, out['sum'].index.values)
            g.set_linewidth(2)
            g.set_color(col_l)
            g.set_label('POPS')
        x = out['aerosol'].values
        y = out['aerosol'].index.values
        if np.any(error):
            col_fill = colors_fill[e]
            a[e].fill_betweenx(y, x * (1 - (error[0] / 100)), x * (1 + (error[1]/100)), color = col_fill)

        g2, = a[e].plot(x,y )
        g2.set_linewidth(2)
        g2.set_color(col_l)
        if rayleigh:
            g2.set_linestyle('--')
            g2.set_label('AOD only')
        else:

            g2.set_label('POPS')



        leg = a[e].legend(numpoints = 1,handlelength=1,  prop={'size':17})
        if e == 0:
            leg.draw_frame(True)
            txt = leg.get_texts()[0]
        #     txt.set_fontsize(10)
        else:
            leg.set_visible(False)
    
    return a