Skip to content
Snippets Groups Projects
lib_era5_land_pixel.py 39 KiB
Newer Older
            with lock:
                pbar.update(round(shared_value.value - pbar.n))

        # Wait for all processes to complete
        for result in results:
            result.wait()

    # Close the pool
    pool.close()
    pool.join()
    rain_list = []
    ET0_list = []
    for i in range(max_cpu):
        rain_list.extend(results[i].get())
        ET0_list.extend(results[max_cpu + i].get())
    del results, result
    weather_dataframe = pd.DataFrame(rain_list, columns = ['date', 'id', 'Rain', 'LC'])
    weather_dataframe['ET0'] = pd.DataFrame(ET0_list, columns = ['date', 'id', 'ET0', 'LC'])['ET0']
    
    # Reorder columns
    weather_dataframe = weather_dataframe.reindex(columns = ['date', 'id', 'Rain', 'ET0', 'LC'])
    
    # Format datatypes
    weather_dataframe['Rain'] = np.round(weather_dataframe['Rain']).astype(int)
    weather_dataframe['ET0'] = np.round(weather_dataframe['ET0']).astype(int)
    
    # Change date type
    weather_dataframe['date'] = pd.to_datetime(weather_dataframe['date'])
    
    # Save dataframe to csv
    weather_dataframe.to_csv(save_path, index = False)
    
    return None