Skip to content
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

Changed to fstring #1706

Merged
merged 5 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 12 additions & 18 deletions tardis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,15 @@ def plot_wave_in_out(self, fig, do_clf=True, plot_resonance=True):
def onpick(event):
print("-" * 80)
print(
"Line_in (%d/%d):\n%s"
% (
len(event.ind),
self.current_no_packets,
self.last_line_list_in.ix[event.ind],
)
"Line_in"
f"({len(event.ind)}/{self.current_no_packets})"
f":\n{self.last_line_list_in.ix[event.ind]}"
)
print("\n\n")
print(
"Line_out (%d/%d):\n%s"
% (
len(event.ind),
self.current_no_packets,
self.last_line_list_in.ix[event.ind],
)
"Line_out"
f"({len(event.ind)}/{self.current_no_packets})"
f":\n{self.last_line_list_in.ix[event.ind]}"
)
print("^" * 80)

Expand Down Expand Up @@ -262,7 +256,7 @@ def load_t_inner(self, iterations=None):

for iter in iterations:
t_inners.append(
hdf_store["model%03d/configuration" % iter].ix["t_inner"]
hdf_store[f"model{iter:03d}/configuration"].ix["t_inner"]
)
hdf_store.close()

Expand All @@ -281,8 +275,8 @@ def load_t_rads(self, iterations=None):
iterations = self.iterations[iterations]

for iter in iterations:
current_iter = "iter%03d" % iter
t_rads_dict[current_iter] = hdf_store["model%03d/t_rads" % iter]
current_iter = f"iter{iter:03d}"
t_rads_dict[current_iter] = hdf_store[f"model{iter:03d}/t_rads"]

t_rads = pd.DataFrame(t_rads_dict)
hdf_store.close()
Expand Down Expand Up @@ -319,7 +313,7 @@ def load_level_populations(self, iterations=None):
iterations = self.iterations[iterations]

for iter in iterations:
current_iter = "iter%03d" % iter
current_iter = f"iter{iter:03d}"
level_populations_dict[current_iter] = hdf_store[
f"model{iter:03d}/level_populations"
]
Expand Down Expand Up @@ -381,7 +375,7 @@ def load_spectrum(self, iteration, spectrum_keyword="luminosity_density"):
hdf_store = pd.HDFStore(self.hdf5_fname, "r")

spectrum = hdf_store[
"model%03d/%s" % (self.iterations[iteration], spectrum_keyword)
f"model{self.iterations[iteration]:03d}/{spectrum_keyword}"
]
hdf_store.close()
return spectrum
Expand Down Expand Up @@ -426,7 +420,7 @@ def get_last_line_interaction(self, iteration=-1):
self.load_atom_data()

hdf_store = pd.HDFStore(self.hdf5_fname, "r")
model_string = "model" + ("%03d" % iteration) + "/%s"
model_string = "model" + (f"{iteration:03d}" ) + "/%s"
last_line_interaction_in_id = hdf_store[
model_string % "last_line_interaction_in_id"
].values
Expand Down
28 changes: 9 additions & 19 deletions tardis/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def __init__(self, index, tablecreator, parent=None):
self.parent = parent
self.shell_index = index
self.setGeometry(400, 150, 200, 400)
self.setWindowTitle("Shell %d Abundances" % (self.shell_index + 1))
self.setWindowTitle(f"Shell {self.shell_index + 1} Abundances" )
self.atomstable = QtWidgets.QTableView()
self.ionstable = QtWidgets.QTableView()
self.levelstable = QtWidgets.QTableView()
Expand All @@ -829,7 +829,7 @@ def __init__(self, index, tablecreator, parent=None):

self.table1_data = self.parent.model.plasma.abundance[self.shell_index]
self.atomsdata = self.createTable(
[["Z = "], ["Count (Shell %d)" % (self.shell_index + 1)]],
[["Z = "], [f"Count (Shell {self.shell_index + 1})" ]],
iterate_header=(2, 0),
index_info=self.table1_data.index.values.tolist(),
)
Expand All @@ -855,7 +855,7 @@ def on_atom_header_double_clicked(self, index):
self.shell_index
].ix[self.current_atom_index]
self.ionsdata = self.createTable(
[["Ion: "], ["Count (Z = %d)" % self.current_atom_index]],
[["Ion: "], [f"Count (Z = {self.current_atom_index})"]],
iterate_header=(2, 0),
index_info=self.table2_data.index.values.tolist(),
)
Expand Down Expand Up @@ -889,7 +889,7 @@ def on_ion_header_double_clicked(self, index):
self.shell_index
].ix[self.current_atom_index, self.current_ion_index]
self.levelsdata = self.createTable(
[["Level: "], ["Count (Ion %d)" % self.current_ion_index]],
[["Level: "], [f"Count (Ion {self.current_ion_index})" ]],
iterate_header=(2, 0),
index_info=self.table3_data.index.values.tolist(),
)
Expand Down Expand Up @@ -931,11 +931,7 @@ def __init__(self, parent, wavelength_start, wavelength_end, tablecreator):
self.parent = parent
self.setGeometry(180 + len(self.parent.line_info) * 20, 150, 250, 400)
self.setWindowTitle(
"Line Interaction: %.2f - %.2f (A) "
% (
wavelength_start,
wavelength_end,
)
f"Line Interaction: {wavelength_start:.2f} - {wavelength_end:.2f} (A) "
)
self.layout = QtWidgets.QVBoxLayout()
packet_nu_line_interaction = analysis.LastLineInteraction.from_model(
Expand Down Expand Up @@ -1010,7 +1006,7 @@ def get_data(self, wavelength_start, wavelength_end):
/ self.grouped_lines_in.wavelength.count().sum()
).values.tolist()
for z, ion in self.ions_in:
self.header_list.append("Z = %d: Ion %d" % (z, ion))
self.header_list.append(f"Z = {z}: Ion {ion}" )

def get_transition_table(self, lines, atom, ion):
"""Called by the two methods below to get transition table for
Expand Down Expand Up @@ -1043,14 +1039,8 @@ def get_transition_table(self, lines, atom, ion):
transitions_count[index] /= float(s)
for key, value in transitions.items():
transitions_parsed.append(
"%d-%d (%.2f A)"
% (
key[0],
key[1],
self.parent.model.atom_data.lines.ix[value[0]][
"wavelength"
],
)
f"{key[0]}-{key[1]}"
f"{self.parent.model.atom_data.lines.ix[value[0]]["wavelength"]:.2f} A"
)
return transitions_parsed, transitions_count

Expand Down Expand Up @@ -1225,7 +1215,7 @@ def on_species_clicked(self, index):
last_line_in_model = self.createTable(
[
last_line_in_string,
["Num. pkts %d" % current_last_line_in.wavelength.count()],
[f"Num. pkts {current_last_line_in.wavelength.count()}"],
]
)
last_line_in_model.add_data(last_line_count)
Expand Down
4 changes: 2 additions & 2 deletions tardis/io/parsers/csvy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def load_csvy(fname):
yaml_end_ind = i
break
else:
raise ValueError("End %s not found" % (YAML_DELIMITER))
raise ValueError(f"End {YAML_DELIMITER} not found" )
yaml_dict = yaml.load("".join(yaml_lines[1:-1]), YAMLLoader)
try:
data = pd.read_csv(fname, skiprows=yaml_end_ind + 1)
Expand Down Expand Up @@ -67,7 +67,7 @@ def load_yaml_from_csvy(fname):
yaml_end_ind = i
break
else:
raise ValueError("End %s not found" % (YAML_DELIMITER))
raise ValueError(f"End {YAML_DELIMITER} not found" )
yaml_dict = yaml.load("".join(yaml_lines[1:-1]), YAMLLoader)
return yaml_dict

Expand Down
2 changes: 1 addition & 1 deletion tardis/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def download_from_url(url, dst):
first_byte = 0
if first_byte >= file_size:
return file_size
header = {"Range": "bytes=%s-%s" % (first_byte, file_size)}
header = {f"Range": "bytes={first_byte}-{file_size}" }
pbar = tqdm(
total=file_size,
initial=first_byte,
Expand Down
8 changes: 4 additions & 4 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ def from_csvy(cls, config):
), "CSVY field descriptions exist without corresponding csv data"
if unsupported_columns != set():
logger.warning(
"The following columns are specified in the csvy"
"model file, but are IGNORED by TARDIS: %s"
% (str(unsupported_columns))
)
"The following columns are "
"specified in the csvy model file,"
f" but are IGNORED by TARDIS: {str(unsupported_columns)}"
)

time_explosion = config.supernova.time_explosion.cgs

Expand Down