Skip to content
Snippets Groups Projects
Commit 5e32f015 authored by Valentin Simon Lüdke's avatar Valentin Simon Lüdke
Browse files

Fix header creation

parent d9c16b88
No related branches found
No related tags found
2 merge requests!16Generate classical mhm setups from classical setup,!8Draft: Resolve "Pre-Proc: incorporate tools for creating global setups"
Pipeline #269497 passed with stages
in 2 minutes and 30 seconds
......@@ -22,14 +22,9 @@ def create_header(ds, output_path=None, no_data_value="-9999", write=True):
lon_key = get_coord_key(ds, lon=True)
x = ds[lon_key].values
y = ds[lat_key].values
# x = x[np.where((x >= mask.lon.values[0]) & (x <= mask.lon.values[-1]))]
# y = y[np.where((y >= mask.lat.values[0]) & (y <= mask.lat.values[-1]))]
cellsize = abs(x[1] - x[0])
xllcorner = np.nanmin(x) - 0.5 * cellsize
if np.nanmin(y) == y[-1]:
yllcorner = np.nanmin(y) + 0.5 * cellsize
else:
yllcorner = np.nanmin(y) - 0.5 * cellsize
yllcorner = np.nanmin(y) - 0.5 * cellsize
ncols = len(x) - 1
nrows = len(y) - 1
......
......@@ -86,20 +86,17 @@ def crop_file_with_header(ds, file_path, mask, output_path):
lat_key = get_coord_key(ds, lat=True, raise_exception=True)
# x values
mask_res = round(mask.lon.values[1] - mask.lon.values[0], 6)
x_mask = (lon >= mask.lon.values[0] - mask_res / 2) & (
lon < mask.lon.values[-1] - mask_res / 2
x_mask = (lon >= float(mask.lon.min()) - mask_res / 2) & (
lon < float(mask.lon.max()) - mask_res / 2
)
x = np.arange(0, ds.sizes[lon_key], 1)
x_cropped = x[x_mask]
# y values
y_mask = (lat >= mask.lat.values[0] + mask_res / 2) & (
lat < mask.lat.values[-1] + mask_res / 2
y_mask = (lat >= float(mask.lat.min()) - mask_res / 2) & (
lat < float(mask.lat.max()) - mask_res / 2
)
y = np.arange(0, ds.sizes[lat_key], 1)
y_cropped = y[y_mask]
if not y_cropped: # if y_cropped empty reverse slicing order
y_mask = (lat >= mask.lat.values[-1]) & (lat <= mask.lat.values[0])
y_cropped = y[y_mask]
# write header file
header_out_path = output_path / header.name
xll = d["xllcorner"] + d["cellsize"] * np.nanmin(x_cropped)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment