Skip to content
Draft
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
53 changes: 31 additions & 22 deletions Exec/science/xrb_spherical/analysis/inset_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
def single_slice(ds, field:str,
loc: str = "top", widthScale: float = 3.0,
theta: Optional[float] = None,
position: float | None = None,
displace_theta: bool = True,
annotate_vline: bool = True,
annotate_lat_lines: bool = True,
show_full_star: bool = True) -> None:
"""
A slice plot a single dataset for a single field parameters for Spherical2D geometry.
Expand All @@ -45,14 +44,13 @@ def single_slice(ds, field:str,
theta:
user defined theta center of the slice plot

position:
draw a vertical line on user defined front position in theta (in radian)

displace_theta:
When theta is explicitly defined, do we want to displace the center
of the slice plot by ~0.7. This is helpful when tracking the flame front.

annotate_vline:
do we want to annotate a vertical line at where theta is.
This is used to indicate flame front.

show_full_star:
do we want to plot the full star instead of a zoom-in slice plot.
"""
Expand Down Expand Up @@ -96,18 +94,17 @@ def single_slice(ds, field:str,
# sp.annotate_text((0.05, 0.05), f"{currentTime.in_cgs():8.5f} s")

# Plot a vertical to indicate flame front
if theta is not None and annotate_vline:
sp.annotate_line([r[0]*np.sin(theta), r[0]*np.cos(theta)],
[r[2]*np.sin(theta), r[2]*np.cos(theta)],
if position is not None:
sp.annotate_line([r[0]*np.sin(position), r[0]*np.cos(position)],
[r[2]*np.sin(position), r[2]*np.cos(position)],
coord_system="plot",
color="k",
linewidth=1.5,
linestyle="-.")

### Annotate Latitude Lines
if annotate_lat_lines:
annotate_latitude_lines(sp, center, box_widths, r,
show_full_star=show_full_star)
annotate_latitude_lines(sp, center, box_widths, r,
show_full_star=show_full_star)

sp._setup_plots()
return sp
Expand All @@ -131,13 +128,14 @@ def single_slice(ds, field:str,
parser.add_argument('-t', '--theta', type=float,
help="""user defined theta center location of the plot domain.
Alternative way of defining plotting center""")
parser.add_argument('-p', '--position', type=float,
help="""user defined front position in theta,
this will draw a vertical line to annotate the front position""")
parser.add_argument('-w', '--width', default=2.0, type=float,
help="scaling for the domain width of the slice plot")
parser.add_argument('--displace_theta', action='store_true',
help="""whether to displace the theta that defines the center of the frame.
This is useful when theta represents the flame front position.""")
parser.add_argument('--annotate_vline', action='store_true',
help="whether to annotate a vertical line along the given theta")

args = parser.parse_args()

Expand All @@ -152,9 +150,9 @@ def single_slice(ds, field:str,

# First get the slice plot of the full-star.
full_star_slice = single_slice(ds, args.field, loc=loc,
widthScale=args.width, theta=args.theta,
displace_theta=args.displace_theta, annotate_vline=args.annotate_vline,
annotate_lat_lines=True, show_full_star=True)
widthScale=args.width, theta=args.theta, position=args.position,
displace_theta=args.displace_theta,
show_full_star=True)
# full_star_slice.render()

# Extract the figure of the full-star slice and use that as the main figure for plotting.
Expand All @@ -166,9 +164,9 @@ def single_slice(ds, field:str,

# Get the slice of the zoom-in plot
zoom_in_slice = single_slice(ds, args.field, loc=loc,
widthScale=args.width, theta=args.theta,
displace_theta=args.displace_theta, annotate_vline=args.annotate_vline,
annotate_lat_lines=True, show_full_star=False)
widthScale=args.width, theta=args.theta, position=args.position,
displace_theta=args.displace_theta,
show_full_star=False)
zoom_in_slice.hide_colorbar()
# zoom_in_slice.render()

Expand Down Expand Up @@ -226,10 +224,21 @@ def single_slice(ds, field:str,

### Now annotate inset box lines ###
# loc1 and loc2: corners to connect (1: upper right, 2: upper left, 3: lower left, 4: lower right)
if args.theta < np.pi/3.0 or (args.theta is None and loc=="top"):
if args.theta is None:
if loc == "top":
loc1 = 1
loc2 = 2
elif loc == "bot":
loc1 = 3
loc2 = 4
else:
# mid
loc1 = 1
loc2 = 4
elif args.theta < np.pi/3.0:
loc1 = 1
loc2 = 2
elif args.theta > 2.0*np.pi/3.0 or (args.theta is None and loc=="bot"):
elif args.theta > 2.0*np.pi/3.0:
loc1 = 3
loc2 = 4
else:
Expand Down
38 changes: 17 additions & 21 deletions Exec/science/xrb_spherical/analysis/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ def slice(fnames:list[str], fields:list[str],
loc: str = "top", widthScale: float = 3.0,
widthRatio: float = 1.0,
theta: float | None = None,
position: float | None = None,
displace_theta: bool = False,
annotate_vline: bool = False,
annotate_lat_lines: bool = True,
show_full_star: bool = False) -> None:
"""
A slice plot of the datasets for different field parameters for Spherical2D geometry.
Expand Down Expand Up @@ -252,19 +251,15 @@ def slice(fnames:list[str], fields:list[str],
For widthRatio > 1, the vertical width is larger than horizontal.

theta:
user defined theta center of the slice plot
user defined theta (in radian) center of the slice plot

position:
draw a vertical line on user defined front position in theta (in radian)

displace_theta:
whether to displace theta so that the vertical lines that represents
the flame front is offset by some amount

annotate_vline:
whether to plot a vertical line to represent the flame front,
which is represented by what theta is.

annotate_lat_lines:
whether to annotate latitude lines.

show_full_star:
whether to plot the full star rather than a zoom-in
"""
Expand Down Expand Up @@ -321,18 +316,17 @@ def slice(fnames:list[str], fields:list[str],
# sp.annotate_text((0.05, 0.05), f"{currentTime.in_cgs():8.5f} s")

# Plot a vertical to indicate flame front
if theta is not None and annotate_vline:
sp.annotate_line([r[0]*np.sin(theta), r[0]*np.cos(theta)],
[r[2]*np.sin(theta), r[2]*np.cos(theta)],
if position is not None:
sp.annotate_line([r[0]*np.sin(position), r[0]*np.cos(position)],
[r[2]*np.sin(position), r[2]*np.cos(position)],
coord_system="plot",
color="k",
linewidth=1.5,
linestyle="-.")

### Annotate Latitude Lines
if annotate_lat_lines:
annotate_latitude_lines(sp, center, box_widths, r,
show_full_star=show_full_star)
annotate_latitude_lines(sp, center, box_widths, r,
show_full_star=show_full_star)

plot = sp.plots[field]
plot.figure = fig
Expand Down Expand Up @@ -391,6 +385,9 @@ def slice(fnames:list[str], fields:list[str],
parser.add_argument('-t', '--theta', type=float,
help="""user defined theta center location of the plot domain.
Alternative way of defining plotting center""")
parser.add_argument('-p', '--position', type=float,
help="""user defined front position in theta,
this will draw a vertical line to annotate the front position""")
parser.add_argument('-r', '--ratio', default=1.0, type=float,
help="""The ratio between the horizontal and vertical width of the slice plot.
For ratio < 1, horizontal width is larger than vertical.
Expand All @@ -400,8 +397,6 @@ def slice(fnames:list[str], fields:list[str],
parser.add_argument('--displace_theta', action='store_true',
help="""whether to displace the theta that defines the center of the frame.
This is useful when theta represents the flame front position.""")
parser.add_argument('--annotate_vline', action='store_true',
help="whether to annotate a vertical line along the given theta")
parser.add_argument('--show_full_star', action='store_true',
help="whether show the full star in the background")

Expand All @@ -417,6 +412,7 @@ def slice(fnames:list[str], fields:list[str],
parser.error("loc must be one of the three: {top, mid, bot}")

slice(args.fnames, args.fields, loc=loc,
widthScale=args.width, widthRatio=args.ratio, theta=args.theta,
displace_theta=args.displace_theta, annotate_vline=args.annotate_vline,
annotate_lat_lines=True, show_full_star=args.show_full_star)
widthScale=args.width, widthRatio=args.ratio,
theta=args.theta, position=args.position,
displace_theta=args.displace_theta,
show_full_star=args.show_full_star)
12 changes: 7 additions & 5 deletions Exec/science/xrb_spherical/analysis/slice_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
parser.add_argument('--displace_theta', action='store_true',
help="""whether to displace the theta that defines the center of the frame.
This is useful when theta represents the flame front position.""")
parser.add_argument('--annotate_vline', action='store_true',
help="whether to annotate a vertical line along the given theta")
parser.add_argument('--jobs', '-j', default=1, type=int,
help="""Number of workers to plot in parallel""")

Expand All @@ -40,13 +38,17 @@
fnames = tracking_data["fname"]
front_thetas = tracking_data["front_theta"]

# Process front_thetas to increase monotonically so that movie doesn't jitter
thetas = [front_thetas[0]]
for theta in front_thetas[1:]:
thetas.append(max(theta, thetas[-1]))

# Parallelize the plotting
with ProcessPoolExecutor(max_workers=args.jobs) as executor:
future_to_index = {
executor.submit(slice, [fname], args.fields, widthScale=args.width,
widthRatio=args.ratio, theta=front_thetas[i],
displace_theta=args.displace_theta, annotate_vline=args.annotate_vline,
annotate_lat_lines=True): i
widthRatio=args.ratio, theta=thetas[i], position=front_thetas[i],
displace_theta=args.displace_theta): i
for i, fname in enumerate(fnames)
}
try:
Expand Down