diff --git a/examples/nblibrary/rof/month_annual_flow.ipynb b/examples/nblibrary/rof/month_annual_flow.ipynb index 1c910ba..fea0c60 100644 --- a/examples/nblibrary/rof/month_annual_flow.ipynb +++ b/examples/nblibrary/rof/month_annual_flow.ipynb @@ -59,6 +59,7 @@ "%matplotlib inline\n", "\n", "import os, sys\n", + "import glob\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "from matplotlib.ticker import FormatStrFormatter\n", @@ -160,7 +161,11 @@ "grid_list = [grid for grid in [grid_name, base_grid_name] if grid is not None]\n", "time_period = slice(f\"{rof_start_date}\", f\"{rof_end_date}\") # analysis time period\n", "nyrs = int(rof_end_date[:4]) - int(rof_start_date[:4]) + 1 # number of years\n", - "nmons = nyrs * 12 # number of months" + "nmons = nyrs * 12 # number of months\n", + "year_list = [\n", + " \"{:04d}\".format(yr)\n", + " for yr in np.arange(int(rof_start_date[0:4]), int(rof_end_date[0:4]) + 1)\n", + "]" ] }, { @@ -231,9 +236,15 @@ " return ds[var_list]\n", "\n", " # monthly\n", + " nc_list = []\n", + " for nc_path in sorted(glob.glob(f\"{in_dire}/{case}.{model}.h*.????-*.nc\")):\n", + " for yr in year_list:\n", + " if yr in os.path.basename(nc_path):\n", + " nc_list.append(nc_path)\n", + "\n", " month_data[case] = (\n", " xr.open_mfdataset(\n", - " f\"{in_dire}/{case}.{model}.h*.????-*.nc\",\n", + " nc_list,\n", " data_vars=\"minimal\",\n", " parallel=True,\n", " preprocess=preprocess,\n", diff --git a/examples/nblibrary/rof/ocean_discharge.ipynb b/examples/nblibrary/rof/ocean_discharge.ipynb index 299d0c6..4c7a8d6 100644 --- a/examples/nblibrary/rof/ocean_discharge.ipynb +++ b/examples/nblibrary/rof/ocean_discharge.ipynb @@ -48,6 +48,7 @@ "%matplotlib inline\n", "\n", "import os, sys\n", + "import glob\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", @@ -163,7 +164,11 @@ "grid_list = [grid for grid in [grid_name, base_grid_name] if grid is not None]\n", "time_period = slice(f\"{rof_start_date}\", f\"{rof_end_date}\") # analysis time period\n", "nyrs = int(rof_end_date[:4]) - int(rof_start_date[:4]) + 1 # number of years\n", - "nmons = nyrs * 12 # number of months" + "nmons = nyrs * 12 # number of months\n", + "year_list = [\n", + " \"{:04d}\".format(yr)\n", + " for yr in np.arange(int(rof_start_date[0:4]), int(rof_end_date[0:4]) + 1)\n", + "]" ] }, { @@ -234,9 +239,14 @@ " return ds[var_list]\n", "\n", " # monthly\n", + " nc_list = []\n", + " for nc_path in sorted(glob.glob(f\"{in_dire}/{case}.{model}.h*.????-*.nc\")):\n", + " for yr in year_list:\n", + " if yr in os.path.basename(nc_path):\n", + " nc_list.append(nc_path)\n", " month_data[case] = (\n", " xr.open_mfdataset(\n", - " f\"{in_dire}/{case}.{model}.h*.????-*.nc\",\n", + " nc_list,\n", " data_vars=\"minimal\",\n", " parallel=True,\n", " preprocess=preprocess,\n",