Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicl-nno committed Sep 20, 2023
1 parent 3dd92fc commit 2a1316d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
34 changes: 18 additions & 16 deletions core/domain/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/input_data/bathy_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions core/input_data/wind_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, :, :]
Expand Down
4 changes: 2 additions & 2 deletions core/swan/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}""")
Expand Down

0 comments on commit 2a1316d

Please sign in to comment.