Skip to content

Commit 75fc771

Browse files
refactor: Deprecate DataContainer and replace with xarray (#168)
- The custom `DataContainer` class has been deprecated and replaced with `xarray.Dataset`. - An `xarray` accessor `fleks` has been created to house the domain-specific logic for calculating derived variables and plotting. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent d791c90 commit 75fc771

8 files changed

Lines changed: 436 additions & 789 deletions

File tree

docs/amrex_data.ipynb

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@
578578
"cell_type": "markdown",
579579
"metadata": {},
580580
"source": [
581-
"Flekspy provides convenient wrappers for creating plots from these slices."
581+
"`flekspy` provides convenient wrappers for creating plots from these slices. You can use query syntax to plot with value range limits:"
582582
]
583583
},
584584
{
@@ -587,9 +587,11 @@
587587
"metadata": {},
588588
"outputs": [],
589589
"source": [
590-
"f, axes = dc.plot(\"By\", pcolor=True)\n",
591-
"dc.add_stream(axes[0], \"Bx\", \"By\", color=\"w\")\n",
592-
"dc.add_contour(axes[0], \"Bx\")"
590+
"f, axes = dc.fleks.plot(\"Bx>(2.2e5)<(3e5) Ex\", pcolor=True, figsize=(12, 6))\n",
591+
"dc.fleks.add_stream(axes[0], \"Bx\", \"By\", color=\"w\")\n",
592+
"dc.fleks.add_contour(axes[1], \"Bx\")\n",
593+
"\n",
594+
"plt.show()"
593595
]
594596
},
595597
{
@@ -611,19 +613,19 @@
611613
"\n",
612614
"fields = [\"By\", \"Bz\"]\n",
613615
"for ivar in range(2):\n",
614-
" v = dc.evaluate_expression(fields[ivar])\n",
616+
" v = dc.fleks.evaluate_expression(fields[ivar])\n",
615617
" vmin = v.min().v\n",
616618
" vmax = v.max().v\n",
617619
" ax = axes[ivar]\n",
618620
" ax.set_title(fields[ivar], fontsize=16)\n",
619621
" ax.set_ylabel(\"Y\", fontsize=16)\n",
620622
" ax.set_xlabel(\"X\", fontsize=16)\n",
621-
" c = ax.pcolormesh(dc.x.value, dc.y.value, np.array(v.T), cmap=\"turbo\")\n",
623+
" c = ax.pcolormesh(dc.X.values, dc.Y.values, np.array(v.T), cmap=\"turbo\")\n",
622624
" cb = f.colorbar(c, ax=ax, pad=0.01)\n",
623625
"\n",
624-
" ax.set_xlim(np.min(dc.x.value), np.max(dc.x.value))\n",
625-
" ax.set_xlim(np.min(dc.y.value), np.max(dc.y.value))\n",
626-
" dc.add_stream(ax, \"Bx\", \"By\", density=0.5, color=\"w\")\n",
626+
" ax.set_xlim(np.min(dc.X.values), np.max(dc.X.values))\n",
627+
" ax.set_xlim(np.min(dc.Y.values), np.max(dc.Y.values))\n",
628+
" dc.fleks.add_stream(ax, \"Bx\", \"By\", density=0.5, color=\"w\")\n",
627629
"\n",
628630
"plt.show()"
629631
]
@@ -760,29 +762,6 @@
760762
"pp_phase.show()"
761763
]
762764
},
763-
{
764-
"cell_type": "markdown",
765-
"metadata": {},
766-
"source": [
767-
"### Advanced Example: Slicing with Range Limits\n",
768-
"\n",
769-
"Now we'll use the second dataset to show a more advanced slicing feature. Inheriting from IDL procedures, you can pass strings to `plot` to limit the plotting range (note: this syntax is experimental)."
770-
]
771-
},
772-
{
773-
"cell_type": "code",
774-
"execution_count": null,
775-
"metadata": {},
776-
"outputs": [],
777-
"source": [
778-
"ds2 = flekspy.load(\"data/fleks_particle_small/3d*amrex\")\n",
779-
"dc2 = ds2.get_slice(\"z\", 0.001)\n",
780-
"\n",
781-
"f, axes = dc2.plot(\"Bx>(2.2e5)<(3e5) Ex\", figsize=(12, 6))\n",
782-
"dc2.add_stream(axes[0], \"Bx\", \"By\", color=\"w\")\n",
783-
"dc2.add_contour(axes[1], \"Bx\", color=\"k\")"
784-
]
785-
},
786765
{
787766
"cell_type": "markdown",
788767
"metadata": {},
@@ -850,4 +829,4 @@
850829
},
851830
"nbformat": 4,
852831
"nbformat_minor": 4
853-
}
832+
}

src/flekspy/util/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,3 @@
44
get_unit,
55
get_ticks,
66
)
7-
from .data_container import (
8-
DataContainer,
9-
DataContainer1D,
10-
DataContainer2D,
11-
DataContainer3D,
12-
)

0 commit comments

Comments
 (0)