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

ci: upgrade ruff #169

Merged
merged 7 commits into from
Nov 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ jobs:
lint: true
# renovate: datasource=conda depName=conda-forge/python
python-version: "3.12.6"
# renovate: datasource=pypi depName=ruff versioning=pep440
ruff-version: "0.7.4"
1 change: 0 additions & 1 deletion ampel/template/ZTFLegacyChannelTemplate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/template/ZTFLegacyChannelTemplate.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/template/ZTFPeriodicSummaryT3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-core/ampel/model/template/PeriodicSummaryT3.py
# License: BSD-3-Clause
# Author: Jakob van Santen <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/template/ZTFProcessLocalAlerts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/template/ZTFProcessLocalAlerts.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
27 changes: 13 additions & 14 deletions ampel/util/Observatory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: ampel/base/Observatory.py
# License: BSD-3-Clause
# Author: [email protected]
Expand Down Expand Up @@ -122,13 +121,11 @@ def set_atmosphere(self, pressure, temperature, rel_humidity, wlength):
self.av_wlength = wlength * 1e-9 * u.m

# some logging
mssg = "\t\t\t\t\t-pressure: %f Pa\n" % pressure
mssg += "\t\t\t\t\t-temperature: %f Celsius\n" % temperature
mssg += "\t\t\t\t\t-relatice humidity: %f perc.\n" % rel_humidity
mssg += "\t\t\t\t\t-central wavelength: %f nm" % wlength
self.logger.info(
"set atmospheric parameters at observatory location: %s" % mssg
)
mssg = f"\t\t\t\t\t-pressure: {pressure:f} Pa\n"
mssg += f"\t\t\t\t\t-temperature: {temperature:f} Celsius\n"
mssg += f"\t\t\t\t\t-relatice humidity: {rel_humidity:f} perc.\n"
mssg += f"\t\t\t\t\t-central wavelength: {wlength:f} nm"
self.logger.info(f"set atmospheric parameters at observatory location: {mssg}")
self.has_atmo = True

def get_alt_az(self, obstime=None):
Expand Down Expand Up @@ -179,7 +176,7 @@ def compute_sun_moon(self, trange, which="sun", dt_min=5):
skypos = get_moon(times).transform_to(obs_altaz)
else:
raise ValueError(
"compute_sun_moon accepts either 'sun' or 'moon'. Got %s" % (which)
f"compute_sun_moon accepts either 'sun' or 'moon'. Got {which}"
)
end = time.time()
self.logger.debug(
Expand Down Expand Up @@ -288,12 +285,14 @@ def compute_visibility(
self.logger.info(
f"computing visibility of source at (ra: {ra:f}, dec: {dec:f}) from observatory {self.name}"
)
mssg = "\t\t\t\t\t-Time resolution: %.2f min\n" % dt_min
mssg += "\t\t\t\t\t-Airmass limit: %.2f\n" % airmass_th
mssg += "\t\t\t\t\t-Sun altitude: %.2f deg" % sun_alt_th
mssg = f"\t\t\t\t\t-Time resolution: {dt_min:.2f} min\n"
mssg += f"\t\t\t\t\t-Airmass limit: {airmass_th:.2f}\n"
mssg += f"\t\t\t\t\t-Sun altitude: {sun_alt_th:.2f} deg"
if min_moon_dist is not None:
mssg += "\n\t\t\t\t\t-Moon distance: %.2f deg" % min_moon_dist
self.logger.info("using visibility constraints:\n%s" % mssg)
mssg += (
f"\n\t\t\t\t\t-Moon distance: {min_moon_dist:%.2f} deg" % min_moon_dist
)
self.logger.info(f"using visibility constraints:\n{mssg}")

# find out the array of dark times
dark_times, dark_mask = self.get_dark_times(
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/HealpixPathSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : Ampel-ZTF/ampel/ztf/alert/HealpixPathSupplier.py
# License : BSD-3-Clause
# Author : Marcus Fenner <[email protected]>
Expand Down
8 changes: 3 additions & 5 deletions ampel/ztf/alert/PhotoAlertPlotter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/PhotoAlertPlotter.py
# Author: valery brinnel <[email protected]>
# Date: 23.01.2018
Expand Down Expand Up @@ -101,8 +100,7 @@ def __init__(
os.makedirs(plot_dir)
self.plot_dir = plot_dir
self.logger.info(
"Initialized PhotoAlertPlotter in bash-mode. Plots will be saved to %s."
% self.plot_dir
f"Initialized PhotoAlertPlotter in bash-mode. Plots will be saved to {self.plot_dir}."
)
self.base_plot_name_tmpl = plot_name_tmpl

Expand All @@ -115,7 +113,7 @@ def save_current_plot(
fig = plt.gcf()
fig.savefig(fname, **kwargs)
plt.close(fig)
self.logger.info("current figure saved to %s" % fname)
self.logger.info(f"current figure saved to {fname}")

def exit(self, alert: AmpelAlertProtocol, fine_name_tag, ax_given, ax, **kwargs):
"""
Expand Down Expand Up @@ -215,7 +213,7 @@ def plot_lc(

ax.invert_yaxis()
for ifilter in [1, 2, 3]:
label = "magpsf %s" % self.__class__.filter_names[ifilter - 1]
label = f"magpsf {self.__class__.filter_names[ifilter - 1]}"
color = self.__class__.pp_colors[ifilter - 1]

# plot detctecions
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZTFFPbotForcedPhotometryAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : Ampel-ZTF/ampel/ztf/alert/ZTFFPbotForcedPhotometryAlertSupplier.py
# License : BSD-3-Clause
# Author : jno <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZTFForcedPhotometryAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZTFForcedPhotometryAlertSupplier.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
13 changes: 4 additions & 9 deletions ampel/ztf/alert/ZTFGeneralActiveAlertRegister.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZTFGeneralActiveAlertRegister.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down Expand Up @@ -56,16 +55,12 @@ def __init__(self, **kwargs) -> None: # type: ignore[override]

def file(self, alert: AmpelAlertProtocol, filter_res: int = 0) -> None:
alid = alert.id
if alid > self.alert_max:
self.alert_max = alid
if alid < self.alert_min:
self.alert_min = alid
self.alert_max = max(alid, self.alert_max)
self.alert_min = min(alid, self.alert_min)

sid = alert.stock
if sid > self.stock_max: # type: ignore[operator]
self.stock_max = sid # type: ignore[assignment]
if sid < self.stock_min: # type: ignore[operator]
self.stock_min = sid # type: ignore[assignment]
self.stock_max = max(sid, self.stock_max) # type: ignore[assignment]
self.stock_min = min(sid, self.stock_min) # type: ignore[assignment]

if (sid & 15) not in self.ztf_years: # type: ignore[operator]
self.ztf_years.add(sid & 15) # type: ignore[operator]
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZTFGeneralAlertRegister.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZTFGeneralAlertRegister.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZTFIPACForcedPhotometryAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZTFIPACForcedPhotometryAlertSupplier.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZiAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZiAlertSupplier.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZiHealpixAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : Ampel-ZTF/ampel/ztf/alert/ZiHealpixAlertSupplier.py
# License : BSD-3-Clause
# Author : Marcus Fenner <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/ZiTaggedAlertSupplier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/alert/ZiTaggedAlertSupplier.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/alert/load/ZTFHealpixAlertLoader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : Ampel-ZTF/ampel/ztf/alert/load/ZTFHealpixAlertLoader.py
# License : BSD-3-Clause
# Author : Marcus Fenner <[email protected]>
Expand Down
21 changes: 13 additions & 8 deletions ampel/ztf/base/CatalogMatchFilter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/base/CatalogMatchFilter.py
# License: BSD-3-Clause
# Author: Jakob van Santen <[email protected]>
Expand Down Expand Up @@ -42,12 +41,18 @@ class CatalogMatchFilter(CatalogMatchUnit, AbsAlertFilter):
"""

min_ndet: int
accept: None | CatalogMatchRequest | AnyOf[CatalogMatchRequest] | AllOf[
CatalogMatchRequest
]
reject: None | CatalogMatchRequest | AnyOf[CatalogMatchRequest] | AllOf[
CatalogMatchRequest
]
accept: (
None
| CatalogMatchRequest
| AnyOf[CatalogMatchRequest]
| AllOf[CatalogMatchRequest]
)
reject: (
None
| CatalogMatchRequest
| AnyOf[CatalogMatchRequest]
| AllOf[CatalogMatchRequest]
)

# TODO: cache catalog lookups if deeply nested models ever become a thing
def _evaluate_match(
Expand Down Expand Up @@ -106,6 +111,6 @@ def process(self, alert: AmpelAlertProtocol) -> bool:
dec = latest["dec"]
if self.accept and not self._evaluate_match(ra, dec, self.accept):
return False
if self.reject and self._evaluate_match(ra, dec, self.reject):
if self.reject and self._evaluate_match(ra, dec, self.reject): # noqa: SIM103
return False
return True
10 changes: 3 additions & 7 deletions ampel/ztf/base/CatalogMatchUnit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/base/CatalogMatchUnit.py
# License: BSD-3-Clause
# Author: Jakob van Santen <[email protected]>
Expand Down Expand Up @@ -94,8 +93,7 @@ def _cone_search(
ra: float,
dec: float,
catalogs: Sequence[ConeSearchRequest],
) -> list[bool]:
...
) -> list[bool]: ...

@overload
def _cone_search(
Expand All @@ -104,8 +102,7 @@ def _cone_search(
ra: float,
dec: float,
catalogs: Sequence[ConeSearchRequest],
) -> list[None | CatalogItem]:
...
) -> list[None | CatalogItem]: ...

@overload
def _cone_search(
Expand All @@ -114,8 +111,7 @@ def _cone_search(
ra: float,
dec: float,
catalogs: Sequence[ConeSearchRequest],
) -> list[None | list[CatalogItem]]:
...
) -> list[None | list[CatalogItem]]: ...

@backoff.on_exception(
backoff.expo,
Expand Down
3 changes: 1 addition & 2 deletions ampel/ztf/dev/DevAlertConsumer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/dev/DevAlertConsumer.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down Expand Up @@ -65,7 +64,7 @@ def get_rejected_alerts(self):

def process_tar(self, tar_file_path, tar_mode="r:gz", iter_max=5000, iter_offset=0):
"""For each alert: load, filter, ingest"""
self.tar_file = tarfile.open(tar_file_path, mode=tar_mode)
self.tar_file = tarfile.open(tar_file_path, mode=tar_mode) # noqa: SIM115
return self._run(
self.tar_file, self._unpack, iter_max=iter_max, iter_offset=iter_offset
)
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/dev/DevSkyPortalClient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/dev/DevSkyPortalClient.py
# Author: Jakob van Santen <[email protected]>
# Date: 16.09.2020
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/dev/ZTFAlert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/dev/ZTFAlert.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/ingest/ZiCompilerOptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/ingest/ZiCompilerOptions.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/ingest/ZiDataPointShaper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/ingest/ZiDataPointShaper.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/ingest/ZiMongoMuxer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/ingest/ZiMongoMuxer.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion ampel/ztf/ingest/tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/ingest/tags.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down
13 changes: 4 additions & 9 deletions ampel/ztf/legacy_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-ZTF/ampel/ztf/legacy_utils.py
# License: BSD-3-Clause
# Author: valery brinnel <[email protected]>
Expand Down Expand Up @@ -69,13 +68,11 @@


@overload
def to_ampel_id(ztf_id: str) -> int:
...
def to_ampel_id(ztf_id: str) -> int: ...


@overload
def to_ampel_id(ztf_id: list[str] | tuple[str, ...]) -> list[int]:
...
def to_ampel_id(ztf_id: list[str] | tuple[str, ...]) -> list[int]: ...


def to_ampel_id(ztf_id: str | list[str] | tuple[str, ...]) -> int | list[int]:
Expand All @@ -102,13 +99,11 @@ def to_ampel_id(ztf_id: str | list[str] | tuple[str, ...]) -> int | list[int]:


@overload
def to_ztf_id(ampel_id: int) -> str:
...
def to_ztf_id(ampel_id: int) -> str: ...


@overload
def to_ztf_id(ampel_id: list[int] | tuple[int, ...]) -> list[str]:
...
def to_ztf_id(ampel_id: list[int] | tuple[int, ...]) -> list[str]: ...


def to_ztf_id(ampel_id: int | list[int] | tuple[int, ...]) -> str | list[str]:
Expand Down
Loading