Exemple #1
0
def get_df_acaps(cmf_path: str, debug: bool) -> pd.DataFrame:
    # Get the ACAPS data from HDX
    data_dir = get_temp_dir('covid19_acaps')
    acaps_dir = os.path.join(cmf_path, CRASH_MOVE_MAIN_DIR, CRASH_MOVE_INPUT_DIR, ACAPS_DIR)
    if not debug:
        filename_original = list(query_api(ACAPS_HDX_ADDRESS, data_dir).values())[0]
        filename = f'{datetime.date.today().strftime("%Y%m%d")}_{filename_original}'
        filepath = os.path.join(acaps_dir, filename)
        # Copy to crash move folder
        logger.info(f'Moving dataset to {filepath}')
        shutil.move(os.path.join(data_dir, filename_original), filepath)
    else:
        # If debug, check datadir folder and take the last item
        filename = sorted(os.listdir(acaps_dir))[-1]
    # Read in the dataframe
    df_acaps = pd.read_excel(os.path.join(acaps_dir, filename), sheet_name=1,
                             parse_dates=['DATE_IMPLEMENTED'],
                             usecols=['REGION', 'COUNTRY', 'ISO', 'CATEGORY', 'MEASURE',
                                      'DATE_IMPLEMENTED', 'ID', 'LOG_TYPE'])
    # Drop rows with empty region
    df_acaps = df_acaps.loc[(df_acaps['REGION'] != '') & (~df_acaps['REGION'].isna())]
    # Make month column and convert datetime column to string to write to shape file
    df_acaps['MONTH'] = df_acaps['DATE_IMPLEMENTED'].dt.strftime('%B')
    df_acaps['DATE_IMPLEMENTED'] = df_acaps['DATE_IMPLEMENTED'].dt.strftime('%Y-%m-%d')
    # Fill NAs in dates with "Unknown"
    df_acaps.loc[:, ['DATE_IMPLEMENTED', 'MONTH']] = df_acaps.loc[:, ['DATE_IMPLEMENTED', 'MONTH']].fillna('Unknown')
    return df_acaps
Exemple #2
0
def get_adm0(raw_data_dir: str, output_filename: str):
    filepath_hdx = query_api(HDX_YEMEN_ADDRESS, raw_data_dir,
                             [HDX_YEMEN_FILENAME])[HDX_YEMEN_FILENAME]
    shutil.move(os.path.join(raw_data_dir, filepath_hdx),
                output_filename)
Exemple #3
0
def get_global_seaports(raw_data_dir: str, output_filename: str):
    filepath_hdx = query_api(
        HDX_GLOBAL_SEAPORT_ADDRESS, raw_data_dir,
        [HDX_GLOBAL_SEAPORT_FILENAME])[HDX_GLOBAL_SEAPORT_FILENAME]
    shutil.move(os.path.join(raw_data_dir, filepath_hdx), output_filename)
def get_df_acaps():
    # Get the ACAPS data from HDX
    Path(RAW_DATA_DIR).mkdir(parents=True, exist_ok=True)
    filename = list(query_api(ACAPS_HDX_ADDRESS, RAW_DATA_DIR).values())[0]
    os.rename(os.path.join(RAW_DATA_DIR, filename), RAW_DATA_FILEPATH)