-
Notifications
You must be signed in to change notification settings - Fork 31
dis_plot can plot a single point by particle and also a cut #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
643ce6e
ec6fe21
b63bdfc
a7f8edb
1b6f717
04a6cec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| kwargs: | ||
| * axis : ("x", "Vx"), ("x", "Vy"), ("x", "Vz"), ("Vx", "Vy") (default) -- | ||
| ("Vx", "Vz"), ("Vy", "Vz") | ||
| ("Vx", "Vz"), ("Vy", "Vz"), ("Vx"), (Vy"), ("Vz") | ||
| * bins : number of bins in each dimension, default is (50,50) | ||
| * gaussian_filter_sigma : sigma of the gaussian filter, default is (0,0) | ||
| * median_filter_size : size of the median filter, default is (0,0) | ||
|
|
@@ -53,50 +53,111 @@ | |
| axis = kwargs.get("axis", ("Vx", "Vy")) | ||
| vaxis = {"Vx": 0, "Vy": 1, "Vz": 2} | ||
|
|
||
| if axis[0] in vaxis: | ||
| x = particles.v[:, vaxis[axis[0]]] | ||
| elif axis[0] == "x": | ||
| x = particles.x | ||
| if axis[1] in vaxis: | ||
| y = particles.v[:, vaxis[axis[1]]] | ||
| if len(axis) == 2: | ||
| if axis[0] in vaxis: | ||
| x = particles.v[:, vaxis[axis[0]]] | ||
| elif axis[0] == "x": | ||
| x = particles.x | ||
| else: | ||
| raise ValueError("Only abscissa and velocity X-axis are supported yet") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we consider the option (y,v) or (z,v) or (v,y) and (v,z) ? |
||
| if axis[1] in vaxis: | ||
| y = particles.v[:, vaxis[axis[1]]] | ||
| else: | ||
| raise ValueError("Only velocity Y-axis are supported yet") | ||
|
|
||
| bins = kwargs.get("bins", (50, 50)) | ||
| h, xh, yh = np.histogram2d( | ||
| x, y, bins=bins, weights=particles.weights[:, 0] | ||
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| bins = kwargs.get("bins", (50, 50)) | ||
| h, xh, yh = np.histogram2d( | ||
| x, y, bins=kwargs.get("bins", bins), weights=particles.weights[:, 0] | ||
| ) | ||
| if "gaussian_filter_sigma" in kwargs and "median_filter_size" not in kwargs: | ||
| from scipy.ndimage import gaussian_filter | ||
|
|
||
| sig = kwargs.get("gaussian_filter_sigma", (0, 0)) | ||
| image = gaussian_filter(h.T, sigma=sig) | ||
| elif "median_filter_size" in kwargs and "gaussian_filter_sigma" not in kwargs: | ||
| from scipy.ndimage import median_filter | ||
|
|
||
| siz = kwargs.get("median_filter_size", (0, 0)) | ||
| image = median_filter(h.T, size=siz) | ||
| elif "gaussian_filter_sigma" not in kwargs and "median_filter_size" not in kwargs: | ||
| image = h.T | ||
| else: | ||
| raise ValueError( | ||
| "gaussian and median filters can not be called at the same time" | ||
| ) | ||
|
|
||
| plain = kwargs.get("plain", False) | ||
|
|
||
| if not plain: | ||
| cmap = kwargs.get("cmap", "jet") | ||
|
|
||
| cmax = kwargs.get("color_max", h.max()) | ||
| cmin = kwargs.get("color_min", h.min()) | ||
| cmin = max(cmin, 1e-4) | ||
|
|
||
| color_scale = kwargs.get("color_scale", "log") | ||
| if color_scale == "log": | ||
| norm = LogNorm(vmin=cmin, vmax=cmax) | ||
| elif color_scale == "linear": | ||
| norm = Normalize(cmin, cmax) | ||
| else: | ||
| raise ValueError("Only log and linear color_scale values are supported yet") | ||
|
|
||
| im = ax.pcolormesh(xh, yh, image, cmap=cmap, norm=norm) | ||
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fig.colorbar(im, ax=ax) | ||
| else: | ||
| color = kwargs.get("color", "k") | ||
| stride = kwargs.get("stride", 1) | ||
| markersize = kwargs.get("markersize", 0.5) | ||
| alpha = kwargs.get("alpha", 0.5) | ||
| im = ax.plot(x[::stride], y[::stride], | ||
Check noticeCode scanning / CodeQL Unused local variable Note
Variable im is not used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, like the one defined with the previous
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, but let's keep it, |
||
| color=color, | ||
| linewidth=0, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the more correct way to do this plot would be to use |
||
| marker='.', | ||
| markersize=markersize, | ||
| alpha=alpha) | ||
|
Comment on lines
+111
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate 🧩 Proposed guard stride = kwargs.get("stride", 1)
+ if stride <= 0:
+ raise ValueError("stride must be a positive integer")
markersize = kwargs.get("markersize", 0.5)🤖 Prompt for AI Agents |
||
|
|
||
| ax.set_ylabel(kwargs.get("ylabel", axis[1])) | ||
|
|
||
|
|
||
| elif len(axis) == 1: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| bins = kwargs.get("bins", (50)) | ||
| cuts = kwargs.get("cuts", None) | ||
| ndim = particles.ndim | ||
|
|
||
| if cuts is not None: | ||
| from pyphare.core.box import Box | ||
| if ndim == 1: | ||
| box_new = Box(cuts[0][0], cuts[0][1]) | ||
| new_particles = particles.select(box_new, box_type="pos") | ||
|
Comment on lines
+127
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle 🧩 One‑dimensional fix (minimal) if cuts is not None:
from pyphare.core.box import Box
if ndim == 1:
- box_new = Box(cuts[0][0], cuts[0][1])
- new_particles = particles.select(box_new, box_type="pos")
+ if cuts[0] is None:
+ new_particles = particles
+ else:
+ box_new = Box(cuts[0][0], cuts[0][1])
+ new_particles = particles.select(box_new, box_type="pos")🤖 Prompt for AI Agents |
||
| elif ndim == 2: | ||
| box_new = Box((cuts[0][0], cuts[1][0]), (cuts[0][1], cuts[1][1])) # TODO need to be tested | ||
| new_particles = particles.select(box_new, box_type="pos") | ||
| else: | ||
| box_new = Box((cuts[0][0], cuts[1][0], cuts[2][0]), (cuts[0][1], cuts[1][1], cuts[2][1])) # TODO need to be tested | ||
| new_particles = particles.select(box_new, box_type="pos") | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: | ||
| new_particles = particles | ||
|
|
||
| if "gaussian_filter_sigma" in kwargs and "median_filter_size" not in kwargs: | ||
| from scipy.ndimage import gaussian_filter | ||
| drawstyle = kwargs.get("drawstyle", "steps-mid") | ||
|
|
||
| sig = kwargs.get("gaussian_filter_sigma", (0, 0)) | ||
| image = gaussian_filter(h.T, sigma=sig) | ||
| elif "median_filter_size" in kwargs and "gaussian_filter_sigma" not in kwargs: | ||
| from scipy.ndimage import median_filter | ||
| if axis[0] in vaxis: | ||
| x = new_particles.v[:, vaxis[axis[0]]] | ||
| else: | ||
| raise ValueError("For 1-D dist_plot, the abscissa has to be a velocity axis") | ||
|
Comment on lines
+146
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. KDE path breaks for 1‑D axis. 🧩 Proposed fix if kwargs.get("kde", False) is True:
import seaborn as sns
-
- sns.kdeplot(x=x, y=y, ax=ax, color="w")
+ if len(axis) == 1:
+ sns.kdeplot(x=x, ax=ax, color="w")
+ else:
+ sns.kdeplot(x=x, y=y, ax=ax, color="w")Also applies to: 162-165 🧰 Tools🪛 GitHub Check: CodeQL[notice] 149-149: Unused local variable 🪛 Ruff (0.14.13)149-149: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
|
|
||
| siz = kwargs.get("median_filter_size", (0, 0)) | ||
| image = median_filter(h.T, size=siz) | ||
| elif "gaussian_filter_sigma" not in kwargs and "median_filter_size" not in kwargs: | ||
| image = h.T | ||
| else: | ||
| raise ValueError( | ||
| "gaussian and median filters can not be called at the same time" | ||
| bins = kwargs.get("bins", 50) | ||
| h, xh = np.histogram( | ||
| x, bins=bins, weights=new_particles.weights[:, 0] | ||
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cmap = kwargs.get("cmap", "jet") | ||
|
|
||
| cmax = kwargs.get("color_max", h.max()) | ||
| cmin = kwargs.get("color_min", h.min()) | ||
| cmin = max(cmin, 1e-4) | ||
| xh_ = 0.5*(xh[:-1]+xh[1:]) | ||
| im = ax.plot(xh_, h, drawstyle=drawstyle) | ||
Check noticeCode scanning / CodeQL Unused local variable Note
Variable im is not used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same, |
||
|
|
||
| color_scale = kwargs.get("color_scale", "log") | ||
| if color_scale == "log": | ||
| norm = LogNorm(vmin=cmin, vmax=cmax) | ||
| elif color_scale == "linear": | ||
| norm = Normalize(cmin, cmax) | ||
| ax.set_ylabel(kwargs.get("ylabel", "f")) | ||
|
|
||
| im = ax.pcolormesh(xh, yh, image, cmap=cmap, norm=norm) | ||
|
|
||
| fig.colorbar(im, ax=ax) | ||
|
|
||
| if kwargs.get("kde", False) is True: | ||
| import seaborn as sns | ||
|
|
@@ -105,7 +166,7 @@ | |
|
|
||
| ax.set_title(kwargs.get("title", "")) | ||
| ax.set_xlabel(kwargs.get("xlabel", axis[0])) | ||
| ax.set_ylabel(kwargs.get("ylabel", axis[1])) | ||
|
|
||
| if "xlim" in kwargs: | ||
| ax.set_xlim(kwargs["xlim"]) | ||
| if "ylim" in kwargs: | ||
|
|
@@ -116,15 +177,15 @@ | |
| if axis[0] in vaxis: | ||
| ax.axvline( | ||
| np.average( | ||
| particles.v[:, vaxis[axis[0]]], weights=particles.weights | ||
| new_particles.v[:, vaxis[axis[0]]], weights=new_particles.weights | ||
| ), | ||
| color="w", | ||
| ls="--", | ||
| ) | ||
| if axis[1] in vaxis: | ||
| ax.axhline( | ||
| np.average( | ||
| particles.v[:, vaxis[axis[1]]], weights=particles.weights | ||
| new_particles.v[:, vaxis[axis[1]]], weights=new_particles.weights | ||
| ), | ||
| color="w", | ||
| ls="--", | ||
|
|
@@ -331,8 +392,8 @@ | |
|
|
||
| ax.set_title(kwargs.get("title", "")) | ||
|
|
||
| ax.set_xlabel(kwargs.get("xlabel", "$x c / \omega_p$")) | ||
| ax.set_ylabel(kwargs.get("ylabel", "$y c / \omega_p$")) | ||
| ax.set_xlabel(kwargs.get("xlabel", "$x \\ (d_p)$")) | ||
| ax.set_ylabel(kwargs.get("ylabel", "$y \\ (d_p)$")) | ||
|
|
||
| if "xlim" in kwargs: | ||
| ax.set_xlim(kwargs["xlim"]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix malformed axis docstring entry.
Line 21 has
(Vy"), which reads as a typo and can confuse users.✏️ Suggested fix
🤖 Prompt for AI Agents