Skip to content

Commit e8b1ebb

Browse files
authored
Merge pull request #281 from gwmod/dev
Minor version update
2 parents bf21f20 + 4ad10b0 commit e8b1ebb

File tree

10 files changed

+138
-107
lines changed

10 files changed

+138
-107
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<img src="docs/_static/logo_10000_2.png" width="256"/>
44

5-
[![nlmod](https://github.com/ArtesiaWater/nlmod/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ArtesiaWater/nlmod/actions/workflows/ci.yml)
6-
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6fadea550ea04ea28b6ccde88fc56f35)](https://www.codacy.com/gh/ArtesiaWater/nlmod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ArtesiaWater/nlmod&utm_campaign=Badge_Grade)
7-
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/6fadea550ea04ea28b6ccde88fc56f35)](https://www.codacy.com/gh/ArtesiaWater/nlmod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ArtesiaWater/nlmod&utm_campaign=Badge_Coverage)
5+
[![nlmod](https://github.com/gwmod/nlmod/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gwmod/nlmod/actions/workflows/ci.yml)
6+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f1797b66e98b42b294bc1c5fc233dbf3)](https://app.codacy.com/gh/gwmod/nlmod/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
7+
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f1797b66e98b42b294bc1c5fc233dbf3)](https://app.codacy.com/gh/gwmod/nlmod/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
88
[![PyPI version](https://badge.fury.io/py/nlmod.svg)](https://badge.fury.io/py/nlmod)
99
[![Documentation Status](https://readthedocs.org/projects/nlmod/badge/?version=stable)](https://nlmod.readthedocs.io/en/stable/?badge=stable)
1010

@@ -49,6 +49,7 @@ Install the module with pip:
4949
* `matplotlib`
5050
* `dask`
5151
* `colorama`
52+
* `joblib`
5253

5354
There are some optional dependecies, only needed (and imported) in a single method.
5455
Examples of this are `bottleneck` (used in calculate_gxg), `geocube` (used in

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"navigation_depth": 4,
7878
"includehidden": True,
7979
"titles_only": False,
80-
# "github_url": "https://github.com/ArtesiaWater/nlmod",
80+
# "github_url": "https://github.com/gwmod/nlmod",
8181
}
8282

8383
# Add any paths that contain custom static files (such as style sheets) here,

docs/getting_started.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ potential solutions.
117117
- matplotlib
118118
- dask
119119
- colorama
120+
- joblib
120121

121122
On top of that there are some optional dependecies:
122123

@@ -126,4 +127,4 @@ On top of that there are some optional dependecies:
126127
- scikit-image (used in calculate_sea_coverage)
127128

128129
These dependencies are only needed (and imported) in a single method or function.
129-
They can be installed using ``pip install nlmod[full]`` or ``pip install -e .[full]``.
130+
They can be installed using ``pip install nlmod[full]`` or ``pip install -e .[full]``.

nlmod/gwf/output.py

+16-63
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
import warnings
43

54
import flopy
@@ -9,16 +8,20 @@
98
from shapely.geometry import Point
109

1110
from ..dims.grid import modelgrid_from_ds
12-
from ..mfoutput.mfoutput import _get_budget_da, _get_heads_da, _get_time_index
11+
from ..mfoutput.mfoutput import (
12+
_get_budget_da,
13+
_get_heads_da,
14+
_get_time_index,
15+
_get_flopy_data_object,
16+
)
1317

1418
logger = logging.getLogger(__name__)
1519

1620

1721
def get_headfile(ds=None, gwf=None, fname=None, grbfile=None):
18-
"""Get modflow HeadFile object.
22+
"""Get flopy HeadFile object.
1923
20-
Provide one of ds, gwf or fname_hds. Not that it really matters but if
21-
all are provided hierarchy is as follows: fname_hds > ds > gwf
24+
Provide one of ds, gwf or fname.
2225
2326
Parameters
2427
----------
@@ -33,34 +36,10 @@ def get_headfile(ds=None, gwf=None, fname=None, grbfile=None):
3336
3437
Returns
3538
-------
36-
headobj : flopy.utils.HeadFile
39+
flopy.utils.HeadFile
3740
HeadFile object handle
3841
"""
39-
msg = "Load the heads using either the ds, gwf or fname_hds"
40-
assert ((ds is not None) + (gwf is not None) + (fname is not None)) >= 1, msg
41-
42-
if fname is None:
43-
if ds is None:
44-
return gwf.output.head()
45-
else:
46-
fname = os.path.join(ds.model_ws, ds.model_name + ".hds")
47-
# get grb file
48-
if ds.gridtype == "vertex":
49-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".disv.grb")
50-
elif ds.gridtype == "structured":
51-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".dis.grb")
52-
else:
53-
grbfile = None
54-
55-
if fname is not None:
56-
if grbfile is not None:
57-
mg = flopy.mf6.utils.MfGrdFile(grbfile).modelgrid
58-
else:
59-
logger.warning(msg)
60-
warnings.warn(msg)
61-
mg = None
62-
headobj = flopy.utils.HeadFile(fname, modelgrid=mg)
63-
return headobj
42+
return _get_flopy_data_object("head", ds, gwf, fname, grbfile)
6443

6544

6645
def get_heads_da(
@@ -93,7 +72,7 @@ def get_heads_da(
9372
9473
Returns
9574
-------
96-
head_da : xarray.DataArray
75+
da : xarray.DataArray
9776
heads data array.
9877
"""
9978
hobj = get_headfile(ds=ds, gwf=gwf, fname=fname, grbfile=grbfile)
@@ -121,10 +100,9 @@ def get_heads_da(
121100

122101

123102
def get_cellbudgetfile(ds=None, gwf=None, fname=None, grbfile=None):
124-
"""Get modflow CellBudgetFile object.
103+
"""Get flopy CellBudgetFile object.
125104
126-
Provide one of ds, gwf or fname_cbc. Not that it really matters but if
127-
all are provided hierarchy is as follows: fname_cbc > ds > gwf
105+
Provide one of ds, gwf or fname.
128106
129107
Parameters
130108
----------
@@ -140,35 +118,10 @@ def get_cellbudgetfile(ds=None, gwf=None, fname=None, grbfile=None):
140118
141119
Returns
142120
-------
143-
cbc : flopy.utils.CellBudgetFile
144-
CellBudgetFile object
121+
flopy.utils.CellBudgetFile
122+
CellBudgetFile object handle
145123
"""
146-
msg = "Load the budgets using either the ds or the gwf"
147-
assert ((ds is not None) + (gwf is not None) + (fname is not None)) == 1, msg
148-
149-
if fname is None:
150-
if ds is None:
151-
return gwf.output.budget()
152-
else:
153-
fname = os.path.join(ds.model_ws, ds.model_name + ".cbc")
154-
# get grb file
155-
if ds.gridtype == "vertex":
156-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".disv.grb")
157-
elif ds.gridtype == "structured":
158-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".dis.grb")
159-
else:
160-
grbfile = None
161-
if fname is not None:
162-
if grbfile is not None:
163-
mg = flopy.mf6.utils.MfGrdFile(grbfile).modelgrid
164-
else:
165-
logger.error("Cannot create budget data-array without grid information.")
166-
raise ValueError(
167-
"Please provide grid information by passing path to the "
168-
"binary grid file with `grbfile=<path to file>`."
169-
)
170-
cbc = flopy.utils.CellBudgetFile(fname, modelgrid=mg)
171-
return cbc
124+
return _get_flopy_data_object("budget", ds, gwf, fname, grbfile)
172125

173126

174127
def get_budget_da(

nlmod/gwf/recharge.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def ds_to_rch(
3333
data array containing mask, recharge is only added where mask is True
3434
pname : str, optional
3535
package name. The default is 'rch'.
36-
auxiliary : str or list of str
37-
name(s) of data arrays to include as auxiliary data to reclist
3836
recharge : str, optional
3937
The name of the variable in ds that contains the recharge flux rate. The default
4038
is "recharge".
39+
auxiliary : str or list of str
40+
name(s) of data arrays to include as auxiliary data to reclist
4141
4242
Returns
4343
-------
@@ -85,7 +85,7 @@ def ds_to_rch(
8585
**kwargs,
8686
)
8787
if (auxiliary is not None) and (ds.transport == 1):
88-
logger.info("-> adding GHB to SSM sources list")
88+
logger.info("-> adding RCH to SSM sources list")
8989
ssm_sources = list(ds.attrs["ssm_sources"])
9090
if rch.package_name not in ssm_sources:
9191
ssm_sources += [rch.package_name]
@@ -107,6 +107,7 @@ def ds_to_evt(
107107
nseg=1,
108108
surface=None,
109109
depth=None,
110+
auxiliary=None,
110111
**kwargs,
111112
):
112113
"""Convert the evaporation data in the model dataset to a evt package with
@@ -133,6 +134,8 @@ def ds_to_evt(
133134
depth : str, float or xr.DataArray, optional
134135
The ET extinction depth. Set to 1 meter (below surface) when None. The default
135136
is None.
137+
auxiliary : str or list of str
138+
name(s) of data arrays to include as auxiliary data to reclist
136139
**kwargs : TYPE
137140
DESCRIPTION.
138141
@@ -186,6 +189,7 @@ def ds_to_evt(
186189
col3=depth,
187190
first_active_layer=True,
188191
only_active_cells=False,
192+
aux=auxiliary,
189193
)
190194

191195
# create rch package
@@ -194,12 +198,20 @@ def ds_to_evt(
194198
filename=f"{gwf.name}.evt",
195199
pname=pname,
196200
fixed_cell=False,
201+
auxiliary="CONCENTRATION" if auxiliary is not None else None,
197202
maxbound=len(spd),
198203
nseg=nseg,
199204
stress_period_data={0: spd},
200205
**kwargs,
201206
)
202207

208+
if (auxiliary is not None) and (ds.transport == 1):
209+
logger.info("-> adding EVT to SSM sources list")
210+
ssm_sources = list(ds.attrs["ssm_sources"])
211+
if evt.package_name not in ssm_sources:
212+
ssm_sources += [evt.package_name]
213+
ds.attrs["ssm_sources"] = ssm_sources
214+
203215
if use_ts:
204216
# create timeseries packages
205217
_add_time_series(evt, evt_unique_dic, ds)

nlmod/gwt/output.py

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
import logging
2-
import os
3-
import warnings
42

5-
import flopy
63
import numpy as np
74
import xarray as xr
85

96
from ..dims.layers import calculate_thickness
10-
from ..mfoutput.mfoutput import _get_heads_da, _get_time_index
7+
from ..mfoutput.mfoutput import _get_heads_da, _get_time_index, _get_flopy_data_object
118

129
logger = logging.getLogger(__name__)
1310

1411

1512
def get_concentration_obj(ds=None, gwt=None, fname=None, grbfile=None):
16-
msg = "Load the concentration using either the ds, gwt or a fname_conc"
17-
assert ((ds is not None) + (gwt is not None) + (fname is not None)) == 1, msg
13+
"""Get flopy HeadFile object connected to the file with the concetration of cells.
1814
19-
if fname is None:
20-
if ds is None:
21-
return gwt.output.concentration()
22-
else:
23-
fname = os.path.join(ds.model_ws, f"{ds.model_name}_gwt.ucn")
24-
# get grb file
25-
if ds.gridtype == "vertex":
26-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".disv.grb")
27-
elif ds.gridtype == "structured":
28-
grbfile = os.path.join(ds.model_ws, ds.model_name + ".dis.grb")
29-
else:
30-
grbfile = None
31-
if fname is not None:
32-
if grbfile is not None:
33-
mg = flopy.mf6.utils.MfGrdFile(grbfile).modelgrid
34-
else:
35-
logger.warning(msg)
36-
warnings.warn(msg)
37-
mg = None
38-
concobj = flopy.utils.HeadFile(fname, text="concentration", modelgrid=mg)
39-
return concobj
15+
Provide one of ds, gwf or fname.
16+
17+
Parameters
18+
----------
19+
ds : xarray.Dataset, optional
20+
model dataset, by default None
21+
gwt : flopy.mf6.ModflowGwt, optional
22+
groundwater transport model, by default None
23+
fname : str, optional
24+
path to heads file, by default None
25+
grbfile : str
26+
path to file containing binary grid information
27+
28+
Returns
29+
-------
30+
flopy.utils.HeadFile
31+
HeadFile object handle
32+
"""
33+
return _get_flopy_data_object("concentration", ds, gwt, fname, grbfile)
4034

4135

4236
def get_concentration_da(
@@ -69,7 +63,7 @@ def get_concentration_da(
6963
7064
Returns
7165
-------
72-
conc_da : xarray.DataArray
66+
da : xarray.DataArray
7367
concentration data array.
7468
"""
7569
cobj = get_concentration_obj(ds=ds, gwt=gwt, fname=fname, grbfile=grbfile)

0 commit comments

Comments
 (0)