Created
October 26, 2019 19:58
-
-
Save matteodefelice/5cdf827bacd830f594707dbe07204f33 to your computer and use it in GitHub Desktop.
Python code to extract river discharge on a specific coordinate from C3S EFAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import pandas as pd | |
from pyproj import Proj, transform | |
import os.path | |
# Data for projections | |
# CHECK WITH https://epsg.io/transform#s_srs=4326&t_srs=3035&x=17.6830006&y=48.4970017 | |
inProj = Proj(init='epsg:4326') | |
outProj = Proj(init='epsg:3035') | |
PATH_TO_EFAS = '/PATH/TO/EFAS/EFAS-historical/' | |
d = xr.open_mfdataset(PATH_TO_EFAS + 'efas*201*nc', chunks = {'time': 10}, combine = 'by_coords') | |
# LOAD POWER PLANTS DATA | |
pp = pd.read_csv('top-20-ror-ppdb.csv') | |
for index, plant in pp.iterrows(): | |
print(plant) | |
filename_out = 'out-'+plant['eic_p']+'_2010-2018.csv' | |
print(filename_out) | |
if not os.path.exists(filename_out): | |
lat = plant['lat'] | |
lon = plant['lon'] | |
x_t,y_t = transform(inProj,outProj,lon,lat) | |
# Get closest grid points | |
dsel = d.sel(x = slice(x_t - 7500, x_t + 7500), y = slice(y_t + 7500, y_t - 7500)).compute() | |
# MAX 9 | |
discharge = dsel.max(['x', 'y']).dis24 | |
discharge.to_dataframe().to_csv(filename_out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment