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

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) 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 download = False # True # download raw ERA5 files
stitch = True # False # create stitched files stitch = True # False # create stitched files
delete = False # False # delete original files delete = True # False # delete original files
""" """
@ -328,33 +328,29 @@ if stitch == True:
if ascent_only == True: if ascent_only == True:
pass pass
else: else:
df1 = xr.open_mfdataset(floatfiles, chunks={'time': 100}, combine="nested", engine='netcdf4', concat_dim="time", with xr.open_mfdataset(floatfiles, chunks={'time': 100}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df1:
parallel=True)
df1 = df1.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1)) df1 = df1.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df1.to_netcdf(os.path.join(folder, df1.to_netcdf(os.path.join(folder, "FLOAT_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(end.year) + str(end.month) + ".nc"),
"FLOAT_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str( mode='w', format="NETCDF4", engine="netcdf4",
end.year) + str(end.month) + ".nc"), mode='w', format="NETCDF4", encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"}, "v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
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', with xr.open_mfdataset(singlefiles, chunks={'time': 500}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df2:
concat_dim="time",
parallel=True)
df2 = df2.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1)) df2 = df2.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1))
df2.to_netcdf(os.path.join(folder, df2.to_netcdf(os.path.join(folder, "RAD_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str(end.year) + str(end.month) + ".nc"),
"RAD_" + str(ident2) + "_" + str(start.year) + str(start.month) + "_to_" + str( mode='w', format="NETCDF4",
end.year) + str(end.month) + ".nc"), mode='w', format="NETCDF4",
engine="netcdf4", engine="netcdf4",
encoding={"cbh": {"dtype": "float32"}, "hcc": {"dtype": "float32"}, "lcc": {"dtype": "float32"}, encoding={"cbh": {"dtype": "float32"}, "hcc": {"dtype": "float32"},
"mcc": {"dtype": "float32"}, "skt": {"dtype": "float32"}, "ssr": {"dtype": "float32"}, "lcc": {"dtype": "float32"},
"str": {"dtype": "float32"}, "sp": {"dtype": "float32"}, "ssrd": {"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"}, "strdc": {"dtype": "float32"}, "strd": {"dtype": "float32"},
"tisr": {"dtype": "float32"}, "tisr": {"dtype": "float32"},
"tsr": {"dtype": "float32"}, "ttr": {"dtype": "float32"}, "tcc": {"dtype": "float32"}, "tsr": {"dtype": "float32"}, "ttr": {"dtype": "float32"},
"tcc": {"dtype": "float32"},
"fdir": {"dtype": "float32"}}) "fdir": {"dtype": "float32"}})
startfile = Dataset(ascentfiles[0], "r", format="NETCDF4") startfile = Dataset(ascentfiles[0], "r", format="NETCDF4")
endfile = Dataset(ascentfiles[-1], "r", format="NETCDF4") endfile = Dataset(ascentfiles[-1], "r", format="NETCDF4")
@ -364,14 +360,12 @@ if stitch == True:
startfile.close() startfile.close()
endfile.close() endfile.close()
df3 = xr.open_mfdataset(ascentfiles, chunks={'time': 800}, combine="nested", engine='netcdf4', concat_dim="time", with xr.open_mfdataset(ascentfiles, chunks={'time': 800}, combine="nested", engine='netcdf4', concat_dim="time", parallel=True) as df3:
parallel=True)
df3 = df3.assign_coords(time=np.linspace(tstart, tend, (tend - tstart) + 1)) 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"), df3.to_netcdf(os.path.join(folder, "ASCENT_" + str(ident1) + "_" + str(start.year) + str(start.month) + ".nc"),
mode='w', format="NETCDF4", engine="netcdf4", mode='w', format="NETCDF4", engine="netcdf4",
encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"}, encoding={"z": {"dtype": "float32"}, "t": {"dtype": "float32"}, "u": {"dtype": "float32"},
"v": {"dtype": "float32"}, "w": {"dtype": "float32"}}) "v": {"dtype": "float32"}, "w": {"dtype": "float32"}})
print("Stitching finished!") print("Stitching finished!")
else: else:
pass pass