Skip to content

Commit

Permalink
chore(deps): update minor updates (master) (#172)
Browse files Browse the repository at this point in the history
* chore(deps): update minor updates

* ruff: make precedence clear

* ruff: f-strings

* ruff: iterate over dict with items()

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jakob van Santen <jvansanten@gmail.com>
  • Loading branch information
renovate[bot] and jvansanten authored Dec 5, 2024
1 parent 4d32b5c commit 0adaab7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
# renovate: datasource=conda depName=conda-forge/python
python-version: "3.13.0"
# renovate: datasource=pypi depName=ruff versioning=pep440
ruff-version: "0.7.4"
ruff-version: "0.8.1"
15 changes: 3 additions & 12 deletions ampel/util/Observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,8 @@ def compute_sun_moon(self, trange, which="sun", dt_min=5):
)
end = time.time()
self.logger.debug(
"Computing %s motion from %s to %s (res: %.2f min, %d steps). Took %.2f sec"
% (
which,
times.min().iso,
times.max().iso,
dt_min,
len(times),
(end - start),
)
f"Computing {which} motion from {times.min().iso} to {times.max().iso}"
f" (res: {dt_min:.2f} min, {len(times)} steps). Took {end-start:.2f} sec"
)
return skypos

Expand Down Expand Up @@ -245,9 +238,7 @@ def compute_airmass(self, zeniths):
am = (
np.sqrt(((r + y) * cosz) ** 2 + 2 * r * (1 - y) - y**2 + 1) - (r + y) * cosz
)
self.logger.debug(
"Computed airmass for %d apparent sky positions" % len(zeniths)
)
self.logger.debug(f"Computed airmass for {len(zeniths)} apparent sky positions")
return am

def compute_visibility(
Expand Down
95 changes: 45 additions & 50 deletions ampel/ztf/alert/calibrate_fps_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,8 @@ def search_peak(
# print(
# f"peaksearch max over scatt {max_over_scatt} peaksnr {peak_snr} fluxmax {flux_max} fluxscatt {flux_scatt}"
# )
if (
(max_over_scatt > single_significance and peak_snr > single_significance)
or (max_over_scatt + peak_snr) > combined_significance
and peak_snr > 3
if (max_over_scatt > single_significance and peak_snr > single_significance) or (
(max_over_scatt + peak_snr) > combined_significance and peak_snr > 3
):
sumdict["det_sn"] = True
sumdict["t_fcqfid_max"] = t_max
Expand Down Expand Up @@ -730,12 +728,12 @@ def get_baseline(
which_base = np.zeros_like(fp_df.forcediffimflux.values).astype(int)
C_baseline = np.zeros_like(fp_df.forcediffimflux.values)

for key in fcqfid_dict:
if fcqfid_dict[key]["N_bl"] > 1:
for key, value in fcqfid_dict.items():
if value["N_bl"] > 1:
ufid = int(key)
this_fcqfid = np.where(fp_df.fcqfid.values == ufid)
if deprecated:
sys_unc = max(fcqfid_dict[key]["chi_pre"] ** 0.5, 1)
sys_unc = max(value["chi_pre"] ** 0.5, 1)
else:
good_fcqfid = np.where(
(fp_df.fcqfid.values == ufid)
Expand Down Expand Up @@ -812,33 +810,31 @@ def get_baseline(
sys_unc = np.where(sys_unc < 1, 1, sys_unc)

if deprecated:
if (fcqfid_dict[key]["N_pre_peak"] >= 25) or (
(fcqfid_dict[key]["N_pre_peak"] >= 10)
and (fcqfid_dict[key]["N_post_peak"] < 25)
if (value["N_pre_peak"] >= 25) or (
(value["N_pre_peak"] >= 10) and (value["N_post_peak"] < 25)
):
baseline = fcqfid_dict[key]["C_pre"]
n_baseline = fcqfid_dict[key]["N_pre_peak"]
baseline = value["C_pre"]
n_baseline = value["N_pre_peak"]
pre_or_post = -1
elif (fcqfid_dict[key]["N_post_peak"] >= 25) or (
(fcqfid_dict[key]["N_pre_peak"] < 10)
and (fcqfid_dict[key]["N_post_peak"] >= 10)
elif (value["N_post_peak"] >= 25) or (
(value["N_pre_peak"] < 10) and (value["N_post_peak"] >= 10)
):
baseline = fcqfid_dict[key]["C_post"]
n_baseline = fcqfid_dict[key]["N_post_peak"]
baseline = value["C_post"]
n_baseline = value["N_post_peak"]
pre_or_post = 1
else:
n_base_obs[this_fcqfid] = fcqfid_dict[key]["N_pre_peak"]
n_base_obs[this_fcqfid] = value["N_pre_peak"]
which_base[this_fcqfid] = -1
continue
else:
# determine if there is emission in pre/post SN baseline
if "C_bl" not in fcqfid_dict[key]:
if "C_bl" not in value:
print(f"{ipac_name}, {key} no C_bl")
continue
baseline = fcqfid_dict[key]["median_bl"]
baseline_unc = fcqfid_dict[key]["median_unc_bl"]
base_scat = fcqfid_dict[key]["scatter_bl"]
fcqfid_dict[key]["which_bl"] = "pre+post SN"
baseline = value["median_bl"]
baseline_unc = value["median_unc_bl"]
base_scat = value["scatter_bl"]
value["which_bl"] = "pre+post SN"

good_df = fp_df.iloc[good_fcqfid].copy()
flux_series = good_df.forcediffimflux
Expand Down Expand Up @@ -868,7 +864,7 @@ def get_baseline(
)
** 2
) / len(good_df.iloc[bl])
fcqfid_dict[key]["chi2nu"] = chi2nu
value["chi2nu"] = chi2nu
if chi2nu > 2:
print("Warning! scaled unc are underestimated")
print(f"{ipac_name} {key} has chi2nu = {chi2nu:.3f}")
Expand All @@ -880,45 +876,45 @@ def get_baseline(

pre_rise_em = False
if len(pre_em) == 0:
fcqfid_dict[key]["which_bl"] = "post SN"
if len(pre_em) >= 1 and len(pre_bl[0]) < 5 or sum(pre_em >= 7) >= 2:
if (len(post_em) >= 10) and (
fcqfid_dict[key]["N_post_peak"] > 2
):
baseline = fcqfid_dict[key]["median_post"]
baseline_unc = fcqfid_dict[key]["median_unc_post"]
base_scat = fcqfid_dict[key]["scatter_post"]
fcqfid_dict[key]["which_bl"] = "post SN"
value["which_bl"] = "post SN"
if (len(pre_em) >= 1 and len(pre_bl[0]) < 5) or sum(
pre_em >= 7
) >= 2:
if (len(post_em) >= 10) and (value["N_post_peak"] > 2):
baseline = value["median_post"]
baseline_unc = value["median_unc_post"]
base_scat = value["scatter_post"]
value["which_bl"] = "post SN"
if sum(pre_em >= 7) >= 2:
print(f"Warning {ipac_name} {ufid} pre-SN")
fcqfid_dict[key]["Warning"] = "pre-SN emission"
value["Warning"] = "pre-SN emission"
pre_rise_em = True
fp_df.loc[fp_df.fcqfid == ufid, "flags"] += 2

post_rise_em = False
if len(post_em) == 0:
fcqfid_dict[key]["which_bl"] = "pre SN"
value["which_bl"] = "pre SN"
if len(post_em) >= 1 and (
len(post_em) < 5 or sum(post_em >= 7) >= 2
):
if (len(pre_em) >= 10) and (fcqfid_dict[key]["N_pre_peak"] > 2):
baseline = fcqfid_dict[key]["median_pre"]
baseline_unc = fcqfid_dict[key]["median_unc_pre"]
base_scat = fcqfid_dict[key]["scatter_pre"]
fcqfid_dict[key]["which_bl"] = "pre SN"
if (len(pre_em) >= 10) and (value["N_pre_peak"] > 2):
baseline = value["median_pre"]
baseline_unc = value["median_unc_pre"]
base_scat = value["scatter_pre"]
value["which_bl"] = "pre SN"
if sum(post_em >= 7) >= 2:
print(f"Warning {ipac_name} {ufid} post-SN")
fcqfid_dict[key]["Warning"] = "post-SN emission"
value["Warning"] = "post-SN emission"
post_rise_em = True
fp_df.loc[fp_df.fcqfid == ufid, "flags"] += 4

if pre_rise_em + post_rise_em == 2:
baseline = fcqfid_dict[key]["median_bl"]
baseline_unc = fcqfid_dict[key]["median_unc_bl"]
base_scat = fcqfid_dict[key]["scatter_bl"]
baseline = value["median_bl"]
baseline_unc = value["median_unc_bl"]
base_scat = value["scatter_bl"]
print(f"Warning {ipac_name} {ufid} bad baseline")
fcqfid_dict[key]["Warning"] = "bad baseline"
fcqfid_dict[key]["which_bl"] = "pre+post SN"
value["Warning"] = "bad baseline"
value["which_bl"] = "pre+post SN"
# fp_df.loc[fp_df.fcqfid == ufid, 'flags'] += 512
if base_scat > 100:
fp_df.loc[fp_df.fcqfid == ufid, "flags"] += 16
Expand Down Expand Up @@ -984,16 +980,15 @@ def get_baseline(
nplots = 0
jdstart = 2458119.5

for key in fcqfid_dict:
if fcqfid_dict[key]["N_bl"] > 1:
for key, value in fcqfid_dict.items():
if value["N_bl"] > 1:
this_fcqfid_good = np.where(
(fp_df.fcqfid.values == int(key)) & (bad_obs == 0)
)
plot_flux = fnu_microJy[this_fcqfid_good]

if (plot_flux == -999).sum() != len(plot_flux) and (
(fcqfid_dict[key]["N_pre_peak"] > 2)
or (fcqfid_dict[key]["N_post_peak"] > 2)
(value["N_pre_peak"] > 2) or (value["N_post_peak"] > 2)
):
nplots += 1

Expand Down
4 changes: 2 additions & 2 deletions ampel/ztf/dev/DevAlertConsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def _run(self, iterable, load, iter_max=5000, iter_offset=0):
break

self._logger.info(
"%i alert(s) processed (time required: %is)"
% (iter_count - iter_offset, int(time.time() - run_start))
f"{iter_count - iter_offset} alert(s) processed"
f" (time required: {time.time() - run_start:.0f}s)"
)

# Return number of processed alerts
Expand Down
9 changes: 3 additions & 6 deletions ampel/ztf/dev/ZTFAlert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ def to_alert(cls, file_path: str) -> AmpelAlert:
@staticmethod
def _upper_limit_id(el: dict[str, Any]) -> int:
return int(
"%i%s%i"
% (
(2457754.5 - el["jd"]) * 1000000,
str(el["pid"])[8:10],
round(abs(el["diffmaglim"]) * 1000),
)
f'{(2457754.5 - el["jd"]) * 1000000:.0f}'
f'{str(el["pid"])[8:10]}'
f'{round(abs(el["diffmaglim"]) * 1000):.0f}'
)

@classmethod
Expand Down
Loading

0 comments on commit 0adaab7

Please sign in to comment.