Ejemplo n.º 1
0
	def __reader(self):

		## read pickle if pickle file exisits and 'reset=False' or process raw data
		if (self.pkl_nam in listdir(self.path))&(~self.reset):
			print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading pickle of {self.nam} lidar")
			with open(pth(self.path,self.pkl_nam),'rb') as f:
				fout = pkl.load(f)
			return fout
		else: 
			print(f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading file of {self.nam} lidar and process raw data")

		##=================================================================================================================
		## metadata parameter
		ext_nam, dt_freq, height, col_fun, col_nam, out_nam, oth_col = self.meta.values()

		## read raw data
		_df_con = None
		
		for file in listdir(self.path):
			if ext_nam not in file.lower(): continue
			print(f"\r\t\treading {file}",end='')

			_df = self.__raw_reader(file)

			if _df is not None:
				_df_con = concat([_df_con,_df]) if _df_con is not None else _df

		## concat the concated list
		df = self.__raw_process(_df_con,dt_freq)
		print()

		##=================================================================================================================
		## classify data
		## use dictionary to store data
		fout = {}
		for col, nam in zip(col_nam,out_nam):
			_df = df[[ eval(col_fun)(h,col) for h in height ]].copy()

			_df.columns = array(height).astype(int)
			_df[0] = 0

			fout[nam] = _df[array([0]+height).astype(int)]







		## process other parameter
		if oth_col is not None:
			df.rename(columns=oth_col,inplace=True)
			fout['other'] = df[list(oth_col.values())].copy()

		##=================================================================================================================
		## dump pickle file
		with open(pth(self.path,self.pkl_nam),'wb') as f:
			pkl.dump(fout,f,protocol=pkl.HIGHEST_PROTOCOL)

		return fout
Ejemplo n.º 2
0
    def __reader(self):

        ## read pickle if pickle file exisits and 'reset=False' or process raw data
        if (self.pkl_nam in listdir(self.path)) & (~self.reset):
            print(
                f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading pickle of {self.nam}"
            )
            with open(pth(self.path, self.pkl_nam), 'rb') as f:
                fout = pkl.load(f)
            return fout
        else:
            print(
                f"\n\t{dtm.now().strftime('%m/%d %X')} : Reading file of {self.nam} and process raw data"
            )

        ##=================================================================================================================
        ## read raw data
        f_list = []
        for file in listdir(self.path):
            if '.txt' not in file.lower(): continue
            print(f"\r\t\treading {file}", end='')

            f_list = self.__raw_reader(f_list, file)
        print()

        # fout = self.__raw_process(f_list,dt_freq)
        fout = self.__raw_process(f_list)

        ##=================================================================================================================
        ## dump pickle file
        with open(pth(self.path, self.pkl_nam), 'wb') as f:
            pkl.dump(fout, f, protocol=pkl.HIGHEST_PROTOCOL)

        return fout
Ejemplo n.º 3
0
    def __raw_reader(self, _flist, _file):
        ## customize each instrument
        ## read one file
        with open(pth(self.path, _file), 'r', errors='ignore') as f:
            _temp = read_table(f, skiprows=1)

            _tm_list = []
            for _ in _temp['Date/time']:
                try:
                    if '\u4e0a\u5348' in _:
                        _tm_list.append(
                            dtm.strptime(_.replace('\u4e0a\u5348', 'AM'),
                                         '%Y/%m/%d %p %X'))
                    else:
                        _tm_list.append(
                            dtm.strptime(_.replace('\u4e0b\u5348', 'PM'),
                                         '%Y/%m/%d %p %X') + dtmdt(hours=12))
                except:
                    _tm_list.append(dtm.strptime(_, '%Y/%m/%d'))

            _temp['Date/time'] = _tm_list
            _temp = _temp.set_index('Date/time')
            _temp.columns = array([
                _key.split('-')[0].strip('> um') for _key in list(_temp.keys())
            ]).astype(float)

            _flist.append(_temp.resample('6T').mean())

        return _flist
Ejemplo n.º 4
0
    def __raw_reader(self, _flist, _file):
        ## customize each instrument
        ## read one file
        with open(pth(self.path, _file),
                  'r',
                  encoding='utf-8',
                  errors='ignore') as f:

            _rename = {
                'airtemp_Avg': 'T',
                'relhumidity_Avg': 'RH',
                'airpressure_Avg': 'P',
                'Wsavg_Avg': 'ws',
                'Wdavg_Avg': 'wd',
                'WindDir_SD1_WVT': 'wd_std'
            }

            _temp = read_csv(f, skiprows=(0, 2, 3), parse_dates=[
                'TIMESTAMP'
            ]).rename(columns=_rename).set_index('TIMESTAMP')

            _temp['Td'] = mcalc.dewpoint_from_relative_humidity(
                _temp['T'].to_numpy(dtype=float) * units.degC,
                _temp['RH'].to_numpy(dtype=float) / 100.).m
            _temp['u'] = -sin(_temp['wd'] / 180. * pi) * _temp['ws']
            _temp['v'] = -cos(_temp['wd'] / 180. * pi) * _temp['ws']

            _flist.append(
                _temp[list(_rename.values()) +
                      ['Td', 'u', 'v']].astype(float).resample('1T').mean())

        return _flist
Ejemplo n.º 5
0
def run():

    ## GRIMM
    '''
	start_dtm = dtm(2021,4,1)
	final_dtm = dtm(2021,4,4)
	path = pth('..','data','GRIMM')
	grimm = GRIMM.reader(path,start_dtm,final_dtm,reset=False)
	# dt = grimm.get_data()
	# dt = grimm.plot(pth('..','picture'),dtm(2021,4,2,6),dtm(2021,4,2,18),tick_freq='2h',mean_freq='6T')
	dt = grimm.plot(pth('..','picture'),start_dtm,final_dtm,tick_freq='12h',mean_freq='30T')
	
	# '''

    ## WXT
    # '''
    start_dtm = dtm(2021, 4, 1)
    final_dtm = dtm(2021, 4, 5)
    path = pth('..', 'data', 'WXT')
    wxt = WXT.reader(path, start_dtm, final_dtm, reset=False)
    dt = wxt.get_data()

    # wxt.plot(pth('..','picture'),dtm(2021,4,3,12),dtm(2021,4,4,16),tick_freq='6h',mean_freq='30T')
    # '''
    return dt
Ejemplo n.º 6
0
 def get_data_list(self):
     anndir = pth(self.main_dir, self.data_name, 'annotations')
     if self.split == 'rval':  #use restval data as train data
         ''' debugging print '''
         tmp = pth(anndir, 'rval_{}.json'.format(self.mode))
         print('datalist path: {}'.format(tmp))
         ''''''
         datalist = json.load(
             open(pth(anndir, 'rval_{}.json'.format(self.mode))))
     elif self.split == '2017':
         datalist = json.load(
             open(pth(anndir, '{}2017.json'.format(self.mode))))
         ''' debugging print '''
         tmp = pth(anndir, '{}2017.json'.format(self.mode))
         print('datalist path: {}'.format(tmp))
         ''''''
     return datalist
Ejemplo n.º 7
0
 def get_coco(self):
     year = '2014' if self.coco_split is 'rval' else '2017'
     caps = {}
     for mode in ['train', 'val']:
         caps[mode] = COCO(
             pth(self.main_dir, self.data_name, 'annotations',
                 'captions_{}{}.json'.format(mode, year)))
     # caps = COCO(pth(self.main_dir, self.data_name, 'annotations','captions_{}{}.json'.format('train', year)))
     # caps_val = COCO(pth(self.main_dir, self.data_name, 'annotations','captions_{}{}.json'.format('val', year)))
     return caps
Ejemplo n.º 8
0
    def _plot_pcolor(_nam, _cmap):
        print(f'\tplot {dt_nam} : {_nam}')

        ## parameter
        fs = 13.
        setting = meta[_nam]

        ## plot ws, wd pcolormesh
        ## parameter
        dt = dt_dic[_nam]
        dt.replace(0., n.nan, inplace=True)

        x_tick = dt.asfreq(tick_freq).index
        x_tick_lab = x_tick.strftime('%Y-%m-%d%n%X')

        ## plot
        fig, ax = subplots(figsize=(12, 6), dpi=150.)
        pm = ax.pcolormesh(dt.index,
                           dt.keys(),
                           dt[:-1].T[:-1],
                           cmap=_cmap,
                           vmin=setting['vmin'],
                           vmax=setting['vmax'])

        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + 0.02, box.width, box.height])
        cax = fig.add_axes([.92, box.y0 + 0.02, .015, box.height])

        cb = fig.colorbar(pm, cax=cax)

        ax.tick_params(which='major', length=6., labelsize=fs - 2.)
        ax.tick_params(which='minor', length=3.5)
        cb.ax.tick_params(which='major', length=5., labelsize=fs - 2.)
        cb.ax.tick_params(which='minor', length=2.5)
        ax.set(xticks=x_tick, ylim=(setting['ylim_bot'], setting['ylim_top']))

        ax.set_xticklabels(x_tick_lab)

        ax.set_xlabel('Time', fontsize=fs)
        ax.set_ylabel('Height (m)', fontsize=fs)
        cb.ax.set_title(setting['cb_label'], fontsize=fs - 2.)

        fig.suptitle(f'{dt_nam.upper()} data : {_nam}',
                     fontsize=fs + 2.,
                     style='italic')

        # show()
        fig.savefig(
            pth(
                save_path,
                f'{dt_nam}_{_nam}_{dt.index[0].strftime("%Y%m%d%H%M")}-{dt.index[-1].strftime("%Y%m%d%H%M")}.png'
            ))
        close()
Ejemplo n.º 9
0
 def __init__(self, config, transform, mode):
     self.main_dir = config.main_dir
     self.data_name = config.data_name
     self.mode = mode
     self.max_token_len = config.max_token_len
     self.split = self.get_split_type(config)
     self.data = self.get_data_list()
     self.vocab = get_vocab(self.main_dir, self.data_name)
     self.transform = transform
     ''' debugging '''
     self.coco_split = config.coco_split
     tmp = pth(
         self.main_dir, self.data_name, 'annotations',
         'captions_{}{}.json'.format(
             self.mode, '2014' if self.coco_split is 'rval' else '2017'))
     print('caption path: {}'.format(tmp))
     ''''''
     self.caps = self.get_coco()
Ejemplo n.º 10
0
    def _plot(meta_nam):
        ## plot quiver and plot z_ws
        meta = meta_dt[meta_nam]

        ## parameter
        fs = 15.
        setting = meta['quiver']

        ## plot
        fig, ax = subplots(figsize=(12, 8), dpi=150.)

        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + 0.05, box.width, box.height])

        ## z_ws
        if 'z_ws' in dt_dic.keys():
            _plot_z_ws(fig, ax, fs, ax.get_position(), meta)
        ## quiver
        x_tick, _st, _fn = _plot_quiver(fig, ax, fs, ax.get_position(), meta)

        ## other figure setting
        ax.tick_params(which='major', length=6., labelsize=fs - 2.)
        ax.tick_params(which='minor', length=3.5)

        ax.set(xticks=x_tick, ylim=(setting['ylim_bot'], setting['ylim_top']))
        ax.set_xticklabels(x_tick.strftime('%Y-%m-%d%n%HLST'))

        # ax.set_xlabel('Time',fontsize=fs)
        ax.set_ylabel('Height (m)', fontsize=fs)

        fig.suptitle(
            f'{dt_nam.upper()} lidar wind profile (every {setting["dt_freq"].replace("T"," min")}) ',
            fontsize=fs + 2.,
            style='italic')

        fig.savefig(
            pth(
                save_path[meta_nam],
                f'{dt_nam}_wswd_{_st.strftime("%Y%m%d%H%M")}-{_fn.strftime("%Y%m%d%H%M")}.png'
            ))
Ejemplo n.º 11
0
    def __getitem__(self, index):
        info = self.data[index]
        img = Image.open(
            pth(self.main_dir, self.data_name, info['filepath'],
                info['filename'])).convert('RGB')
        if info['filepath'] in ['train2017', 'train2014']:
            caps = self.caps['train']
        else:
            caps = self.caps['val']
        anns = caps.loadAnns(info['sentid'])

        img_id = info['imgid']
        # random pick one of 5 text captions
        idx = random.randint(0, len(anns) - 1) if self.mode is 'train' else 0
        cap = anns[idx]['caption']
        vec = self.encode_token(cap)
        # tokens = nltk.tokenize.word_tokenize(str(cap).lower().decode('utf-8'))
        # cap = []
        # # cap.append(self.vocab('<start>'))
        # cap.extend([self.vocab(token) for token in tokens])
        # cap.append(self.vocab('<end>'))
        return self.transform(img), vec, img_id
Ejemplo n.º 12
0
def plot_all(dt_dic, fig_path='.', tick_freq='6h', input_tick=None):

    ## parameter
    dt_nam = dt_dic['nam'].split('_')[0]
    _ind = dt_dic['ws'].index
    print(f'\nPlot {dt_nam} data')

    ## make picture dir
    dir_path = pth(fig_path, dt_nam)
    mkdir(dir_path) if not exists(dir_path) else None

    save_path = {}
    save_path[dt_nam] = pth(
        dir_path,
        f'{_ind[0].strftime("%Y-%m-%d %H")}_{_ind[-1].strftime("%Y-%m-%d %H")}'
    )
    mkdir(save_path[dt_nam]) if not exists(save_path[dt_nam]) else None

    mkdir(
        pth(fig_path,
            'lidar_comp')) if not exists(pth(fig_path, 'lidar_comp')) else None
    save_path['comp'] = pth(
        fig_path, 'lidar_comp',
        f'{_ind[0].strftime("%Y-%m-%d %H")}_{_ind[-1].strftime("%Y-%m-%d %H")}'
    )
    mkdir(save_path['comp']) if not exists(save_path['comp']) else None

    ## function
    meta = meta_dt[dt_nam]

    def _plot_pcolor(_nam, _cmap):
        print(f'\tplot {dt_nam} : {_nam}')

        ## parameter
        fs = 13.
        setting = meta[_nam]

        ## plot ws, wd pcolormesh
        ## parameter
        dt = dt_dic[_nam]
        dt.replace(0., n.nan, inplace=True)

        x_tick = dt.asfreq(tick_freq).index
        x_tick_lab = x_tick.strftime('%Y-%m-%d%n%X')

        ## plot
        fig, ax = subplots(figsize=(12, 6), dpi=150.)
        pm = ax.pcolormesh(dt.index,
                           dt.keys(),
                           dt[:-1].T[:-1],
                           cmap=_cmap,
                           vmin=setting['vmin'],
                           vmax=setting['vmax'])

        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + 0.02, box.width, box.height])
        cax = fig.add_axes([.92, box.y0 + 0.02, .015, box.height])

        cb = fig.colorbar(pm, cax=cax)

        ax.tick_params(which='major', length=6., labelsize=fs - 2.)
        ax.tick_params(which='minor', length=3.5)
        cb.ax.tick_params(which='major', length=5., labelsize=fs - 2.)
        cb.ax.tick_params(which='minor', length=2.5)
        ax.set(xticks=x_tick, ylim=(setting['ylim_bot'], setting['ylim_top']))

        ax.set_xticklabels(x_tick_lab)

        ax.set_xlabel('Time', fontsize=fs)
        ax.set_ylabel('Height (m)', fontsize=fs)
        cb.ax.set_title(setting['cb_label'], fontsize=fs - 2.)

        fig.suptitle(f'{dt_nam.upper()} data : {_nam}',
                     fontsize=fs + 2.,
                     style='italic')

        # show()
        fig.savefig(
            pth(
                save_path,
                f'{dt_nam}_{_nam}_{dt.index[0].strftime("%Y%m%d%H%M")}-{dt.index[-1].strftime("%Y%m%d%H%M")}.png'
            ))
        close()

    ## plot quiver and vertical wind
    def _plot_quiver(fig, ax, fs, box, meta):

        ## parameter
        def wswd2uv(_ws, _wd):
            return -n.sin(_wd / 180. * n.pi) * _ws, -n.cos(
                _wd / 180. * n.pi) * _ws

        cmap_bot = cm.get_cmap('RdGy', 512)(n.linspace(.15, .5, 512))
        cmap_top = cm.get_cmap('RdGy', 512)(n.linspace(.5, 1., 512))
        cmap = mc.ListedColormap(n.vstack((cmap_bot, cmap_top)))
        cmap = 'jet'

        setting = meta['quiver']
        # dt_ws, dt_wd = dt_dic['ws'].asfreq(dt_freq)[::setting['sep']], dt_dic['wd'].asfreq(dt_freq)[::setting['sep']]
        dt_ws, dt_wd = dt_dic['ws'].asfreq(
            setting['dt_freq']), dt_dic['wd'].asfreq(setting['dt_freq'])

        # dt_ws[dt_ws.keys()[0]].replace(0.,n.nan,inplace=True)
        # dt_wd[dt_ws.keys()[0]].replace(0.,n.nan,inplace=True)

        ## (1) replace 0 as nan, process the by-product after interpolate
        ## (2) get the mask below 2.5
        ## (3) set the value as nan under mask
        ## (4) get the mask out value, apply scatter plot
        dt_ws.replace(0., n.nan, inplace=True)
        _mask = dt_ws.copy() < 2.5
        dt_ws.mask(_mask, n.nan, inplace=True)
        _index, _height = n.meshgrid(dt_ws.index, dt_ws.keys())

        ## change ws, wd to u, v
        ## get height as y axis and get x ticks
        _u, _v = wswd2uv(1.5, dt_wd)
        height = n.array(list(dt_ws.keys())).astype(float)
        x_tick = input_tick if input_tick is not None else dt_ws.asfreq(
            tick_freq).index

        ## plot
        sc = ax.scatter(_index[_mask.T],
                        _height[_mask.T],
                        s=15,
                        fc='None',
                        ec='#666666',
                        label='< 2.5 m/s')

        qv = ax.quiver(_u.index,
                       height[::setting['sep']],
                       _u.T[::setting['sep']],
                       _v.T[::setting['sep']],
                       dt_ws.T[::setting['sep']].values,
                       cmap=cmap,
                       scale=50,
                       clim=(setting['vmin'], setting['vmax']))

        cax = fig.add_axes([.92, box.y0, .015, box.height])

        cb = fig.colorbar(qv, cax=cax)
        cb.ax.tick_params(which='major', length=5., labelsize=fs - 2.)
        cb.ax.tick_params(which='minor', length=2.5)
        cb.ax.set_title(setting['cb_label'], fontsize=fs - 2.)

        ax.legend(handles=[sc],
                  framealpha=0,
                  fontsize=fs - 1.,
                  loc=10,
                  bbox_to_anchor=(0.1, 1.025),
                  handlelength=1.)

        return x_tick, dt_ws.index[0], dt_ws.index[-1]

    ## plot z_ws pcolormesh
    def _plot_z_ws(fig, ax, fs, box, meta):

        ## parameter
        setting = meta['z_ws']

        # cmap_bot = cm.get_cmap('Blues_r',512)(n.linspace(.5,1.,512))
        cmap_top = cm.get_cmap('Greys', 512)(n.linspace(.45, .6, 512))
        cmap_bot = cm.get_cmap('Greys', 512)(n.linspace(.0, .3, 512))
        cmap = mc.ListedColormap(n.vstack((cmap_bot, cmap_top)))

        ## data
        dt = dt_dic['z_ws']
        # dt.replace(0.,n.nan,inplace=True)

        ## plot
        ## set z_ws as background and the colorbar is horizontal
        pm = ax.pcolormesh(dt.index,
                           dt.keys(),
                           dt[1:].T[1:],
                           cmap=cmap,
                           vmin=setting['vmin'],
                           vmax=setting['vmax'])

        box = ax.get_position()
        cax = fig.add_axes([box.x0, .045, box.width, .015])

        cb = fig.colorbar(pm, cax=cax, extend='both', orientation='horizontal')

        cb.ax.tick_params(which='major', length=5., labelsize=fs - 2.)
        cb.ax.tick_params(which='minor', length=2.5)

        cb.ax.set_title(setting['cb_label'], fontsize=fs - 2.)

    def _plot(meta_nam):
        ## plot quiver and plot z_ws
        meta = meta_dt[meta_nam]

        ## parameter
        fs = 15.
        setting = meta['quiver']

        ## plot
        fig, ax = subplots(figsize=(12, 8), dpi=150.)

        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + 0.05, box.width, box.height])

        ## z_ws
        if 'z_ws' in dt_dic.keys():
            _plot_z_ws(fig, ax, fs, ax.get_position(), meta)
        ## quiver
        x_tick, _st, _fn = _plot_quiver(fig, ax, fs, ax.get_position(), meta)

        ## other figure setting
        ax.tick_params(which='major', length=6., labelsize=fs - 2.)
        ax.tick_params(which='minor', length=3.5)

        ax.set(xticks=x_tick, ylim=(setting['ylim_bot'], setting['ylim_top']))
        ax.set_xticklabels(x_tick.strftime('%Y-%m-%d%n%HLST'))

        # ax.set_xlabel('Time',fontsize=fs)
        ax.set_ylabel('Height (m)', fontsize=fs)

        fig.suptitle(
            f'{dt_nam.upper()} lidar wind profile (every {setting["dt_freq"].replace("T"," min")}) ',
            fontsize=fs + 2.,
            style='italic')

        fig.savefig(
            pth(
                save_path[meta_nam],
                f'{dt_nam}_wswd_{_st.strftime("%Y%m%d%H%M")}-{_fn.strftime("%Y%m%d%H%M")}.png'
            ))

    ## plot
    # _plot_pcolor('ws','jet')
    # _plot_pcolor('z_ws',cmap)

    # _plot('comp')
    _plot(dt_nam)
Ejemplo n.º 13
0
# from pandas import date_range, concat
import json as jsn

## bugs box
"""


# """

__all__ = [
    'plot_all',
]

# parameter
cur_file_path = dirname(realpath(__file__))
with open(pth(cur_file_path, 'metadata.json'), 'r') as f:
    meta_dt = jsn.load(f)


## plot all variable
def plot_all(dt_dic, fig_path='.', tick_freq='6h', input_tick=None):

    ## parameter
    dt_nam = dt_dic['nam'].split('_')[0]
    _ind = dt_dic['ws'].index
    print(f'\nPlot {dt_nam} data')

    ## make picture dir
    dir_path = pth(fig_path, dt_nam)
    mkdir(dir_path) if not exists(dir_path) else None
Ejemplo n.º 14
0
    def plot(self,
             fig_path='.',
             start=None,
             final=None,
             mean_freq=None,
             tick_freq='6h'):

        ## plot time series
        ## make picture dir
        save_path = pth(fig_path, 'WXT')
        mkdir(save_path) if not exists(save_path) else None

        ## get data
        df = self.get_data(start, final, mean_freq)

        ## plot (T, Td), pressure, uv wind
        ## parameter
        fs = 13.
        x_tick = df.asfreq(tick_freq).index
        x_tick_lab = x_tick.strftime('%Y-%m-%d%n%X')

        ## plot
        fig, axes = subplots(3,
                             1,
                             figsize=(10, 7),
                             dpi=150.,
                             gridspec_kw=dict(wspace=.325, hspace=.45),
                             sharex=False,
                             sharey=False)

        ## plot T and P
        axes[0].plot(df['Td'], color='#4cffff', label='$T_d$')

        for ax, _nam in zip(axes, ['T', 'P']):
            setting = self.meta[_nam]

            ax.plot(df[_nam], color=setting['color'], label=_nam)

            ax.set(ylim=(setting['ylim_bot'], setting['ylim_top']),
                   xticks=x_tick)
            ax.set_title(setting['title'], fontsize=fs)
            ax.set_ylabel(setting['ylabel'], fontsize=fs)
            ax.set_xticklabels('')

        axes[0].legend(framealpha=0, fontsize=fs - 2.5)

        ## plot uv
        ax = axes[2]
        setting = self.meta['wind']

        itv = setting['itv']
        ax.quiver(df.index[::itv],
                  0.,
                  df['u'][::itv],
                  df['v'][::itv],
                  scale=5,
                  scale_units='inches',
                  color='#cc99ff',
                  headwidth=2.)
        # ax.quiver(df.index[::itv],0.,df['u'][::itv],df['v'][::itv],angles='xy', scale_units='xy', scale=1.,color='#cc99ff')

        ax.set(xticks=x_tick, ylim=(-2, 2), xlim=(df.index[0], df.index[-1]))
        ax.set_title(setting['title'], fontsize=fs)
        ax.set_ylabel(setting['ylabel'], fontsize=fs)

        ax.set_xticklabels(x_tick_lab)

        fig.text(.5, .03, 'Time', ha='center', fontsize=fs)

        fig.suptitle('WXT data', fontsize=fs + 2., style='italic')
        fig.savefig(
            pth(
                save_path,
                f'WXT_{df.index[0].strftime("%Y%m%d%H%M")}-{df.index[-1].strftime("%Y%m%d%H%M")}.png'
            ))
        # show()
        close()

        ## plot diurnal cycle
        df['diurnal'] = df.index.map(lambda _: _.strftime('%H:00'))
        df_diu = df.groupby('diurnal').mean()
        x_tick = list(df['diurnal'])[::6]

        ## parameter
        fs = 13.

        #'''
        ## plot
        fig, axes = subplots(3,
                             1,
                             figsize=(8, 6),
                             dpi=150.,
                             gridspec_kw=dict(wspace=.325, hspace=.325),
                             sharex=False,
                             sharey=False)

        for _nam, ax in zip(['T', 'Td', 'P'], axes.flatten()):

            setting = self.meta['diu'][_nam]
            ax.plot(df_diu[_nam], c=setting['color'])

            ax.tick_params(which='major',
                           direction='in',
                           length=7,
                           labelsize=fs - 2.5)
            [ax.spines[axis].set_visible(False) for axis in ['right', 'top']]

            ax.set(ylim=(setting['ylim_bot'], setting['ylim_top']),
                   xticks=x_tick)
            ax.set_xticklabels('')

            ax.set_ylabel(setting['ylabel'], fontsize=fs)

            ax.set_title(setting['title'], fontsize=fs)

        ax.set_xticklabels(x_tick)

        fig.text(.5, .03, 'Time', ha='center', fontsize=fs)

        fig.suptitle(
            f'WXT diurnal cycle : from {df.index[0].strftime("%Y/%m/%d %H%M")} to {df.index[-1].strftime("%Y/%m/%d %H%M")}',
            fontsize=fs + 2.,
            style='italic')
        fig.savefig(
            pth(
                save_path,
                f'WXT_diuunal_{df.index[0].strftime("%Y%m%d%H%M")}-{df.index[-1].strftime("%Y%m%d%H%M")}.png'
            ))
        close()

        return df
Ejemplo n.º 15
0
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = pth(BASE_DIR, "static_root")
MEDIA_ROOT = pth(BASE_DIR, "media")

STATICFILES_DIRS = (
    pth(BASE_DIR, "static"),
)

TEMPLATE_DIRS = (
    pth(BASE_DIR, "templates"),
)
Ejemplo n.º 16
0
    def plot(self,
             fig_path='.',
             start=None,
             final=None,
             mean_freq=None,
             tick_freq='6h'):

        from matplotlib.colors import LogNorm
        from matplotlib.pyplot import subplots, close, show

        ## plot time series
        ## make picture dir
        save_path = pth(fig_path, self.nam)
        mkdir(save_path) if not exists(save_path) else None

        ## get data
        dt = self.get_data(start, final, mean_freq)

        ## plot (T, Td), pressure, uv wind
        ## parameter
        fs = 13.
        x_tick = dt.asfreq(tick_freq).index
        x_tick_lab = x_tick.strftime('%Y-%m-%d%n%X')

        setting = self.meta

        ## plot
        fig, ax = subplots(figsize=(12, 6), dpi=150.)
        pm = ax.pcolormesh(dt.index,
                           dt.keys(),
                           dt.T,
                           cmap='jet',
                           norm=LogNorm(vmin=setting['vmin'],
                                        vmax=setting['vmax']),
                           shading='auto')
        ax.hlines(2.5, dt.index[0], dt.index[-1], color='#000000', ls='--')
        ax.hlines(10., dt.index[0], dt.index[-1], color='#000000', ls='--')

        box = ax.get_position()
        ax.set_position([box.x0, box.y0 + 0.02, box.width, box.height])
        cax = fig.add_axes([.92, box.y0 + 0.02, .015, box.height])

        cb = fig.colorbar(pm, cax=cax)

        ax.tick_params(which='major', length=6., labelsize=fs - 2.)
        ax.tick_params(which='minor', length=3.5)
        cb.ax.tick_params(which='major', length=5., labelsize=fs - 2.)
        cb.ax.tick_params(which='minor', length=2.5)
        ax.set(xticks=x_tick, yscale='log')

        ax.set_xticklabels(x_tick_lab)

        ax.set_xlabel('Time', fontsize=fs)
        ax.set_ylabel('Diameter ($\mu m$)', fontsize=fs)
        cb.ax.set_title('number conc.\n(#/$m^3$/$\Delta log D_p$)',
                        fontsize=fs - 2.)

        fig.suptitle(f'GRIMM data ({mean_freq} ave.)',
                     fontsize=fs + 2.,
                     style='italic')

        # show()
        fig.savefig(
            pth(
                save_path,
                f'GRIMM_{dt.index[0].strftime("%Y%m%d%H%M")}-{dt.index[-1].strftime("%Y%m%d%H%M")}.png'
            ))
        close()

        return dt
Ejemplo n.º 17
0
def run():

    res = 0
    fig_pth = pth('..', 'picture')

    ## NDU
    # '''
    start_dtm = dtm(2021, 4, 1, 0, 0, 0)
    final_dtm = dtm(2021, 4, 6, 0, 0, 0)
    path = pth('..', 'data', 'Lidar_NDU', 'use')
    reader = NDU.reader(path, start_dtm, final_dtm, reset=res)
    # dt = reader.get_data(dtm(2021,4,2,0,0,0),dtm(2021,4,5,0,0,0))
    dt = reader.get_data()

    plot.plot_all(dt, fig_pth, tick_freq='24h')
    # '''

    ## SSC
    # '''
    start_dtm = dtm(2021, 4, 1)
    final_dtm = dtm(2021, 4, 6)
    path = pth('..', 'data', 'Lidar_SSC')
    reader = SSC.reader(path, start_dtm, final_dtm, reset=res)
    # dt = reader.get_data(dtm(2021,4,2,0,0,0),dtm(2021,4,5,0,0,0))
    dt = reader.get_data()

    plot.plot_all(dt, fig_pth, tick_freq='24h')
    # '''

    ## RCEC
    # '''
    start_dtm = dtm(2021, 4, 1)
    final_dtm = dtm(2021, 4, 6)
    path = pth('..', 'data', 'Lidar_RCEC')
    reader = RCEC.reader(path, start_dtm, final_dtm, reset=res)
    # dt = reader.get_data(dtm(2021,4,2,0,0,0),dtm(2021,4,5,0,0,0))
    dt = reader.get_data()

    plot.plot_all(dt, fig_pth, tick_freq='24h')
    # '''

    ## TORI
    # '''
    start_dtm = dtm(2021, 4, 1)
    final_dtm = dtm(2021, 4, 6)
    path = pth('..', 'data', 'Lidar_TORI')
    reader = TORI.reader(path, start_dtm, final_dtm, reset=res)
    # dt = reader.get_data(dtm(2021,4,2,0,0,0),dtm(2021,4,5,0,0,0))
    dt = reader.get_data()

    plot.plot_all(dt, fig_pth, tick_freq='24h')
    # '''

    ## GRIMM
    '''
	start_dtm = dtm(2021,4,1)
	final_dtm = dtm(2021,4,4)
	path = pth('..','data','GRIMM')
	grimm = GRIMM.reader(path,start_dtm,final_dtm,reset=False)
	# dt = grimm.get_data()
	# dt = grimm.plot(pth('..','picture'),dtm(2021,4,2,6),dtm(2021,4,2,18),tick_freq='2h',mean_freq='6T')
	dt = grimm.plot(pth('..','picture'),start_dtm,final_dtm,tick_freq='12h',mean_freq='30T')
	
	# '''

    ## WXT
    '''
	start_dtm = dtm(2021,4,1)
	final_dtm = dtm(2021,4,5)
	path = pth('..','data','WXT')
	wxt = WXT.reader(path,start_dtm,final_dtm,reset=False)
	dt = wxt.get_data()

	dt = wxt.plot(pth('..','picture'),dtm(2021,4,3,12),dtm(2021,4,4,16),tick_freq='6h',mean_freq='30T')
	# '''
    return dt