Skip to content

Commit

Permalink
Merge pull request #58 from dafyddstephenson/fix_time_step
Browse files Browse the repository at this point in the history
Complete support for time step modification
  • Loading branch information
dafyddstephenson authored Sep 4, 2024
2 parents 2ef1478 + cdb2e0f commit 4a7d66a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 49 deletions.
12 changes: 10 additions & 2 deletions cstar/roms/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ROMSComponent(Component):
additional_code: AdditionalCode or list of AdditionalCodes
Additional code contributing to a unique instance of this ROMS run
e.g. namelists, source modifications, etc.
time_step: int, Optional, default=1
time_step: int
The time step with which to run ROMS in this configuration
nx,ny,n_levels: int
The number of x and y points and vertical levels in the domain associated with this object
Expand All @@ -77,9 +77,9 @@ class ROMSComponent(Component):
def __init__(
self,
base_model: "ROMSBaseModel",
time_step: int,
input_datasets: Optional["InputDataset" | List["InputDataset"]] = None,
additional_code: Optional[AdditionalCode] = None,
time_step: int = 1,
nx: Optional[int] = None,
ny: Optional[int] = None,
n_levels: Optional[int] = None,
Expand All @@ -94,6 +94,8 @@ def __init__(
base_model: ROMSBaseModel
An object pointing to the unmodified source code of a model handling an individual
aspect of the simulation such as biogeochemistry or ocean circulation
time_step: int
The time step with which to run ROMS in this configuration
input_datasets: InputDataset or list of InputDatasets
Any spatiotemporal data needed to run this instance of the base model
e.g. initial conditions, surface forcing, etc.
Expand Down Expand Up @@ -315,6 +317,12 @@ def run(
"__NTIMES_PLACEHOLDER__",
str(n_time_steps),
)
_replace_text_in_file(
str(mod_namelist),
"__TIMESTEP_PLACEHOLDER__",
str(self.time_step),
)

else:
raise ValueError(
"No editable namelist found to set ROMS runtime parameters. "
Expand Down
4 changes: 2 additions & 2 deletions examples/cstar_blueprint_roms_marbl_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ components:
checkout_target: 'marbl0.45.0'
additional_code:
location: 'https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git'
checkout_target: '69ee87b554082c46e3f138a9b3faf17439966e90'
checkout_target: 'b621f3ab0986262cad82438f15043d5f8f660daf'
namelists:
- "namelists/MARBL/marbl_in"
- "namelists/MARBL/marbl_tracer_output_list"
Expand All @@ -32,7 +32,7 @@ components:
time_step: 360
additional_code:
location: 'https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git'
checkout_target: '69ee87b554082c46e3f138a9b3faf17439966e90'
checkout_target: 'b621f3ab0986262cad82438f15043d5f8f660daf'
source_mods:
- "source_mods/ROMS/bgc.opt"
- "source_mods/ROMS/bulk_frc.opt"
Expand Down
90 changes: 45 additions & 45 deletions examples/cstar_example_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"marbl_additional_code = AdditionalCode(\n",
" base_model=marbl_base_model,\n",
" location='https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git',\n",
" checkout_target='69ee87b554082c46e3f138a9b3faf17439966e90',\n",
" checkout_target='b621f3ab0986262cad82438f15043d5f8f660daf',\n",
" namelists=[\n",
" \"namelists/MARBL/marbl_in\",\n",
" \"namelists/MARBL/marbl_tracer_output_list\",\n",
Expand Down Expand Up @@ -269,7 +269,7 @@
"roms_additional_code = AdditionalCode(\n",
" base_model=roms_base_model,\n",
" location='https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git',\n",
" checkout_target='69ee87b554082c46e3f138a9b3faf17439966e90',\n",
" checkout_target='b621f3ab0986262cad82438f15043d5f8f660daf',\n",
" source_mods=[\n",
" \"source_mods/ROMS/bgc.opt\",\n",
" \"source_mods/ROMS/bulk_frc.opt\",\n",
Expand Down Expand Up @@ -422,8 +422,8 @@
"MARBLComponent object \n",
"---------------------\n",
"Built from: \n",
"1 AdditionalCode repositories (query using ROMSComponent.additional_code)\n",
"0 InputDataset objects (query using ROMSComponent.input_datasets"
"1 AdditionalCode repositories (query using Component.additional_code)\n",
"0 InputDataset objects (query using Component.input_datasets"
]
},
"execution_count": 12,
Expand Down Expand Up @@ -461,8 +461,8 @@
"ROMSComponent object \n",
"--------------------\n",
"Built from: \n",
"1 AdditionalCode repositories (query using ROMSComponent.additional_code)\n",
"7 InputDataset objects (query using ROMSComponent.input_datasets\n",
"1 AdditionalCode repositories (query using Component.additional_code)\n",
"7 InputDataset objects (query using Component.input_datasets\n",
"\n",
"Discretization info:\n",
"time_step: 360s\n",
Expand Down Expand Up @@ -710,7 +710,7 @@
" time_step: 360\n",
" additional_code:\n",
" location: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git\n",
" checkout_target: 69ee87b554082c46e3f138a9b3faf17439966e90\n",
" checkout_target: b621f3ab0986262cad82438f15043d5f8f660daf\n",
" source_mods:\n",
" - source_mods/ROMS/bgc.opt\n",
" - source_mods/ROMS/bulk_frc.opt\n",
Expand Down Expand Up @@ -756,7 +756,7 @@
" checkout_target: marbl0.45.0\n",
" additional_code:\n",
" location: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example.git\n",
" checkout_target: 69ee87b554082c46e3f138a9b3faf17439966e90\n",
" checkout_target: b621f3ab0986262cad82438f15043d5f8f660daf\n",
" namelists:\n",
" - namelists/MARBL/marbl_in\n",
" - namelists/MARBL/marbl_tracer_output_list\n",
Expand Down Expand Up @@ -849,10 +849,10 @@
"source": [
"## A quick look at the output\n",
"The output of the case consists of 4 file types:\n",
"- `MARBL_bgc.20120103120000.nc` contains the 32 BGC tracers\n",
"- `MARBL_bgc_dia.20120103120000.nc` contains 343 BGC diagnostics\n",
"- `MARBL_his.201201??120000.nc` contains ocean physics variables\n",
"- `MARBL_rst.201201??120000.nc` are restart files"
"- `ROMS_MARBL_bgc.20120103120000.nc` contains the 32 BGC tracers\n",
"- `ROMS_MARBL_bgc_dia.20120103120000.nc` contains 343 BGC diagnostics\n",
"- `ROMS_MARBL_his.201201??120000.nc` contains ocean physics variables\n",
"- `ROMS_MARBL_rst.201201??120000.nc` are restart files"
]
},
{
Expand All @@ -865,36 +865,36 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[34mPARTITIONED\u001b[m\u001b[m/ roms_his.20120130120000.nc\n",
"roms_bgc.20120103120000.nc roms_his.20120131120000.nc\n",
"roms_bgc_dia.20120103120000.nc roms_rst.20120104120000.nc\n",
"roms_his.20120103120000.nc roms_rst.20120105120000.nc\n",
"roms_his.20120104120000.nc roms_rst.20120106120000.nc\n",
"roms_his.20120105120000.nc roms_rst.20120107120000.nc\n",
"roms_his.20120106120000.nc roms_rst.20120108120000.nc\n",
"roms_his.20120107120000.nc roms_rst.20120109120000.nc\n",
"roms_his.20120108120000.nc roms_rst.20120110120000.nc\n",
"roms_his.20120109120000.nc roms_rst.20120111120000.nc\n",
"roms_his.20120110120000.nc roms_rst.20120112120000.nc\n",
"roms_his.20120111120000.nc roms_rst.20120113120000.nc\n",
"roms_his.20120112120000.nc roms_rst.20120114120000.nc\n",
"roms_his.20120113120000.nc roms_rst.20120115120000.nc\n",
"roms_his.20120114120000.nc roms_rst.20120116120000.nc\n",
"roms_his.20120115120000.nc roms_rst.20120117120000.nc\n",
"roms_his.20120116120000.nc roms_rst.20120118120000.nc\n",
"roms_his.20120117120000.nc roms_rst.20120119120000.nc\n",
"roms_his.20120118120000.nc roms_rst.20120120120000.nc\n",
"roms_his.20120119120000.nc roms_rst.20120121120000.nc\n",
"roms_his.20120120120000.nc roms_rst.20120122120000.nc\n",
"roms_his.20120121120000.nc roms_rst.20120123120000.nc\n",
"roms_his.20120122120000.nc roms_rst.20120124120000.nc\n",
"roms_his.20120123120000.nc roms_rst.20120125120000.nc\n",
"roms_his.20120124120000.nc roms_rst.20120126120000.nc\n",
"roms_his.20120125120000.nc roms_rst.20120127120000.nc\n",
"roms_his.20120126120000.nc roms_rst.20120128120000.nc\n",
"roms_his.20120127120000.nc roms_rst.20120129120000.nc\n",
"roms_his.20120128120000.nc roms_rst.20120130120000.nc\n",
"roms_his.20120129120000.nc roms_rst.20120131120000.nc\n"
"\u001b[34mPARTITIONED\u001b[m\u001b[m/ ROMS_MARBL_his.20120130120000.nc\n",
"ROMS_MARBL_bgc.20120103120000.nc ROMS_MARBL_his.20120131120000.nc\n",
"ROMS_MARBL_bgc_dia.20120103120000.nc ROMS_MARBL_rst.20120104120000.nc\n",
"ROMS_MARBL_his.20120103120000.nc ROMS_MARBL_rst.20120105120000.nc\n",
"ROMS_MARBL_his.20120104120000.nc ROMS_MARBL_rst.20120106120000.nc\n",
"ROMS_MARBL_his.20120105120000.nc ROMS_MARBL_rst.20120107120000.nc\n",
"ROMS_MARBL_his.20120106120000.nc ROMS_MARBL_rst.20120108120000.nc\n",
"ROMS_MARBL_his.20120107120000.nc ROMS_MARBL_rst.20120109120000.nc\n",
"ROMS_MARBL_his.20120108120000.nc ROMS_MARBL_rst.20120110120000.nc\n",
"ROMS_MARBL_his.20120109120000.nc ROMS_MARBL_rst.20120111120000.nc\n",
"ROMS_MARBL_his.20120110120000.nc ROMS_MARBL_rst.20120112120000.nc\n",
"ROMS_MARBL_his.20120111120000.nc ROMS_MARBL_rst.20120113120000.nc\n",
"ROMS_MARBL_his.20120112120000.nc ROMS_MARBL_rst.20120114120000.nc\n",
"ROMS_MARBL_his.20120113120000.nc ROMS_MARBL_rst.20120115120000.nc\n",
"ROMS_MARBL_his.20120114120000.nc ROMS_MARBL_rst.20120116120000.nc\n",
"ROMS_MARBL_his.20120115120000.nc ROMS_MARBL_rst.20120117120000.nc\n",
"ROMS_MARBL_his.20120116120000.nc ROMS_MARBL_rst.20120118120000.nc\n",
"ROMS_MARBL_his.20120117120000.nc ROMS_MARBL_rst.20120119120000.nc\n",
"ROMS_MARBL_his.20120118120000.nc ROMS_MARBL_rst.20120120120000.nc\n",
"ROMS_MARBL_his.20120119120000.nc ROMS_MARBL_rst.20120121120000.nc\n",
"ROMS_MARBL_his.20120120120000.nc ROMS_MARBL_rst.20120122120000.nc\n",
"ROMS_MARBL_his.20120121120000.nc ROMS_MARBL_rst.20120123120000.nc\n",
"ROMS_MARBL_his.20120122120000.nc ROMS_MARBL_rst.20120124120000.nc\n",
"ROMS_MARBL_his.20120123120000.nc ROMS_MARBL_rst.20120125120000.nc\n",
"ROMS_MARBL_his.20120124120000.nc ROMS_MARBL_rst.20120126120000.nc\n",
"ROMS_MARBL_his.20120125120000.nc ROMS_MARBL_rst.20120127120000.nc\n",
"ROMS_MARBL_his.20120126120000.nc ROMS_MARBL_rst.20120128120000.nc\n",
"ROMS_MARBL_his.20120127120000.nc ROMS_MARBL_rst.20120129120000.nc\n",
"ROMS_MARBL_his.20120128120000.nc ROMS_MARBL_rst.20120130120000.nc\n",
"ROMS_MARBL_his.20120129120000.nc ROMS_MARBL_rst.20120131120000.nc\n"
]
}
],
Expand All @@ -915,19 +915,19 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 27,
"id": "39ace729-e553-412c-a0b6-4a50a86e5ae7",
"metadata": {},
"outputs": [],
"source": [
"BGC_DS = xr.open_dataset(roms_marbl_case.caseroot + '/output/roms_bgc.20120103120000.nc')\n",
"BGC_DS = xr.open_dataset(roms_marbl_case.caseroot + '/output/ROMS_MARBL_bgc.20120103120000.nc')\n",
"var = 'DOC'\n",
"BGC_DA = BGC_DS[var].isel(s_rho=99)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 28,
"id": "6e52ba38-986d-4943-8301-33e0a682ca23",
"metadata": {},
"outputs": [
Expand Down

0 comments on commit 4a7d66a

Please sign in to comment.