Repository navigation
Read surface topography from Elmer-Xios output #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ed8370
1e6dff8
7890ea8
31384f8
cbb2c5c
e6a2fc2
f5aea8b
1833131
3cb21e9
4be61a8
db825d1
29350ad
dcea3f7
ea7e28c
1428593
07f050f
e163957
b6c1b0b
2cf7b25
0b14bf3
3b37aee
9b044b9
c404755
f222ff9
a859699
c495e6e
631b8f6
2101e63
01229e7
e7d2807
db2c652
48f8008
67f59f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from netCDF4 import Dataset, num2date | ||
|
|
||
| from pathlib import Path | ||
| from reader import read_elmer_mesh, read_dem | ||
| from reader import read_elmer_mesh, read_dem, read_dem_xios | ||
|
|
||
| from elmer.mesh import Mesh | ||
| from ebfm.config import GridConfig | ||
|
|
@@ -153,8 +153,14 @@ def init_constants(): | |
|
|
||
| def init_grid(grid, io, config: GridConfig): | ||
| grid["is_partitioned"] = config.is_partitioned | ||
|
|
||
| if config.grid_type is GridInputType.CUSTOM: # Read grid from Elmer, elevations from BedMachine | ||
| grid["is_unstructured"] = config.is_unstructured | ||
|
|
||
| # Read grid from Elmer, elevations from BedMachine | ||
| if config.dem_file: | ||
| grid_input_type_supporting_dem = [GridInputType.CUSTOM, GridInputType.ELMERXIOS] | ||
| assert ( | ||
| config.grid_type in grid_input_type_supporting_dem | ||
| ), f"DEM file can only be specified for {grid_input_type_supporting_dem}." | ||
| if config.is_partitioned: | ||
| mesh: Mesh = read_elmer_mesh( | ||
| mesh_root=config.mesh_file, | ||
|
|
@@ -165,15 +171,18 @@ def init_grid(grid, io, config: GridConfig): | |
| mesh: Mesh = read_elmer_mesh(mesh_root=config.mesh_file) | ||
|
|
||
| grid["x"], grid["y"] = mesh.x_vertices, mesh.y_vertices | ||
| grid["z"] = read_dem(config.dem_file, grid["x"], grid["y"]) | ||
| if config.grid_type is GridInputType.CUSTOM: | ||
| grid["z"] = read_dem(config.dem_file, grid["x"], grid["y"]) | ||
| grid["lat"] = np.zeros_like(grid["x"]) + 75 # test values! | ||
| grid["lon"] = np.zeros_like(grid["x"]) + 320 # test values! | ||
| if config.grid_type is GridInputType.ELMERXIOS: | ||
| grid = read_dem_xios(config.dem_file, grid) | ||
| grid["mask"] = np.ones_like(grid["x"]) # treats every grid cell as glacier | ||
| grid["gpsum"] = np.sum(grid["mask"] == 1) # number of modelled grid cells | ||
| grid["slope_x"] = np.zeros_like(grid["x"]) # test values! | ||
| grid["slope_y"] = np.zeros_like(grid["x"]) # test values! | ||
| grid["lat"] = np.zeros_like(grid["x"]) + 75 # test values! | ||
| grid["lon"] = np.zeros_like(grid["x"]) + 320 # test values! | ||
| grid["slope_beta"] = np.zeros_like(grid["x"]) # test values! | ||
| grid["slope_gamma"] = np.zeros_like(grid["x"]) # test values! | ||
| grid["mask"] = np.ones_like(grid["x"]) # treats every grid cell as glacier | ||
| grid["gpsum"] = np.sum(grid["mask"] == 1) # number of modelled grid cells | ||
| grid["mesh"] = mesh | ||
| grid["has_shading"] = False # TODO: see https://github.com/EBFMorg/EBFM/issues/11 | ||
| # TODO later add slope | ||
|
|
@@ -300,12 +309,33 @@ def init_grid(grid, io, config: GridConfig): | |
| grid["slope_gamma"][(grid["slope_x"] > 0) & (grid["slope_y"] == 0)] = np.pi / 2 | ||
| grid["slope_gamma"][(grid["slope_x"] < 0) & (grid["slope_y"] == 0)] = -np.pi / 2 | ||
| grid["slope_gamma"] = -grid["slope_gamma"] | ||
| elif grid["input_type"] is GridInputType.ELMER_XIOS: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work? It's generally a good idea to make sure that at least one of the cases in this chain of |
||
| grid = read_elmer_xios_grid(grid=grid, gridfile=config.dem_file) | ||
| grid["gpsum"] = grid["z"].shape[0] | ||
| grid["mask"] = (grid["h"] > 1.0) * 1.0 | ||
| grid["x"] = np.zeros_like(grid["z"]) | ||
| grid["slope_beta"] = np.zeros_like(grid["x"]) # test values! | ||
| grid["slope_gamma"] = np.zeros_like(grid["x"]) # test values! | ||
| else: | ||
| raise ValueError(f"Unsupported grid input type {config.grid_type} specified in configuration.") | ||
|
|
||
| return grid | ||
|
|
||
|
|
||
| def read_elmer_xios_grid(grid, gridfile: Path): | ||
| import netCDF4 as nc | ||
|
|
||
| print(gridfile) | ||
| with nc.Dataset(gridfile) as file: | ||
| grid["lat"] = file["mesh2D_node_x"][:] | ||
| grid["lon"] = file["mesh2D_node_y"][:] | ||
| grid["x"] = file["x"][:] | ||
| grid["y"] = file["y"][:] | ||
| grid["z"] = np.squeeze(file["zs"][:].data) | ||
| grid["h"] = np.squeeze(file["h"][:].data) | ||
| return grid | ||
|
|
||
|
|
||
| def read_MATLAB_grid(gridfile: Path): | ||
| """ | ||
| Provides grid information by reading from a .mat file or allowing user input. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ def extract_active_coupling_features(args: argparse.Namespace) -> List[str]: | |
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
|
||
| parser.add_argument( | ||
| "--version", | ||
|
|
@@ -126,20 +126,27 @@ def main(): | |
| " If --netcdf-mesh is provided elevations will be read from the given NetCDF mesh file.", | ||
| ) | ||
|
|
||
| input_group.add_argument( | ||
| "--netcdf-mesh-unstructured", | ||
| type=Path, | ||
| help="Path to the unstructured NetCDF mesh file. Optional if using --elmer-mesh." | ||
| " If --netcdf-mesh is provided elevations will be read from the given NetCDF mesh file.", | ||
| ) | ||
|
|
||
| time_group = parser.add_argument_group("time configuration") | ||
|
|
||
| time_group.add_argument( | ||
| "--start-time", | ||
| type=str, | ||
| help="Start time of the simulation in format 'DD-Mon-YYYY HH:MM', e.g., '01-Jan-1979 00:00'.", | ||
| help="Start time of the simulation in format 'DD-Mon-YYYY HH:MM'", | ||
| default="1-Jan-1979 00:00", | ||
| ) | ||
|
|
||
| time_group.add_argument( | ||
| "--end-time", | ||
| type=str, | ||
| help="End time of the simulation in format 'DD-Mon-YYYY HH:MM', e.g., '02-Jan-1979 09:00'.", | ||
| default="2-Jan-1979 09:00", | ||
| help="End time of the simulation in format 'DD-Mon-YYYY HH:MM'", | ||
| default="2-Jan-1979 00:00", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did another merge of You can also use the new options to provide different values. |
||
| ) | ||
|
|
||
| time_group.add_argument( | ||
|
|
@@ -297,11 +304,10 @@ def main(): | |
|
|
||
| # Write output to files (only in uncoupled run and for unpartitioned grid) | ||
| if not grid["is_partitioned"] and not coupler.has_coupling: | ||
| assert ( | ||
| grid_config.grid_type is GridInputType.MATLAB | ||
| ), "Output writing currently only implemented for MATLAB input grids." | ||
| io, OUTFILE = LOOP_write_to_file.main(OUTFILE, io, OUT, grid, t, time, C) | ||
| pass | ||
| if grid_config.grid_type is GridInputType.MATLAB: | ||
| io, OUTFILE = LOOP_write_to_file.main(OUTFILE, io, OUT, grid, t, time, C) | ||
| else: | ||
| logger.warning("Skipping writing output to file for Elmer input grids.") | ||
| elif grid["is_partitioned"] or coupler.has_coupling: | ||
| logger.warning("Skipping writing output to file for coupled or partitioned runs.") | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.