workflow.scripts.generate_model_coordinates
Write Model Coordinates.
Description
Write out model parameters for EMOD3D.
Inputs
- A realisation file containing domain parameters.
Outputs
- A model parameters file describing the location of the domain in latitude, longitude,
- A grid parameters file describing the discretisation of the domain.
Environment
Can be run in the cybershake container. Can also be run from your own computer using the generate-model-coordinates command which is installed after running pip install workflow@git+https://github.com/ucgmsim/workflow.
Usage
generate-station-coordinates [OPTIONS] REALISATIONS_FFP OUTPUT_PATH
For More Help
See the output of generate-model-coordinates --help.
1"""Write Model Coordinates. 2 3Description 4----------- 5Write out model parameters for EMOD3D. 6 7Inputs 8------ 91. A realisation file containing domain parameters. 10 11Outputs 12------- 131. A model parameters file describing the location of the domain in latitude, longitude, 142. A grid parameters file describing the discretisation of the domain. 15 16Environment 17----------- 18Can be run in the cybershake container. Can also be run from your own computer using the `generate-model-coordinates` command which is installed after running `pip install workflow@git+https://github.com/ucgmsim/workflow`. 19 20Usage 21----- 22`generate-station-coordinates [OPTIONS] REALISATIONS_FFP OUTPUT_PATH` 23 24For More Help 25------------- 26See the output of `generate-model-coordinates --help`. 27""" 28 29from pathlib import Path 30from typing import Annotated 31 32import typer 33 34from workflow import log_utils 35from workflow.realisations import DomainParameters 36 37app = typer.Typer() 38 39 40@app.command(help="Generate model coordinate files for EMOD3D from a realisation file") 41@log_utils.log_call() 42def generate_model_coordinates( 43 realisation_ffp: Annotated[ 44 Path, 45 typer.Argument( 46 help="Path to realisation JSON file", exists=True, readable=True 47 ), 48 ], 49 output_ffp: Annotated[ 50 Path, 51 typer.Argument( 52 help="Path to directory to output model coordinates", 53 writable=True, 54 ), 55 ], 56) -> None: 57 """ 58 Generate model coordinate files for EMOD3D from a realisation JSON file. 59 60 This function reads domain parameters from a realisation and generates 61 two output files: one containing grid file specifications and the other containing 62 model parameters. These files are used for EMOD3D simulations. 63 64 Parameters 65 ---------- 66 realisation_ffp : Path 67 Path to the realisation file. 68 output_ffp : Path 69 Path to the directory where the output model coordinate files will be saved. 70 The directory will be created if it does not exist. 71 72 Returns 73 ------- 74 None 75 This function does not return a value. It writes two files to the specified output directoy: 76 - `grid_file` containing the grid dimensions and resolution. 77 - `model_params` containing the model origin coordinates, shifts, corners, and dimensions. 78 """ 79 output_ffp.mkdir(exist_ok=True) 80 domain_parameters = DomainParameters.read_from_realisation(realisation_ffp) 81 x_len = domain_parameters.domain.extent_x 82 y_len = domain_parameters.domain.extent_y 83 z_len = domain_parameters.depth 84 resolution = domain_parameters.resolution 85 grid_file = output_ffp / "grid_file" 86 model_params = output_ffp / "model_params" 87 grid_file.write_text( 88 "\n".join( 89 [ 90 f"xlen={x_len:.4f}", 91 f"{0:10.4f} {x_len:10.4f} {resolution:13.6e}", 92 f"ylen={y_len:.4f}", 93 f"{0:10.4f} {y_len:10.4f} {resolution:13.6e}", 94 f"zlen={z_len:.4f}", 95 f"{0:10.4f} {z_len:10.4f} {resolution:13.6e}\n", 96 ] 97 ) 98 ) 99 model_origin = domain_parameters.domain.origin 100 x_shift = -(domain_parameters.domain.extent_x - domain_parameters.resolution) / 2 101 y_shift = -(domain_parameters.domain.extent_y - domain_parameters.resolution) / 2 102 103 model_params.write_text( 104 "\n".join( 105 [ 106 "Model origin coordinates:", 107 f" lon= {model_origin[1]:10.5f} lat= {model_origin[0]:10.5f}" 108 f" rotate= {domain_parameters.domain.great_circle_bearing:7.2f}", 109 "", 110 "Model origin shift (cartesian vs. geographic):", 111 f" xshift(km)= {x_shift:12.5f} yshift(km)= {y_shift:12.5f}", 112 "", 113 "Model corners:", 114 ] 115 + [ 116 f" c{i + 1}= {corner[1]:10.5f} {corner[0]:10.5f}" 117 # Corner order is clockwise from top-left 118 for i, corner in enumerate(domain_parameters.domain.corners[::-1]) 119 ] 120 + [ 121 "", 122 "Model Dimensions:", 123 f" xlen= {x_len:10.4f} km", 124 f" ylen= {y_len:10.4f} km", 125 f" zlen= {z_len:10.4f} km", 126 "", 127 ] 128 ) 129 )
app =
<typer.main.Typer object>
@app.command(help='Generate model coordinate files for EMOD3D from a realisation file')
@log_utils.log_call()
def
generate_model_coordinates( realisation_ffp: Annotated[pathlib.Path, <typer.models.ArgumentInfo object>], output_ffp: Annotated[pathlib.Path, <typer.models.ArgumentInfo object>]) -> None:
41@app.command(help="Generate model coordinate files for EMOD3D from a realisation file") 42@log_utils.log_call() 43def generate_model_coordinates( 44 realisation_ffp: Annotated[ 45 Path, 46 typer.Argument( 47 help="Path to realisation JSON file", exists=True, readable=True 48 ), 49 ], 50 output_ffp: Annotated[ 51 Path, 52 typer.Argument( 53 help="Path to directory to output model coordinates", 54 writable=True, 55 ), 56 ], 57) -> None: 58 """ 59 Generate model coordinate files for EMOD3D from a realisation JSON file. 60 61 This function reads domain parameters from a realisation and generates 62 two output files: one containing grid file specifications and the other containing 63 model parameters. These files are used for EMOD3D simulations. 64 65 Parameters 66 ---------- 67 realisation_ffp : Path 68 Path to the realisation file. 69 output_ffp : Path 70 Path to the directory where the output model coordinate files will be saved. 71 The directory will be created if it does not exist. 72 73 Returns 74 ------- 75 None 76 This function does not return a value. It writes two files to the specified output directoy: 77 - `grid_file` containing the grid dimensions and resolution. 78 - `model_params` containing the model origin coordinates, shifts, corners, and dimensions. 79 """ 80 output_ffp.mkdir(exist_ok=True) 81 domain_parameters = DomainParameters.read_from_realisation(realisation_ffp) 82 x_len = domain_parameters.domain.extent_x 83 y_len = domain_parameters.domain.extent_y 84 z_len = domain_parameters.depth 85 resolution = domain_parameters.resolution 86 grid_file = output_ffp / "grid_file" 87 model_params = output_ffp / "model_params" 88 grid_file.write_text( 89 "\n".join( 90 [ 91 f"xlen={x_len:.4f}", 92 f"{0:10.4f} {x_len:10.4f} {resolution:13.6e}", 93 f"ylen={y_len:.4f}", 94 f"{0:10.4f} {y_len:10.4f} {resolution:13.6e}", 95 f"zlen={z_len:.4f}", 96 f"{0:10.4f} {z_len:10.4f} {resolution:13.6e}\n", 97 ] 98 ) 99 ) 100 model_origin = domain_parameters.domain.origin 101 x_shift = -(domain_parameters.domain.extent_x - domain_parameters.resolution) / 2 102 y_shift = -(domain_parameters.domain.extent_y - domain_parameters.resolution) / 2 103 104 model_params.write_text( 105 "\n".join( 106 [ 107 "Model origin coordinates:", 108 f" lon= {model_origin[1]:10.5f} lat= {model_origin[0]:10.5f}" 109 f" rotate= {domain_parameters.domain.great_circle_bearing:7.2f}", 110 "", 111 "Model origin shift (cartesian vs. geographic):", 112 f" xshift(km)= {x_shift:12.5f} yshift(km)= {y_shift:12.5f}", 113 "", 114 "Model corners:", 115 ] 116 + [ 117 f" c{i + 1}= {corner[1]:10.5f} {corner[0]:10.5f}" 118 # Corner order is clockwise from top-left 119 for i, corner in enumerate(domain_parameters.domain.corners[::-1]) 120 ] 121 + [ 122 "", 123 "Model Dimensions:", 124 f" xlen= {x_len:10.4f} km", 125 f" ylen= {y_len:10.4f} km", 126 f" zlen= {z_len:10.4f} km", 127 "", 128 ] 129 ) 130 )
Generate model coordinate files for EMOD3D from a realisation JSON file.
This function reads domain parameters from a realisation and generates two output files: one containing grid file specifications and the other containing model parameters. These files are used for EMOD3D simulations.
Parameters
- realisation_ffp (Path): Path to the realisation file.
- output_ffp (Path): Path to the directory where the output model coordinate files will be saved. The directory will be created if it does not exist.
Returns
- None: This function does not return a value. It writes two files to the specified output directoy:
grid_filecontaining the grid dimensions and resolution.model_paramscontaining the model origin coordinates, shifts, corners, and dimensions.