Skip to content

Commit a19d939

Browse files
committed
move data loading to kipp_args
this allows creating one kipp_args and reusing it for various subplots
1 parent 2860975 commit a19d939

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

Kippenhahn.png

-882 Bytes
Loading

Kippenhahn2.png

-1.17 KB
Loading

Kippenhahn3.png

-594 Bytes
Loading

Kippenhahn4.png

-317 Bytes
Loading

Kippenhahn5.png

-1.19 KB
Loading

Kippenhahn6.png

-1.17 KB
Loading

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
mkipp.kipp_plot(mkipp.Kipp_Args())
1111

1212
#specify xrange and filename
13-
mkipp.kipp_plot(mkipp.Kipp_Args(save_filename = "Kippenhahn2.png"), xlims = [300,600])
13+
mkipp.kipp_plot(mkipp.Kipp_Args(save_filename = "Kippenhahn2.png", xlims = [300,600]))
1414

1515
#plot of Helium abundance against time, independent decoration
1616
fig = plt.figure()

mkipp.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def __init__(self,
7777
decorate_plot = True,
7878
show_plot = False,
7979
save_file = True,
80-
save_filename = "Kippenhahn.png"):
80+
save_filename = "Kippenhahn.png",
81+
xlims = None):
8182
"""Initializes properties for a Kippenhahn plot
8283
8384
Note:
@@ -124,12 +125,11 @@ def __init__(self,
124125
show_plot (bool): If True, pyplot.show() is ran at the end
125126
save_file (bool): If True, plot is saved after pyplot.show()
126127
save_filename (str): Filename to save plot. Extension determines filetype.
128+
xlims (Tuple(float)): range in x to which the loaded data is restricted. By default all data is loaded
127129
128130
"""
129131

130132
self.logs_dirs = logs_dirs
131-
self.profile_paths = profile_paths
132-
self.history_paths = history_paths
133133
self.clean_data = clean_data
134134
self.extra_history_cols = extra_history_cols
135135
self.identifier = identifier
@@ -158,11 +158,26 @@ def __init__(self,
158158
self.show_plot = show_plot
159159
self.save_file = save_file
160160
self.save_filename = save_filename
161+
self.xlims = xlims
162+
163+
#Fill profile and history names if unspecified
164+
self.profile_paths = profile_paths
165+
if len(self.profile_paths) == 0:
166+
self.profile_paths = get_profile_paths(logs_dirs = self.logs_dirs)
167+
168+
self.history_paths = history_paths
169+
if len(self.history_paths) == 0:
170+
self.history_paths = []
171+
for log_dir in self.logs_dirs:
172+
self.history_paths.append(log_dir+"/history.data")
173+
174+
self.xyz_data = get_xyz_data(self.profile_paths, self, xlims = xlims)
175+
self.mixing_zones = get_mixing_zones(self.history_paths, self, xlims = xlims)
161176

162177

163178
#kipp_plot: Plots a Kippenhahn diagram into the matplotlib axis given. No decoration
164179
# done (i.e. axis labeling or colorbars). Returns
165-
def kipp_plot(kipp_args, axis=None, xlims = None):
180+
def kipp_plot(kipp_args, axis=None):
166181
xaxis_divide = kipp_args.xaxis_divide
167182
if kipp_args.xaxis == "star_age":
168183
if kipp_args.time_units == "1000 yr":
@@ -176,17 +191,7 @@ def kipp_plot(kipp_args, axis=None, xlims = None):
176191
fig = plt.figure()
177192
axis = fig.gca()
178193

179-
#Fill profile and history names if unspecified
180-
profile_paths = kipp_args.profile_paths
181-
if len(profile_paths) == 0:
182-
profile_paths = get_profile_paths(logs_dirs = kipp_args.logs_dirs)
183-
history_paths = kipp_args.history_paths
184-
if len(history_paths) == 0:
185-
history_paths = []
186-
for log_dir in kipp_args.logs_dirs:
187-
history_paths.append(log_dir+"/history.data")
188-
189-
xyz_data = get_xyz_data(profile_paths, kipp_args, xlims = xlims)
194+
xyz_data = kipp_args.xyz_data
190195

191196
#only plot if there is data
192197
if xyz_data.Z.size > 0:
@@ -207,9 +212,7 @@ def kipp_plot(kipp_args, axis=None, xlims = None):
207212
contour_plot = axis.contourf([[None,None]], [[None,None]], [[None,None]], \
208213
cmap=kipp_args.contour_colormap, antialiased = False)
209214

210-
211-
mixing_zones = get_mixing_zones(history_paths, kipp_args, xlims = xyz_data.xlims)
212-
215+
mixing_zones = kipp_args.mixing_zones
213216

214217
for i,zone in enumerate(mixing_zones.zones):
215218
color = ""
@@ -289,8 +292,8 @@ def kipp_plot(kipp_args, axis=None, xlims = None):
289292
else:
290293
axis.set_ylabel(r'$m/M_\odot$')
291294

292-
if xlims != None:
293-
axis.set_xlim(xlims)
295+
if kipp_args.xlims != None:
296+
axis.set_xlim(kipp_args.xlims)
294297

295298
if kipp_args.show_plot:
296299
plt.show()

0 commit comments

Comments
 (0)