Skip to content

Commit

Permalink
Changes to example notebook and environment.yml addressing #18,#21,#22,
Browse files Browse the repository at this point in the history
…#23; fix bug caught by pre-commit in cstar_case.py
  • Loading branch information
“Dafydd committed Aug 20, 2024
1 parent 1a47dbf commit d0ba139
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 123 deletions.
4 changes: 2 additions & 2 deletions ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:
- compilers
- netcdf-fortran
- mpich
- nco
- ncview
- xarray
- netCDF4
45 changes: 0 additions & 45 deletions cstar_ocean/.pre-commit-config.yaml

This file was deleted.

20 changes: 12 additions & 8 deletions cstar_ocean/cstar_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,13 @@ def persist(self, filename: str):

# Add start date to valid_date_range if it exists
if self.valid_start_date is not None:
bp_dict["registry_attrs"].setdefault("valid_date_range", {})["start_date"] = str(self.valid_start_date)
bp_dict["registry_attrs"].setdefault("valid_date_range", {})[
"start_date"
] = str(self.valid_start_date)
if self.valid_end_date is not None:
bp_dict["registry_attrs"].setdefault("valid_date_range", {})["end_date"] = str(self.valid_end_date)
bp_dict["registry_attrs"].setdefault("valid_date_range", {})["end_date"] = (
str(self.valid_end_date)
)

bp_dict["components"] = []

Expand Down Expand Up @@ -577,12 +581,12 @@ def persist(self, filename: str):
# Create a dictionary of file_info for each dataset file:
if "files" not in input_dataset_info[dct_key].keys():
input_dataset_info[dct_key]["files"] = []
file_info={"source":ind.source,"hash":ind.file_hash}
if hasattr(ind,"start_date"):
file_info["start_date"]=ind.start_date
if hasattr(ind,"end_date"):
file_info["end_date"]=ind.end_date
file_info = {"source": ind.source, "hash": ind.file_hash}
if hasattr(ind, "start_date"):
file_info["start_date"] = str(ind.start_date)
if hasattr(ind, "end_date"):
file_info["end_date"] = str(ind.end_date)

input_dataset_info[dct_key]["files"].append(file_info)

component_info["input_datasets"] = input_dataset_info
Expand Down
154 changes: 86 additions & 68 deletions examples/cstar_example_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@
" source=\"https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_bry_2012.nc\",\n",
" file_hash=\"c3b0e14aae6dd5a0d54703fa04cf95960c1970e732c0a230427bf8b0fbbd8bf1\"\n",
")\n",
"roms_bgc_boundary_forcing=cstar.BoundaryForcing(\n",
" base_model=roms_base_model,\n",
" source=\"https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_bry_bgc_MARBL.nc\",\n",
" file_hash=\"897a8df8ed45841a98b3906f2dd07750decc5c2b50095ba648a855c869c7d3ee\"\n",
"roms_bgc_boundary_forcing = cstar.BoundaryForcing(\n",
" base_model = roms_base_model,\n",
" source = \"https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_bry_bgc_MARBL.nc\",\n",
" file_hash = \"897a8df8ed45841a98b3906f2dd07750decc5c2b50095ba648a855c869c7d3ee\"\n",
")\n",
"# Surface\n",
"roms_bgc_surface_forcing=cstar.SurfaceForcing(\n",
"roms_bgc_surface_forcing = cstar.SurfaceForcing(\n",
" base_model=roms_base_model,\n",
" source=\"https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_frc_bgc.nc\",\n",
" file_hash=\"621dd23691d87aa93c5cc582daf6c5f18333ed062ff934777d50b63346c3f84d\"\n",
")\n",
"roms_phys_surface_forcing=cstar.SurfaceForcing(\n",
"roms_phys_surface_forcing = cstar.SurfaceForcing(\n",
" base_model=roms_base_model,\n",
" source=\"https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_frc.201201.nc\",\n",
" file_hash=\"923049a9c2ab9ce77fa4a0211585e6848a12e87bf237e7aa310f693c3ac6abfa\"\n",
Expand Down Expand Up @@ -347,8 +347,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": 8,
Expand All @@ -357,9 +357,9 @@
}
],
"source": [
"marbl_component=cstar.MARBLComponent(\n",
" base_model=marbl_base_model,\n",
" additional_code=marbl_additional_code\n",
"marbl_component = cstar.MARBLComponent(\n",
" base_model = marbl_base_model,\n",
" additional_code = marbl_additional_code\n",
")\n",
"marbl_component "
]
Expand All @@ -386,8 +386,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: 1\n",
Expand All @@ -401,10 +401,10 @@
}
],
"source": [
"roms_component=cstar.ROMSComponent(\n",
" base_model=roms_base_model,\n",
" additional_code=roms_additional_code,\n",
" input_datasets=roms_input_datasets,\n",
"roms_component = cstar.ROMSComponent(\n",
" base_model = roms_base_model,\n",
" additional_code = roms_additional_code,\n",
" input_datasets = roms_input_datasets,\n",
" n_procs_x = 3,\n",
" n_procs_y = 3)\n",
"roms_component "
Expand All @@ -416,7 +416,7 @@
"metadata": {},
"source": [
"## And finally, we can build the Case object:\n",
"This is instantiated using a list of components, a name string, and a \"caseroot\" - the local path where the case will be run"
"This is instantiated using a list of components, a name string, and a \"caseroot\" - the local path where the case will be run. Additionally we choose a start date and end date for the run. The values below run the case for one model month, which may take several minutes to run (depending on your machine). **If you'd like to run the case more quickly**, modify `end_date` below:"
]
},
{
Expand Down Expand Up @@ -462,12 +462,12 @@
}
],
"source": [
"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",
" start_date='20120103 12:00:00',\n",
" end_date='20120131 12:00:00')\n",
"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",
" start_date = '20120103 12:00:00',\n",
" end_date = '20120131 12:00:00')\n",
"roms_marbl_case"
]
},
Expand Down Expand Up @@ -567,7 +567,11 @@
],
"source": [
"%%bash\n",
"tree $roms_marbl_caseroot"
"if command -v tree >/dev/null 2>&1; then \n",
" tree $roms_marbl_caseroot; \n",
"else \n",
" echo \"tree is not installed on your system so you can't see this cell - sorry!\"\n",
"fi\n"
]
},
{
Expand All @@ -582,7 +586,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 14,
"id": "868f69f3-9f34-4105-942d-1926c15f96e5",
"metadata": {},
"outputs": [],
Expand All @@ -592,7 +596,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"id": "062668a5-4f25-4f20-a969-95c1a856026a",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -635,27 +639,41 @@
" model_grid:\n",
" files:\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_grd.nc\n",
" file_hash: fd537ef8159fabb18e38495ec8d44e2fa1b7fb615fcb1417dd4c0e1bb5f4e41d\n",
" hash: fd537ef8159fabb18e38495ec8d44e2fa1b7fb615fcb1417dd4c0e1bb5f4e41d\n",
" start_date: None\n",
" end_date: None\n",
" initial_conditions:\n",
" files:\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/MARBL_rst.20120103120000.nc\n",
" file_hash: fc3bbd039256edc89c898efda0eebc5c53773995598d59310bc6d57f454a6ddd\n",
" hash: fc3bbd039256edc89c898efda0eebc5c53773995598d59310bc6d57f454a6ddd\n",
" start_date: None\n",
" end_date: None\n",
" tidal_forcing:\n",
" files:\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_tides.nc\n",
" file_hash: 90db174ab174909f9bf27c13fa19995c03f680bcb80e7d012268505b48590338\n",
" hash: 90db174ab174909f9bf27c13fa19995c03f680bcb80e7d012268505b48590338\n",
" start_date: None\n",
" end_date: None\n",
" boundary_forcing:\n",
" files:\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_bry_2012.nc\n",
" file_hash: c3b0e14aae6dd5a0d54703fa04cf95960c1970e732c0a230427bf8b0fbbd8bf1\n",
" hash: c3b0e14aae6dd5a0d54703fa04cf95960c1970e732c0a230427bf8b0fbbd8bf1\n",
" start_date: None\n",
" end_date: None\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_bry_bgc_MARBL.nc\n",
" file_hash: 897a8df8ed45841a98b3906f2dd07750decc5c2b50095ba648a855c869c7d3ee\n",
" hash: 897a8df8ed45841a98b3906f2dd07750decc5c2b50095ba648a855c869c7d3ee\n",
" start_date: None\n",
" end_date: None\n",
" surface_forcing:\n",
" files:\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_frc_bgc.nc\n",
" file_hash: 621dd23691d87aa93c5cc582daf6c5f18333ed062ff934777d50b63346c3f84d\n",
" hash: 621dd23691d87aa93c5cc582daf6c5f18333ed062ff934777d50b63346c3f84d\n",
" start_date: None\n",
" end_date: None\n",
" - source: https://github.com/CWorthy-ocean/input_datasets_roms_marbl_example/raw/main/roms_frc.201201.nc\n",
" file_hash: 923049a9c2ab9ce77fa4a0211585e6848a12e87bf237e7aa310f693c3ac6abfa\n",
" hash: 923049a9c2ab9ce77fa4a0211585e6848a12e87bf237e7aa310f693c3ac6abfa\n",
" start_date: None\n",
" end_date: None\n",
"- component:\n",
" base_model:\n",
" name: MARBL\n",
Expand Down Expand Up @@ -764,55 +782,54 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 20,
"id": "dde01e3d-352c-40b7-91f6-a9bbb38a859c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MARBL_bgc.20120103120000.nc MARBL_rst.20120104120000.nc\n",
"MARBL_bgc_dia.20120103120000.nc MARBL_rst.20120105120000.nc\n",
"MARBL_his.20120103120000.nc MARBL_rst.20120106120000.nc\n",
"MARBL_his.20120104120000.nc MARBL_rst.20120107120000.nc\n",
"MARBL_his.20120105120000.nc MARBL_rst.20120108120000.nc\n",
"MARBL_his.20120106120000.nc MARBL_rst.20120109120000.nc\n",
"MARBL_his.20120107120000.nc MARBL_rst.20120110120000.nc\n",
"MARBL_his.20120108120000.nc MARBL_rst.20120111120000.nc\n",
"MARBL_his.20120109120000.nc MARBL_rst.20120112120000.nc\n",
"MARBL_his.20120110120000.nc MARBL_rst.20120113120000.nc\n",
"MARBL_his.20120111120000.nc MARBL_rst.20120114120000.nc\n",
"MARBL_his.20120112120000.nc MARBL_rst.20120115120000.nc\n",
"MARBL_his.20120113120000.nc MARBL_rst.20120116120000.nc\n",
"MARBL_his.20120114120000.nc MARBL_rst.20120117120000.nc\n",
"MARBL_his.20120115120000.nc MARBL_rst.20120118120000.nc\n",
"MARBL_his.20120116120000.nc MARBL_rst.20120119120000.nc\n",
"MARBL_his.20120117120000.nc MARBL_rst.20120120120000.nc\n",
"MARBL_his.20120118120000.nc MARBL_rst.20120121120000.nc\n",
"MARBL_his.20120119120000.nc MARBL_rst.20120122120000.nc\n",
"MARBL_his.20120120120000.nc MARBL_rst.20120123120000.nc\n",
"MARBL_his.20120121120000.nc MARBL_rst.20120124120000.nc\n",
"MARBL_his.20120122120000.nc MARBL_rst.20120125120000.nc\n",
"MARBL_his.20120123120000.nc MARBL_rst.20120126120000.nc\n",
"MARBL_his.20120124120000.nc MARBL_rst.20120127120000.nc\n",
"MARBL_his.20120125120000.nc MARBL_rst.20120128120000.nc\n",
"MARBL_his.20120126120000.nc MARBL_rst.20120129120000.nc\n",
"MARBL_his.20120127120000.nc MARBL_rst.20120130120000.nc\n",
"MARBL_his.20120128120000.nc MARBL_rst.20120131120000.nc\n",
"MARBL_his.20120129120000.nc \u001b[34mPARTITIONED\u001b[m\u001b[m/\n",
"MARBL_his.20120130120000.nc analyse.py\n",
"MARBL_his.20120131120000.nc analyse.py~\n"
"MARBL_bgc.20120103120000.nc MARBL_his.20120131120000.nc\n",
"MARBL_bgc_dia.20120103120000.nc MARBL_rst.20120104120000.nc\n",
"MARBL_his.20120103120000.nc MARBL_rst.20120105120000.nc\n",
"MARBL_his.20120104120000.nc MARBL_rst.20120106120000.nc\n",
"MARBL_his.20120105120000.nc MARBL_rst.20120107120000.nc\n",
"MARBL_his.20120106120000.nc MARBL_rst.20120108120000.nc\n",
"MARBL_his.20120107120000.nc MARBL_rst.20120109120000.nc\n",
"MARBL_his.20120108120000.nc MARBL_rst.20120110120000.nc\n",
"MARBL_his.20120109120000.nc MARBL_rst.20120111120000.nc\n",
"MARBL_his.20120110120000.nc MARBL_rst.20120112120000.nc\n",
"MARBL_his.20120111120000.nc MARBL_rst.20120113120000.nc\n",
"MARBL_his.20120112120000.nc MARBL_rst.20120114120000.nc\n",
"MARBL_his.20120113120000.nc MARBL_rst.20120115120000.nc\n",
"MARBL_his.20120114120000.nc MARBL_rst.20120116120000.nc\n",
"MARBL_his.20120115120000.nc MARBL_rst.20120117120000.nc\n",
"MARBL_his.20120116120000.nc MARBL_rst.20120118120000.nc\n",
"MARBL_his.20120117120000.nc MARBL_rst.20120119120000.nc\n",
"MARBL_his.20120118120000.nc MARBL_rst.20120120120000.nc\n",
"MARBL_his.20120119120000.nc MARBL_rst.20120121120000.nc\n",
"MARBL_his.20120120120000.nc MARBL_rst.20120122120000.nc\n",
"MARBL_his.20120121120000.nc MARBL_rst.20120123120000.nc\n",
"MARBL_his.20120122120000.nc MARBL_rst.20120124120000.nc\n",
"MARBL_his.20120123120000.nc MARBL_rst.20120125120000.nc\n",
"MARBL_his.20120124120000.nc MARBL_rst.20120126120000.nc\n",
"MARBL_his.20120125120000.nc MARBL_rst.20120127120000.nc\n",
"MARBL_his.20120126120000.nc MARBL_rst.20120128120000.nc\n",
"MARBL_his.20120127120000.nc MARBL_rst.20120129120000.nc\n",
"MARBL_his.20120128120000.nc MARBL_rst.20120130120000.nc\n",
"MARBL_his.20120129120000.nc MARBL_rst.20120131120000.nc\n",
"MARBL_his.20120130120000.nc \u001b[34mPARTITIONED\u001b[m\u001b[m/\n"
]
}
],
"source": [
"ls /Users/dafyddstephenson/Code/my_c_star/cstar_ocean/roms_marbl_example_cstar_case/output/"
"ls {roms_marbl_case.caseroot}/output/"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 22,
"id": "6e52ba38-986d-4943-8301-33e0a682ca23",
"metadata": {},
"outputs": [
Expand All @@ -828,6 +845,7 @@
}
],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import xarray as xr\n",
"import matplotlib.pyplot as plt\n",
Expand Down

0 comments on commit d0ba139

Please sign in to comment.