def _load_ground_weather(self, reload):
     
     # 保存ファイルの有無を確認する
     ground_weather_csv = os.path.join(self._temp_dir, 'ground_weather.csv')
     exist_csv = os.path.isfile(ground_weather_csv)
     
     if (reload == False) and (exist_csv == True):
         # 読み込み済み、かつ、リロード無しの場合は、
         # 保存したファイルを読み込む
         ground_df = pd.read_csv(ground_weather_csv, index_col=0, parse_dates=[1])
     else:
         ground_dir = os.path.join(self._input_dir, 'ground_weather')
         ground_df = wfile.get_ground_weather(ground_dir)
         ground_df.to_csv(ground_weather_csv)
     
     return ground_df
Beispiel #2
0
    def _load_ground_weather(self, reload):

        # 保存ファイルの有無を確認する
        os.makedirs(self._temp_dir, exist_ok=True)
        ground_weather_csv = os.path.join(self._temp_dir, 'ground_weather.csv')
        exist_csv = os.path.isfile(ground_weather_csv)

        if (reload == False) and (exist_csv == True):
            # 読み込み済み、かつ、リロード無しの場合は、
            # 保存したファイルを読み込む
            ground_df = pd.read_csv(ground_weather_csv,
                                    index_col=0,
                                    parse_dates=[1])
        else:
            ground_dir = os.path.join(self._input2_dir, 'ground_weather')
            ground_df = wfile.get_ground_weather(ground_dir)
            ground_df.to_csv(ground_weather_csv)

        # 3時,9時,15時,21時のデータを抽出する
        ground_df = util.extract_row_isin(ground_df, '時', [3, 9, 15, 21])

        # 天気を数値に変換する
        ground_df = wdfproc.convert_weather_to_interger(ground_df)

        # 天気を所定の境界値で分類する
        if self._weather_convert_mode == 'rain_or_not':
            convert_mode = WeatherConvertMode.RainOrNot
        else:
            convert_mode = WeatherConvertMode.Coarse

        ground_df = wdfproc.replace_weather(ground_df,
                                            columns=['Mito_天気'],
                                            mode=convert_mode)
        #ground_df = wdfproc.replace_weather(ground_df, columns=['Mito_天気'], mode=WeatherConvertMode.RainOrNot)

        # 水戸の天気,海面気圧,気温,湿度を抽出する
        extract_columns = [
            '日付', '時', 'Mito_海面気圧(hPa)', 'Mito_気温(℃)', 'Mito_湿度(%)', 'Mito_天気'
        ]
        ground_df = ground_df.loc[:, extract_columns]

        return ground_df
def get_ground_weather():

    # カレントディレクトリを取得する
    cwd = os.getcwd()

    # 地上気象データを取得する
    ground_weather_csv = 'ground_weather.csv'
    if os.path.isfile(ground_weather_csv):
        ground_df = pd.read_csv(ground_weather_csv,
                                index_col=0,
                                parse_dates=[1])

    else:
        ground_dir = os.path.join(cwd, 'ground_weather')
        ground_df = wfile.get_ground_weather(ground_dir)
        ground_df.to_csv(ground_weather_csv)

    # 天気記号を数値に変換する
    ground_df = wdfproc.convert_symbol_to_number(ground_df)

    # 地上気象データからNaNが含まれる列を削る
    ground_df = wdfproc.drop_ground(ground_df)
    ground_df.to_csv('ground2.csv')

    # 風速・風向きを数値に変換する
    ground_df = wdfproc.convert_wind_to_vector_ground(ground_df)
    ground_df.to_csv('ground3.csv')

    # 天気を数値に変換する
    ground_df = wdfproc.convert_weather_to_interger(ground_df)
    ground_df.to_csv('ground4.csv')

    # 雲量を浮動小数点数に変換する
    ground_df = wdfproc.convert_cloud_volume_to_float(ground_df)
    ground_df.to_csv('ground5.csv')

    # 天気を指定した境界値で分類する
    #  - 水戸は3分割、それ以外は○分割にする
    weather_cols = [col for col in ground_df.columns if ('天気' in col)]
    weather_cols.pop(weather_cols.index('Mito_天気'))
    ground_df = wdfproc.replace_weather(ground_df,
                                        columns=weather_cols,
                                        mode=wdfproc.WeatherConvertMode.Coarse)
    ground_df.to_csv('ground6.csv')
    ground_df = wdfproc.replace_weather(ground_df, columns=['Mito_天気'])
    ground_df.to_csv('ground7.csv')

    # 浮動小数点数を32ビットに変換する
    ground_df = wdfproc.type_to_float32(ground_df)
    ground_df.to_csv('ground8.csv')

    # 不要な列を除去する
    ground_df = remove_cols(
        ground_df,
        #        [ '現地気圧', '海面気圧', '気温', '露点温度', '蒸気圧', '日照時間',
        #          '降雪', '積雪', '雲量', '視程', '全天日射', '降水量', '風速' ]
        [
            '現地気圧', '海面気圧', '気温', '露点温度', '蒸気圧', '日照時間', '降雪', '積雪', '雲量',
            '視程', '全天日射', '降水量'
        ])

    print(ground_df.info())

    return ground_df
 def _load_ground_weather(self, reload):
     
     # 保存ファイルの有無を確認する
     os.makedirs(self._temp_dir, exist_ok=True)
     ground_weather_csv = os.path.join(self._temp_dir, 'ground_weather.csv')
     exist_csv = os.path.isfile(ground_weather_csv)
     
     if (reload == False) and (exist_csv == True):
         # 読み込み済み、かつ、リロード無しの場合は、
         # 保存したファイルを読み込む
         ground_df = pd.read_csv(ground_weather_csv, index_col=0, parse_dates=[1])
     else:
         ground_dir = os.path.join(self._input2_dir, 'ground_weather')
         ground_df = wfile.get_ground_weather(ground_dir)
         ground_df.to_csv(ground_weather_csv)
     
     # 3時,9時,15時,21時のデータを抽出する
     ground_df = util.extract_row_isin(ground_df, '時', [3, 9, 15, 21])
     
     # 天気記号を数値に変換する
     ground_df = wdfproc.convert_symbol_to_number(ground_df)
     
     # 地上気象データから不要データを除去する
     ground_df = wdfproc.drop_unneeded_ground(ground_df)
     
     # 風速・風向きを数値に変換する
     ground_df = wdfproc.convert_wind_to_vector_ground(ground_df)
     
     # 天気を数値に変換する
     ground_df = wdfproc.convert_weather_to_interger(ground_df)
     
     # 雲量を浮動小数点数に変換する
     ground_df = wdfproc.convert_cloud_volume_to_float(ground_df)
     
     # 天気を所定の境界値で分類する
     if self._weather_convert_mode == 'rain_or_not':
         convert_mode = WeatherConvertMode.RainOrNot
     else:
         convert_mode = WeatherConvertMode.Coarse
     
     # 天気を晴れ,くもり,雨のいずれかに分類する
     weather_cols = [col for col in ground_df.columns if('天気' in col)]
     ground_df = wdfproc.replace_weather(
                         ground_df, columns=weather_cols, 
                          mode=wdfproc.WeatherConvertMode.Coarse)
     
     # 月の平均値を追加する
     #ground_df = util.add_monthly_mean(ground_df, ['天気'])
     
     # 不要な列を除去する
     ground_df = wdfproc.drop_columns(
         ground_df, 
         #[ '現地気圧', '海面気圧', '降水量', '気温', '露点温度', '蒸気圧', '湿度', '風速', 
         #  '日照時間', '全天日射', '降雪', '積雪', '視程', ]
         [ '現地気圧', '露点温度', '蒸気圧', '日照時間', 
           '降雪', '積雪', '視程', '全天日射' ]
     )
     
     #ground_df = wdfproc.replace_weather(ground_df, columns=[self._label_name], mode=convert_mode)
     
     # 水戸の天気,海面気圧,気温,湿度を抽出する
     #extract_columns = ['日付', '時', 'Mito_海面気圧(hPa)', 'Mito_気温(℃)', 'Mito_湿度(%)', 'Mito_天気']
     #ground_df = ground_df.loc[:, extract_columns]
     
     return ground_df
# coding: utf-8

import os
import wfile
import wdfproc

##################################################
# メイン
##################################################
if __name__ == '__main__':
    
    # カレントディレクトリを取得する
    cwd = os.getcwd()

    # 地上気象データを取得する
    ground_dir = os.path.join(cwd, 'ground_weather')
    ground_df = wfile.get_ground_weather(ground_dir)
    
    # 地上気象データからNaNが含まれる列を削る
    ground_df = wdfproc.drop_ground(ground_df)
    ground_df.to_csv('ground.csv')

    # 高層気象データを取得する
    highrise_dir = os.path.join(cwd, 'highrise_weather')
    highrise_df = wfile.get_highrise_weather(highrise_dir)
    highrise_df.to_csv('highrise.csv')