Skip to content

Commit

Permalink
Merge pull request #16 from dafyddstephenson/main
Browse files Browse the repository at this point in the history
Fix bug in Component.__str__() identified in #14; update repo urls an…
  • Loading branch information
TomNicholas authored and “Dafydd committed Aug 20, 2024
2 parents f0b8e35 + 2da2eb8 commit 4e7b43e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 53 deletions.
22 changes: 12 additions & 10 deletions cstar_ocean/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def __str__(self):
base_str += "\n" + "-" * (len(name) + 7)

# Attrs
base_str += f"\ntime_step: {self.time_step} seconds"
base_str += "\nBuilt from: "

NAC = 0 if self.additional_code is None else 1
Expand All @@ -118,30 +117,33 @@ def __str__(self):
f"\n{NID} InputDataset objects (query using ROMSComponent.input_datasets"
)

base_str += "\n\nDiscretization info:"
disc_str=''
if hasattr(self, "time_step") and self.time_step is not None:
base_str += "\ntime_step: " + str(self.time_step)
disc_str += "\ntime_step: " + str(self.time_step)
if hasattr(self, "n_procs_x") and self.n_procs_x is not None:
base_str += (
disc_str += (
"\nn_procs_x: "
+ str(self.n_procs_x)
+ " (Number of x-direction processors)"
)
if hasattr(self, "n_procs_y") and self.n_procs_y is not None:
base_str += (
disc_str += (
"\nn_procs_y:"
+ str(self.n_procs_y)
+ " (Number of y-direction processors)"
)
if hasattr(self, "n_levels") and self.n_levels is not None:
base_str += "\nn_levels:" + str(self.n_levels)
disc_str += "\nn_levels:" + str(self.n_levels)
if hasattr(self, "nx") and self.nx is not None:
base_str += "\nnx:" + str(self.nx)
disc_str += "\nnx:" + str(self.nx)
if hasattr(self, "ny") and self.ny is not None:
base_str += "\nny:" + str(self.ny)
disc_str += "\nny:" + str(self.ny)
if hasattr(self, "exe_path") and self.exe_path is not None:
base_str += "\n\nIs compiled: True"
base_str += "\n exe_path: " + self.exe_path
disc_str += "\n\nIs compiled: True"
disc_str += "\n exe_path: " + self.exe_path
if len(disc_str)>0:
disc_str = "\n\nDiscretization info:"+disc_str
base_str+=disc_str
return base_str

def __repr__(self):
Expand Down
17 changes: 14 additions & 3 deletions cstar_ocean/cstar_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,32 @@ def __init__(
if isinstance(valid_start_date, dt.datetime)
else dateutil.parser.parse(valid_start_date)
)
else:
warnings.warn(
"Valid start date not provided."
+ " Unable to check if simulation dates are out of range. "
+ "Case objects should be initialized with valid_start_date "
+ "and valid_end_date attributes.",
RuntimeWarning,
)
self.valid_start_date = None

if valid_end_date is not None:
self.valid_end_date: Optional[dt.datetime] = (
valid_end_date
if isinstance(valid_end_date, dt.datetime)
else dateutil.parser.parse(valid_end_date)
)
# Warn user if valid dates are not present:
if valid_end_date is None or valid_start_date is None:
else:
warnings.warn(
"Range of valid dates not provided."
"Valid end date not provided."
+ " Unable to check if simulation dates are out of range. "
+ "Case objects should be initialized with valid_start_date "
+ "and valid_end_date attributes.",
RuntimeWarning,
)
self.valid_end_date=None


# Make sure Case start_date is set and is a datetime object:
if start_date is not None:
Expand Down
2 changes: 1 addition & 1 deletion cstar_ocean/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _write_to_config_file(config_file_str):
)

base_conf_str += "\nimport os\n"
base_conf_str += "def set_local_environment():"
base_conf_str += "def set_local_environment():\n"
config_file_str = base_conf_str + config_file_str

with open(_CSTAR_CONFIG_FILE, "a") as f:
Expand Down
8 changes: 4 additions & 4 deletions examples/cstar_blueprint_roms_marbl_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ components:
source_repo: 'https://github.com/marbl-ecosys/MARBL.git'
checkout_target: 'marbl0.45.0'
additional_code:
source_repo: 'https://github.com/dafyddstephenson/roms_marbl_example.git'
checkout_target: 'cstar_latest'
source_repo: 'https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example'
checkout_target: '69ee87b554082c46e3f138a9b3faf17439966e90'
namelists:
- "namelists/MARBL/marbl_in"
- "namelists/MARBL/marbl_tracer_output_list"
Expand All @@ -31,8 +31,8 @@ components:
n_procs_y: 3
time_step: 360
additional_code:
source_repo: 'https://github.com/dafyddstephenson/roms_marbl_example.git'
checkout_target: 'cstar_latest'
source_repo: 'https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example'
checkout_target: '69ee87b554082c46e3f138a9b3faf17439966e90'
source_mods:
- "source_mods/ROMS/bgc.opt"
- "source_mods/ROMS/bulk_frc.opt"
Expand Down
85 changes: 50 additions & 35 deletions examples/cstar_example_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"#BaseModel object, ROMS:\n",
"\n",
"roms_base_model=cstar.ROMSBaseModel(\n",
" source_repo='https://github.com/dafyddstephenson/ucla-roms.git',\n",
" checkout_target='marbl_improvements_20240611')\n",
" source_repo='https://github.com/CESR-lab/ucla-roms.git',\n",
" checkout_target='2a4e9107ffc771d2833fbea3e08f1e169759b5ff')\n",
"\n",
"marbl_base_model=cstar.MARBLBaseModel(\n",
" source_repo='https://github.com/marbl-ecosys/MARBL.git',\n",
Expand All @@ -90,8 +90,8 @@
"text/plain": [
"ROMSBaseModel object \n",
"---------------------\n",
"source_repo = https://github.com/dafyddstephenson/ucla-roms.git\n",
"checkout_target = marbl_improvements_20240611 corresponding to hash 27a31e29f1126a6fcf2675a032655acde4487d6e\n",
"source_repo = https://github.com/CESR-lab/ucla-roms.git (default)\n",
"checkout_target = 2a4e9107ffc771d2833fbea3e08f1e169759b5ff\n",
"local_config_status=3 (Environment variable ROMS_ROOT is not present and it is assumed the base model is not installed locally)"
]
},
Expand Down Expand Up @@ -129,14 +129,6 @@
"marbl_base_model"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62733dc5-f931-4c4b-9152-9d0122c90842",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "4b4eb43e-1129-4e10-8dbf-c0c7c980c149",
Expand Down Expand Up @@ -168,7 +160,7 @@
"AdditionalCode object\n",
"---------------------\n",
"Base model: MARBL\n",
"Additional code repository URL: https://github.com/dafyddstephenson/roms_marbl_example.git (checkout target: cstar_latest)\n",
"Additional code repository URL: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example (checkout target: 69ee87b554082c46e3f138a9b3faf17439966e90)\n",
"Namelist files (paths relative to repository top level):\n",
" namelists/MARBL/marbl_in\n",
" namelists/MARBL/marbl_tracer_output_list\n",
Expand All @@ -183,8 +175,8 @@
"source": [
"marbl_additional_code=cstar.AdditionalCode(\n",
" base_model=marbl_base_model,\n",
" source_repo='https://github.com/dafyddstephenson/roms_marbl_example.git',\n",
" checkout_target='cstar_latest',\n",
" source_repo='https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example',\n",
" checkout_target='69ee87b554082c46e3f138a9b3faf17439966e90',\n",
" namelists=[\"namelists/MARBL/marbl_in\",\n",
" \"namelists/MARBL/marbl_tracer_output_list\",\n",
" \"namelists/MARBL/marbl_diagnostic_output_list\"]\n",
Expand Down Expand Up @@ -213,7 +205,7 @@
"AdditionalCode object\n",
"---------------------\n",
"Base model: ROMS\n",
"Additional code repository URL: https://github.com/dafyddstephenson/roms_marbl_example.git (checkout target: cstar_latest)\n",
"Additional code repository URL: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example (checkout target: 69ee87b554082c46e3f138a9b3faf17439966e90)\n",
"Source code modification files (paths relative to repository top level):\n",
" source_mods/ROMS/bgc.opt\n",
" source_mods/ROMS/bulk_frc.opt\n",
Expand All @@ -237,8 +229,8 @@
"source": [
"roms_additional_code=cstar.AdditionalCode(\n",
" base_model=roms_base_model,\n",
" source_repo='https://github.com/dafyddstephenson/roms_marbl_example.git',\n",
" checkout_target='cstar_latest',\n",
" source_repo='https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example',\n",
" checkout_target='69ee87b554082c46e3f138a9b3faf17439966e90',\n",
" source_mods=[\"source_mods/ROMS/bgc.opt\",\n",
" \"source_mods/ROMS/bulk_frc.opt\",\n",
" \"source_mods/ROMS/cppdefs.opt\",\n",
Expand Down Expand Up @@ -355,8 +347,8 @@
"MARBLComponent object \n",
"---------------------\n",
"Built from: \n",
"1 AdditionalCode repositories\n",
"0 InputDataset objects"
"1 AdditionalCode repositories (query using ROMSComponent.additional_code)\n",
"0 InputDataset objects (query using ROMSComponent.input_datasets"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -394,8 +386,13 @@
"ROMSComponent object \n",
"--------------------\n",
"Built from: \n",
"1 AdditionalCode repositories\n",
"7 InputDataset objects"
"1 AdditionalCode repositories (query using ROMSComponent.additional_code)\n",
"7 InputDataset objects (query using ROMSComponent.input_datasets\n",
"\n",
"Discretization info:\n",
"time_step: 1\n",
"n_procs_x: 3 (Number of x-direction processors)\n",
"n_procs_y:3 (Number of y-direction processors)"
]
},
"execution_count": 9,
Expand Down Expand Up @@ -428,15 +425,30 @@
"id": "1a32ad6f-8701-416f-ae50-598f7650cf5e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/dafyddstephenson/Code/my_c_star/cstar_ocean/cstar_case.py:107: RuntimeWarning: Valid start date not provided. Unable to check if simulation dates are out of range. Case objects should be initialized with valid_start_date and valid_end_date attributes.\n",
" warnings.warn(\n",
"/Users/dafyddstephenson/Code/my_c_star/cstar_ocean/cstar_case.py:123: RuntimeWarning: Valid end date not provided. Unable to check if simulation dates are out of range. Case objects should be initialized with valid_start_date and valid_end_date attributes.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
"------------------\n",
"C-Star case object \n",
"------------------\n",
"Name: roms_marbl_example_cstar_case\n",
"Local caseroot: /Users/dafyddstephenson/Code/my_c_star/cstar_ocean/roms_marbl_example_cstar_case\n",
"caseroot: /Users/dafyddstephenson/Code/my_c_star/examples/roms_marbl_example_cstar_case\n",
"start_date: 2012-01-03 12:00:00\n",
"end_date: 2012-01-31 12:00:00\n",
"Is setup: False\n",
"Valid date range:\n",
"valid_start_date: None\n",
"valid_end_date: None\n",
"\n",
"\n",
"It is built from the following Component base models (query using Case.components): \n",
Expand All @@ -453,7 +465,9 @@
"roms_marbl_case=cstar.Case(\n",
" components=[roms_component,marbl_component],\n",
" name='roms_marbl_example_cstar_case',\n",
" caseroot=os.getcwd()+'/roms_marbl_example_cstar_case')\n",
" caseroot=os.getcwd()+'/roms_marbl_example_cstar_case',\n",
" start_date='20120103 12:00:00',\n",
" end_date='20120131 12:00:00')\n",
"roms_marbl_case"
]
},
Expand Down Expand Up @@ -517,7 +531,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[01;34m/Users/dafyddstephenson/Code/my_c_star/cstar_ocean/roms_marbl_example_cstar_case\u001b[0m\n",
"\u001b[01;34m/Users/dafyddstephenson/Code/my_c_star/examples/roms_marbl_example_cstar_case\u001b[0m\n",
"├── \u001b[01;34minput_datasets\u001b[0m\n",
"│   └── \u001b[01;34mROMS\u001b[0m\n",
"│   ├── \u001b[00mMARBL_rst.20120103120000.nc\u001b[0m\n",
Expand Down Expand Up @@ -568,7 +582,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 15,
"id": "868f69f3-9f34-4105-942d-1926c15f96e5",
"metadata": {},
"outputs": [],
Expand All @@ -578,7 +592,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 16,
"id": "062668a5-4f25-4f20-a969-95c1a856026a",
"metadata": {},
"outputs": [
Expand All @@ -592,17 +606,18 @@
"- component:\n",
" base_model:\n",
" name: ROMS\n",
" source_repo: https://github.com/dafyddstephenson/ucla-roms.git\n",
" checkout_target: marbl_improvements_20240611\n",
" source_repo: https://github.com/CESR-lab/ucla-roms.git\n",
" checkout_target: 2a4e9107ffc771d2833fbea3e08f1e169759b5ff\n",
" discretization:\n",
" nx: null\n",
" ny: null\n",
" n_levels: null\n",
" n_procs_x: 3\n",
" n_procs_y: 3\n",
" time_step: 1\n",
" additional_code:\n",
" - source_repo: https://github.com/dafyddstephenson/roms_marbl_example.git\n",
" checkout_target: cstar_latest\n",
" source_repo: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example\n",
" checkout_target: 69ee87b554082c46e3f138a9b3faf17439966e90\n",
" source_mods:\n",
" - source_mods/ROMS/bgc.opt\n",
" - source_mods/ROMS/bulk_frc.opt\n",
Expand Down Expand Up @@ -647,8 +662,8 @@
" source_repo: https://github.com/marbl-ecosys/MARBL.git\n",
" checkout_target: marbl0.45.0\n",
" additional_code:\n",
" - source_repo: https://github.com/dafyddstephenson/roms_marbl_example.git\n",
" checkout_target: cstar_latest\n",
" source_repo: https://github.com/CWorthy-ocean/cstar_blueprint_roms_marbl_example\n",
" checkout_target: 69ee87b554082c46e3f138a9b3faf17439966e90\n",
" namelists:\n",
" - namelists/MARBL/marbl_in\n",
" - namelists/MARBL/marbl_tracer_output_list\n",
Expand Down Expand Up @@ -797,7 +812,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 25,
"id": "6e52ba38-986d-4943-8301-33e0a682ca23",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -882,7 +897,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 4e7b43e

Please sign in to comment.