Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/examples/13_plot_methods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@
"source": [
"# create data frame with well data (random)\n",
"nwells = 11\n",
"max_dist = 1000\n",
"df = pd.DataFrame(\n",
" {\n",
" \"screen_top\": np.random.randint(-80, -40, nwells),\n",
" \"screen_bottom\": np.random.randint(-125, -81, nwells),\n",
" \"x\": np.random.randint(117000, 120000, nwells),\n",
" \"y\": np.random.randint(439000, 442000, nwells),\n",
" \"x\": np.random.randint(ds.extent[0], ds.extent[1], nwells),\n",
" \"y\": np.random.randint(ds.extent[2], ds.extent[3], nwells),\n",
" },\n",
" index=[f\"well{i}\" for i in range(nwells)],\n",
")\n",
Expand All @@ -239,15 +240,18 @@
"dcs.plot_wells(\n",
" df,\n",
" legend=True,\n",
" max_dist=500,\n",
" max_dist=max_dist,\n",
" filter_kwargs={'alpha':0.5, 'zorder':10},\n",
" tubeline_kwargs={'alpha':0.5},\n",
" legend_kwds={\"loc\": (0, 1), \"frameon\": False, \"ncol\": 7},\n",
")\n",
"\n",
"# inset map\n",
"mapax = nlmod.plot.inset_map(ax, ds.extent)\n",
"# plot all wells in grey, wells within 500 m of cross section in color\n",
"\n",
"# plot all wells in grey, wells within x meter of cross section in color\n",
"gdf.plot(ax=mapax, color=\"grey\", edgecolor=\"grey\", markersize=20)\n",
"gdf_plotted = gdf[gdf.geometry.distance(LineString(line)) <= 500]\n",
"gdf_plotted = gdf[gdf.geometry.distance(LineString(line)) <= max_dist]\n",
"gdf_plotted.plot(\n",
" ax=mapax, color=gdf_plotted[\"filtercolor_face\"], edgecolor=\"k\", markersize=20\n",
")\n",
Expand Down
36 changes: 30 additions & 6 deletions nlmod/plot/dcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ def plot_wells(
legend_kwds=None,
max_dist=None,
sort_by_dist=True,
filter_kwargs=None,
tubeline_kwargs=None,
):
"""plot filter screens in cross section from a DataFrame

Expand Down Expand Up @@ -552,11 +554,20 @@ def plot_wells(
legend : bool, optional
if True a legend with the names (index of the df) is plotted, by default
False.
legend_kwds : dict, optional
keyword arguments passed to ax.legend(), by default None
max_dist : float, optional
maximum distance of the well from the cross section line to be plotted,
by default None
sort_by_dist : bool, optional
if True the values are sorted by distance along the cross section line.
filter_kwargs : None, optional
additional keyword arguments passed to the PatchCollection of the
filters.
tubeline_kwargs : None, optional
additional keyword arguments passed to the tube line plot.
**kwargs


Returns
-------
Expand All @@ -570,10 +581,15 @@ def plot_wells(

# convert x,y to geometries
if not isinstance(df, gpd.GeoDataFrame):
if (df["x"] < self.xedge[0]).any() or (df["x"] > self.xedge[-1]).any():
logger.warning("well x-coordinate outside of cross section extent")
if (df["y"] < self.yedge[-1]).any() or (df["y"] > self.yedge[0]).any():
logger.warning("well y-coordinate outside of cross section extent")
if hasattr(self.ds, "extent"):
if (df["x"] < self.ds.extent[0]).any() or (
df["x"] > self.ds.extent[1]
).any():
logger.warning("well x-coordinate outside of cross section extent")
if (df["y"] < self.ds.extent[2]).any() or (
df["y"] > self.ds.extent[3]
).any():
logger.warning("well y-coordinate outside of cross section extent")
df = gpd.GeoDataFrame(
df.copy(deep=True), geometry=gpd.points_from_xy(df["x"], df["y"])
)
Expand Down Expand Up @@ -608,6 +624,12 @@ def plot_wells(
else:
df[parname] = color

# parse filter and tube kwargs
if filter_kwargs is None:
filter_kwargs = {}
if tubeline_kwargs is None:
tubeline_kwargs = {}

# get distance of point along xsec line
df["s"] = [self.line.project(geom) for geom in df.geometry.values]

Expand All @@ -616,8 +638,8 @@ def plot_wells(
check_dist = df.geometry.distance(self.line) <= max_dist
if check_dist.any():
logger.info(
f"only plotting {check_dist.sum()} of {len(df)} wells within "
f"{max_dist} of cross section line"
f"plotting {check_dist.sum()} of {len(df)} wells within "
f"{max_dist}m of cross section line"
)
df = df[check_dist]

Expand All @@ -641,6 +663,7 @@ def plot_wells(
color=row["tubecolor"],
label="",
solid_capstyle="butt",
**tubeline_kwargs,
)

# plot filter (as rectangle)
Expand All @@ -666,6 +689,7 @@ def plot_wells(
rectangles,
facecolors=df["filtercolor_face"],
edgecolors=df["filtercolor_edge"],
**filter_kwargs,
)
self.ax.add_collection(patch_collection)

Expand Down
Loading