Skip to content

Commit

Permalink
Merge pull request #37 from hugovk/rm-2
Browse files Browse the repository at this point in the history
Upgrade Python syntax with pyupgrade
  • Loading branch information
HealthyPear committed Sep 21, 2020
2 parents 12afef5 + 1cdceeb commit e7ae38e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyirf/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_config(name):
"""
try:
with open(name, "r") as stream:
with open(name) as stream:
cfg = yaml.load(stream, Loader=yaml.FullLoader)
except FileNotFoundError as e:
print(e)
Expand Down
14 changes: 7 additions & 7 deletions pyirf/perf/cut_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def apply_cuts(self, debug):
for particle in self.evt_dict.keys():
data = self.apply_cuts_on_data(self.evt_dict[particle].copy(), debug)
data.to_hdf(
os.path.join(self.outdir, "{}_processed.h5".format(particle)),
os.path.join(self.outdir, f"{particle}_processed.h5"),
key="dl2",
mode="w",
)
Expand Down Expand Up @@ -499,7 +499,7 @@ def find_best_cutoff(self, energy_values, angular_values):
for ibin in range(len(energy_values) - 1):
emin = energy_values[ibin]
emax = energy_values[ibin + 1]
print(" ==> {}) Working in E=[{:.3f},{:.3f}]".format(ibin, emin, emax))
print(f" ==> {ibin}) Working in E=[{emin:.3f},{emax:.3f}]")

# OLDER PANDAS EQUIVALENT FROM PROTOPIPE

Expand Down Expand Up @@ -552,7 +552,7 @@ def find_best_cutoff(self, energy_values, angular_values):
# Loop on angular cut
for th_cut in theta_to_loop_on:
if self.verbose_level > 0:
print("- Theta={:.2f}".format(th_cut))
print(f"- Theta={th_cut:.2f}")

# Select gamma-rays in ON region

Expand Down Expand Up @@ -626,8 +626,8 @@ def find_best_cutoff(self, energy_values, angular_values):
key_list = []
for key in results_th_cut_dict:
key_list.append(key)
flux_list.append((results_th_cut_dict[key]["result"]["min_flux"]))
eff_sig.append((results_th_cut_dict[key]["result"]["eff_sig"]))
flux_list.append(results_th_cut_dict[key]["result"]["min_flux"])
eff_sig.append(results_th_cut_dict[key]["result"]["eff_sig"])
th.append(results_th_cut_dict[key]["th_cut"])

# In case of equal min fluxes, take the one with bigger sig efficiency
Expand Down Expand Up @@ -804,11 +804,11 @@ def _get_sigma_flux(cls, excess, bkg, alpha, min_sigma):

@classmethod
def _get_energy_key(cls, emin, emax):
return "{:.3f}-{:.3f}TeV".format(emin, emax)
return f"{emin:.3f}-{emax:.3f}TeV"

@classmethod
def _get_angular_key(cls, ang):
return "{:.3f}deg".format(ang)
return f"{ang:.3f}deg"

def get_binned_data(self, g, p, e, nbins=100, score_range=[-1, 1]):
"""Returns binned data as a dictionnary"""
Expand Down
2 changes: 1 addition & 1 deletion pyirf/scripts/lst_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def main(args):
# Set 0.05 as a lower value
idx = np.where(thsq_values.value < 0.05)
thsq_values[idx] = 0.05 * u.deg
print('Using theta cut: {}'.format(thsq_values))
print(f'Using theta cut: {thsq_values}')

# Cuts optimisation
print('### Finding best cuts...')
Expand Down
6 changes: 3 additions & 3 deletions pyirf/scripts/make_DL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ def main():
thsq_opt_type = cfg["analysis"]["thsq_opt"]["type"]
if thsq_opt_type == "fixed":
thsq_values = np.array([cfg["analysis"]["thsq_opt"]["value"]]) * u.deg
print("Using fixed theta cut: {}".format(thsq_values))
print(f"Using fixed theta cut: {thsq_values}")
elif thsq_opt_type == "opti":
thsq_values = np.arange(0.05, 0.40, 0.01) * u.deg
print("Optimising theta cut for: {}".format(thsq_values))
print(f"Optimising theta cut for: {thsq_values}")
elif thsq_opt_type == "r68":
print("Using R68% theta cut")
print("Computing...")
Expand Down Expand Up @@ -275,7 +275,7 @@ def main():
# Set 0.05 as a lower value
idx = np.where(thsq_values.value < 0.05)
thsq_values[idx] = 0.05 * u.deg
print("Using theta cut: {}".format(thsq_values))
print(f"Using theta cut: {thsq_values}")

# Cuts optimisation
print("### Finding best cuts...")
Expand Down

0 comments on commit e7ae38e

Please sign in to comment.