Skip to content

Commit

Permalink
Github token needed for CI when downloading executables (#349)
Browse files Browse the repository at this point in the history
* Github token needed for CI when downloading executables

* Envvar NLMOD_SUPPRESS_VERION_CHECK

* Renamed envvar

* Let's see if we can now get by without passing the GITHUB_TOKEN env

* Default to not check version

* Consume version_tag arg when creating model_ds

* Removing env SUPPRESS_EXE_VERSION_CHECK

* Removed dangling argument

* Added version_tag to refine/gridgen

* Also auto-download modpath_provisional for other platforms than win
  • Loading branch information
bdestombe authored May 29, 2024
1 parent 0a6394a commit c78976e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 59 deletions.
23 changes: 20 additions & 3 deletions nlmod/dims/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
logger = logging.getLogger(__name__)


def set_ds_attrs(ds, model_name, model_ws, mfversion="mf6", exe_name=None):
def set_ds_attrs(
ds, model_name, model_ws, mfversion="mf6", exe_name=None, version_tag=None
):
"""Set the attribute of a model dataset.
Parameters
Expand All @@ -31,6 +33,11 @@ def set_ds_attrs(ds, model_name, model_ws, mfversion="mf6", exe_name=None):
path to modflow executable, default is None, which assumes binaries
are available in nlmod/bin directory. Binaries can be downloaded
using `nlmod.util.download_mfbinaries()`.
version_tag : str, default None
GitHub release ID: for example "18.0" or "latest". If version_tag is provided,
the most recent installation location of MODFLOW is found in flopy metadata
that respects `version_tag`. If not found, the executables are downloaded.
Not compatible with exe_name.
Returns
-------
Expand All @@ -46,7 +53,9 @@ def set_ds_attrs(ds, model_name, model_ws, mfversion="mf6", exe_name=None):
ds.attrs["created_on"] = dt.datetime.now().strftime(fmt)

if exe_name is None:
exe_name = util.get_exe_path(exe_name=mfversion)
exe_name = util.get_exe_path(exe_name=mfversion, version_tag=version_tag)
else:
exe_name = util.get_exe_path(exe_name=exe_name, version_tag=version_tag)

ds.attrs["exe_name"] = exe_name

Expand Down Expand Up @@ -78,6 +87,7 @@ def to_model_ds(
drop_attributes=True,
transport=False,
remove_nan_layers=True,
version_tag=None,
):
"""Transform an input dataset to a groundwater model dataset.
Expand Down Expand Up @@ -136,6 +146,11 @@ def to_model_ds(
remove_nan_layers : bool, optional
if True remove layers with only nan values in the botm. Default is
True.
version_tag : str, default None
GitHub release ID: for example "18.0" or "latest". If version_tag is provided,
the most recent installation location of MODFLOW is found in flopy metadata
that respects `version_tag`. If not found, the executables are downloaded.
Not compatible with exe_name.
Returns
-------
Expand Down Expand Up @@ -176,7 +191,9 @@ def to_model_ds(
ds = extrapolate_ds(ds)

# add attributes
ds = set_ds_attrs(ds, model_name, model_ws)
ds = set_ds_attrs(
ds, model_name, model_ws, mfversion="mf6", version_tag=version_tag
)
ds.attrs["transport"] = int(transport)

# fill nan's
Expand Down
10 changes: 9 additions & 1 deletion nlmod/dims/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def refine(
exe_name=None,
remove_nan_layers=True,
model_coordinates=False,
version_tag=None,
):
"""Refine the grid (discretization by vertices, disv), using Gridgen.
Expand All @@ -432,6 +433,11 @@ def refine(
When model_coordinates is True, the features supplied in refinement_features are
already in model-coordinates. Only used when a grid is rotated. The default is
False.
version_tag : str, default None
GitHub release ID: for example "18.0" or "latest". If version_tag is provided,
the most recent installation location of MODFLOW is found in flopy metadata
that respects `version_tag`. If not found, the executables are downloaded.
Not compatible with exe_name.
Returns
-------
Expand All @@ -442,7 +448,9 @@ def refine(
logger.info("create vertex grid using gridgen")

if exe_name is None:
exe_name = util.get_exe_path(exe_name="gridgen")
exe_name = util.get_exe_path(exe_name="gridgen", version_tag=version_tag)
else:
exe_name = util.get_exe_path(exe_name=exe_name, version_tag=version_tag)

if model_ws is None:
model_ws = os.path.join(ds.model_ws, "gridgen")
Expand Down
4 changes: 3 additions & 1 deletion nlmod/modpath/modpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ def mpf(gwf, exe_name=None, modelname=None, model_ws=None):
"the save_flows option of the npf package should be True not None"
)

# get executable
# get executable. version_tag not supported yet
if exe_name is None:
exe_name = util.get_exe_path(exe_name="mp7_2_002_provisional")
else:
exe_name = util.get_exe_path(exe_name=exe_name)

# create mpf model
mpf = flopy.modpath.Modpath7(
Expand Down
28 changes: 22 additions & 6 deletions nlmod/sim/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_tdis_perioddata(ds, nstp="nstp", tsmult="tsmult"):
return tdis_perioddata


def sim(ds, exe_name=None):
def sim(ds, exe_name=None, version_tag=None):
"""create sim from the model dataset.
Parameters
Expand All @@ -117,9 +117,14 @@ def sim(ds, exe_name=None):
attributes: model_name, mfversion, model_ws, time_units, start,
perlen, nstp, tsmult
exe_name: str, optional
path to modflow executable, default is None, which assumes binaries
are available in nlmod/bin directory. Binaries can be downloaded
using `nlmod.util.download_mfbinaries()`.
path to modflow executable, default is None. If None, the path is
obtained from the flopy metadata that respects `version_tag`. If not
found, the executables are downloaded. Not compatible with version_tag.
version_tag : str, default None
GitHub release ID: for example "18.0" or "latest". If version_tag is provided,
the most recent installation location of MODFLOW is found in flopy metadata
that respects `version_tag`. If not found, the executables are downloaded.
Not compatible with exe_name.
Returns
-------
Expand All @@ -130,8 +135,19 @@ def sim(ds, exe_name=None):
# start creating model
logger.info("creating mf6 SIM")

if exe_name is None:
exe_name = util.get_exe_path(exe_name=ds.mfversion)
# Most likely exe_name was previously set with to_model_ds()
if exe_name is not None:
exe_name = util.get_exe_path(exe_name=exe_name, version_tag=version_tag)
elif "exe_name" in ds.attrs:
exe_name = util.get_exe_path(
exe_name=ds.attrs["exe_name"], version_tag=version_tag
)
elif "mfversion" in ds.attrs:
exe_name = util.get_exe_path(
exe_name=ds.attrs["mfversion"], version_tag=version_tag
)
else:
raise ValueError("No exe_name provided and no exe_name found in ds.attrs")

# Create the Flopy simulation object
sim = flopy.mf6.MFSimulation(
Expand Down
Loading

0 comments on commit c78976e

Please sign in to comment.