Script for download and stitching of ERA5 atmospheric data

This commit is contained in:
Marcel Christian Frommelt 2021-07-01 22:31:26 +09:00
parent dcdb566c17
commit 5836032c6f
1 changed files with 29 additions and 35 deletions

View File

@ -47,7 +47,7 @@ Operations you want to be performed:
ascent_only = False # True # get only ERA5 data for ascent (e. g. for new location or time within same region)
download = False # True # download raw ERA5 files
stitch = True # False # create stitched files
delete = False # False # delete original files
delete = True # False # delete original files
"""
@ -328,32 +328,28 @@ if stitch == True:
if ascent_only == True:
pass
else:
df1 = xr.open_mfdataset(floatfiles, chunks={'time': 100}, combine="nested", engine='netcdf4', concat_dim="time",
parallel=True)
df1 = df1.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df1.to_netcdf(os.path.join(folder,
"FLOAT_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(
end.year) + str(end.month) + ".nc"), mode='w', format="NETCDF4",
engine="netcdf4",
encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"},
"v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
df2 = xr.open_mfdataset(singlefiles, chunks={'time': 500}, combine="nested", engine='netcdf4',
concat_dim="time",
parallel=True)
df2 = df2.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df2.to_netcdf(os.path.join(folder,
"RAD_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(
end.year) + str(end.month) + ".nc"), mode='w', format="NETCDF4",
engine="netcdf4",
encoding={"cbh": {"dtype": "float32"}, "hcc": {"dtype": "float32"}, "lcc": {"dtype": "float32"},
"mcc": {"dtype": "float32"}, "skt": {"dtype": "float32"}, "ssr": {"dtype": "float32"},
"str": {"dtype": "float32"}, "sp": {"dtype": "float32"}, "ssrd": {"dtype": "float32"},
"strdc": {"dtype": "float32"}, "strd": {"dtype": "float32"},
"tisr": {"dtype": "float32"},
"tsr": {"dtype": "float32"}, "ttr": {"dtype": "float32"}, "tcc": {"dtype": "float32"},
"fdir": {"dtype": "float32"}})
with xr.open_mfdataset(floatfiles, chunks={'time': 100}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df1:
df1 = df1.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df1.to_netcdf(os.path.join(folder, "FLOAT_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(end.year) + str(end.month) + ".nc"),
mode='w', format="NETCDF4", engine="netcdf4",
encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"}, "v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
with xr.open_mfdataset(singlefiles, chunks={'time': 500}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df2:
df2 = df2.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df2.to_netcdf(os.path.join(folder, "RAD_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(end.year) + str(end.month) + ".nc"),
mode='w', format="NETCDF4",
engine="netcdf4",
encoding={"cbh": {"dtype": "float32"}, "hcc": {"dtype": "float32"},
"lcc": {"dtype": "float32"},
"mcc": {"dtype": "float32"}, "skt": {"dtype": "float32"},
"ssr": {"dtype": "float32"},
"str": {"dtype": "float32"}, "sp": {"dtype": "float32"},
"ssrd": {"dtype": "float32"},
"strdc": {"dtype": "float32"}, "strd": {"dtype": "float32"},
"tisr": {"dtype": "float32"},
"tsr": {"dtype": "float32"}, "ttr": {"dtype": "float32"},
"tcc": {"dtype": "float32"},
"fdir": {"dtype": "float32"}})
startfile = Dataset(ascentfiles[0], "r", format="NETCDF4")
endfile = Dataset(ascentfiles[-1], "r", format="NETCDF4")
@ -364,15 +360,13 @@ if stitch == True:
startfile.close()
endfile.close()
df3 = xr.open_mfdataset(ascentfiles, chunks={'time': 800}, combine="nested", engine='netcdf4', concat_dim="time",
parallel=True)
df3 = df3.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df3.to_netcdf(os.path.join(folder, "ASCENT_" + str(ident1) + "_" + str(start.year) + str(start.month) + ".nc"),
mode='w', format="NETCDF4", engine="netcdf4",
encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"},
"v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
print("Stitching finished!")
with xr.open_mfdataset(ascentfiles, chunks={'time': 800}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df3:
df3 = df3.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df3.to_netcdf(os.path.join(folder, "ASCENT_" + str(ident1) + "_" + str(start.year) + str(start.month) + ".nc"),
mode='w', format="NETCDF4", engine="netcdf4",
encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"},
"v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
print("Stitching finished!")
else:
pass