From 2a1316d4841e55ac91bd6ec0b15469e4debacd72 Mon Sep 17 00:00:00 2001 From: Nikolay Nikitin Date: Thu, 21 Sep 2023 02:49:41 +0300 Subject: [PATCH] fix --- core/domain/grid.py | 34 ++++++++++++++++++---------------- core/input_data/bathy_gen.py | 2 +- core/input_data/wind_gen.py | 8 ++++++-- core/swan/config.py | 4 ++-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/core/domain/grid.py b/core/domain/grid.py index e9d802d..44f259d 100644 --- a/core/domain/grid.py +++ b/core/domain/grid.py @@ -179,30 +179,32 @@ def grid_from_csv(grid_id: str, grid_csv_path: str, grid_type='spherical'): x_lim = max(data['xIndex']) y_lim = max(data['yIndex']) - step_x = abs(lons[19] - lons[20]) # TODO refactor!!! - step_y = abs(lats[0] - lats[1]) step_type = 'deg' - lons_mat = np.zeros((x_lim, y_lim)) - lats_mat = np.zeros((x_lim, y_lim)) - depth = np.zeros((x_lim, y_lim)) - - for i in range(x_lim): - for j in range(y_lim): - lons_mat[i, j] = float(data[(data['xIndex'] == i) & (data['yIndex'] == j)]['lat']) - lats_mat[i, j] = float(data[(data['xIndex'] == i) & (data['yIndex'] == j)]['lon']) - depth[i, j] = float(data[(data['xIndex'] == i) & (data['yIndex'] == j)]['elevation']) - if depth[i, j] > 0: - depth[i, j] = 0 - else: - depth[i, j] = abs(depth[i,j]) + lons_mat = np.zeros((y_lim, x_lim)) + lats_mat = np.zeros((y_lim, x_lim)) + depth = np.zeros((y_lim, x_lim)) + + for i in range(y_lim): + for j in range(x_lim): + lons_mat[i, j] = float(data[(data['yIndex'] == i) & (data['xIndex'] == j)]['lat']) + lats_mat[i, j] = float(data[(data['yIndex'] == i) & (data['xIndex'] == j)]['lon']) + depth[i, j] = float(data[(data['yIndex'] == i) & (data['xIndex'] == j)]['elevation']) + # if depth[i, j] > 0: + # depth[i, j] = 0 + # else: + # depth[i, j] = abs(depth[i,j]) + + step_x = abs(lons_mat[0,0] - lons_mat[0,1]) # TODO refactor!!! + step_y = abs(lats_mat[0,0] - lats_mat[1,0]) instance_path = f'./data/bathy_{grid_id}.nc' variable_to_netcdf(grid_lons=lons_mat, grid_lats=lats_mat, var_name='elevation', var=depth, target_path=instance_path) - grid = Grid(grid_id, min_x=np.min(lons), min_y=np.min(lats), max_x=np.max(lons), max_y=np.max(lats), + grid = Grid(grid_id, min_x=np.min(lons), min_y=np.min(lats), + max_x=np.max(lons), max_y=np.max(lats), step=step_x, step_y=step_y, step_type=step_type, instance_path=instance_path, grid_type=grid_type) return grid diff --git a/core/input_data/bathy_gen.py b/core/input_data/bathy_gen.py index ec537bc..7269124 100644 --- a/core/input_data/bathy_gen.py +++ b/core/input_data/bathy_gen.py @@ -25,7 +25,7 @@ def bathy_to_txt(nc_file_name: str, new_name: str, process_as_is=False): bathy = np.asarray(ncin.variables['elevation']) - # TODO take lon/lat direction in nc into accound + # TODO take lon/lat direction in nc into account bathy = np.flipud(bathy) if not process_as_is: diff --git a/core/input_data/wind_gen.py b/core/input_data/wind_gen.py index 7cf90ac..0a2cf3e 100644 --- a/core/input_data/wind_gen.py +++ b/core/input_data/wind_gen.py @@ -68,8 +68,12 @@ def _wind_to_txt(final_file_name_template: str, task: SimulationTask, grid: Grid ncin = nc.Dataset(interpolated_wind, 'r', format='NETCDF4') try: - u10 = np.asarray(ncin.variables['u10']) - v10 = np.asarray(ncin.variables['v10']) + if len(np.asarray(ncin.variables['u10']).shape) > 3: + u10 = np.asarray(ncin.variables['u10'])[:, 0, :, :] + v10 = np.asarray(ncin.variables['v10'])[:, 0, :, :] + else: + u10 = np.asarray(ncin.variables['u10']) + v10 = np.asarray(ncin.variables['v10']) except KeyError: u10 = np.asarray(ncin.variables['10u'])[:, 0, :, :] v10 = np.asarray(ncin.variables['10v'])[:, 0, :, :] diff --git a/core/swan/config.py b/core/swan/config.py index 0dea52f..ecb37f7 100644 --- a/core/swan/config.py +++ b/core/swan/config.py @@ -62,7 +62,7 @@ def config_label(self): @staticmethod def generate(task: SimulationTask, grid: Grid, output_options: OutputOptions): - wind_step = '1 HR' # TODO automate + wind_step = '6 HR' # TODO automate!!! wind_drag = 1.21 int_step = task.integration_step # TODO automate @@ -154,7 +154,7 @@ def _grid_to_input_desciption(self, grid_type: str): if grid_type == 'spherical': return (f"""REGular xpinp={self.grid.min_x} ypinp={self.grid.min_y} & alpinp=0. mxinp={self.grid.x_cells - 1} myinp={self.grid.y_cells - 1} & - dxinp={round(self.grid.x_step_deg, 6)} dyinp={round(self.grid.y_step_deg, 6)}""") + dxinp={round(self.grid.x_step_deg, 10):.10f} dyinp={round(self.grid.y_step_deg, 10):.10f}""") elif grid_type == 'CART': return ( f"""0. 0. 0. {self.grid.x_cells - 1} {self.grid.y_cells - 1} {self.grid.step} {self.grid.step}""")