Skip to content

Commit

Permalink
Fix bug in Component.__str__() identified in #14; update repo urls an…
Browse files Browse the repository at this point in the history
…d checkout targets in examples per #12
  • Loading branch information
“Dafydd committed Aug 15, 2024
1 parent f0b8e35 commit 2da2eb8
Show file tree
Hide file tree
Showing 5 changed files with 74,169 additions and 59 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
Loading

0 comments on commit 2da2eb8

Please sign in to comment.