Skip to content

Commit

Permalink
Merge pull request #2416 from cta-observatory/ruff_pre_commit
Browse files Browse the repository at this point in the history
Use ruff for linting
  • Loading branch information
kosack authored Mar 1, 2024
2 parents eb43957 + ad078e2 commit 8f71cce
Show file tree
Hide file tree
Showing 152 changed files with 351 additions and 417 deletions.
1 change: 0 additions & 1 deletion .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ engines:
pyflakes:
disable:
- F999

3 changes: 3 additions & 0 deletions .codespell-ignores
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chec
usera
nd
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A clear and concise description of what the bug is.
Steps to reproduce the behavior:
1.
2.
3.
3.

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Check for news fragment
if: ${{ ! contains( github.event.pull_request.labels.*.name, 'no-changelog-needed')}}
uses: andstor/file-existence-action@v3
with:
with:
files: ${{ env.FRAGMENT_NAME }}
fail: true
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
cache-downloads: true

- name: Python setup
if: matrix.install-method == 'pip' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false
if: matrix.install-method == 'pip' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
# branches to consider in the event; optional, defaults to all
branches:
- main


jobs:
update_release_draft:
Expand Down
2 changes: 1 addition & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Alison Mitchell <alison.mitchell@mpi-hd.mpg.de> Alison Mitchell <amitchell@eduro
Alison Mitchell <alison.mitchell@mpi-hd.mpg.de> Alison Mitchell <amitchell@wlan-3-83.mpi-hd.mpg.de>

Daniel Nieto <nieto@gae.ucm.es> nieto@talos <nieto@gae.ucm.es>
Daniel Parsons <dparsons@lfs2.mpi-hd.mpg.de> Dan Parsons <parsonsrd@gmail.com>
Daniel Parsons <dparsons@lfs2.mpi-hd.mpg.de> Dan Parsons <parsonsrd@gmail.com>
Daniel Parsons <dparsons@lfs2.mpi-hd.mpg.de> parsonsrd <parsonsrd@gmail.com>

Andrés Baquero <andres.baquero@cta-consortium.org> Andres-Baquerp <52699174+andres-baquero@users.noreply.github.com>
Expand Down
33 changes: 20 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
repos:
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html#integration-with-pre-commit
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 22.6.0
- id: trailing-whitespace
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: black-jupyter
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html?highlight=other%20tools#flake8
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
hooks:
- id: flake8
args: [--max-line-length=88, "--extend-ignore=E203,E712"]
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ exclude-protected=_asdict,
_replace,
_source,
_make,
_v_attrs,
_v_attrs,
_v_attrnames

# List of valid names for the first argument in a class method.
Expand Down
38 changes: 19 additions & 19 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ API Changes
-----------

- The ``ctapipe-dump-triggers`` tool was removed, since it wrote a custom data format
not compatble with e.g. the output of the ``DataWriter`` and ``ctapipe-process``.
not compatible with e.g. the output of the ``DataWriter`` and ``ctapipe-process``.
If you only want to store trigger and simulation information from simulated / DL0
input files into the ctapipe format HDF5 files, you can now use
``ctapipe-process -i <input> -o <output> --no-write-parameters``. [`#2375 <https://github.com/cta-observatory/ctapipe/pull/2375>`__]

- Change the fill value for invalid telescope ids in ``SubarrayDescription.tel_index_array``
from ``-1`` to ``np.iinfo(int).minval`` to prevent ``-1`` being used as an index resulting in the last element being used for invalid telescope ids. [`#2376 <https://github.com/cta-observatory/ctapipe/pull/2376>`__]

- Remove ``EventSource.from_config``, simply use ``EventSource(config=config)`` or
- Remove ``EventSource.from_config``, simply use ``EventSource(config=config)`` or
``EventSource(parent=parent)``. [`#2384 <https://github.com/cta-observatory/ctapipe/pull/2384>`__]


Expand Down Expand Up @@ -145,7 +145,7 @@ Bug Fixes
New Features
------------

- Add ``SubarrayDescription.mulitplicity`` method that can compute
- Add ``SubarrayDescription.multiplicity`` method that can compute
telescope multiplicity for a given telescope boolean mask, either for
all telescope or a given telescope type.

Expand Down Expand Up @@ -219,25 +219,25 @@ ctapipe v0.18.0 (2023-02-09)
API Changes
-----------

- ctapipe now uses entry points for plugin discovery. ``EventSource`` implementations
- ctapipe now uses entry points for plugin discovery. ``EventSource`` implementations
now need to advertise a ``ctapipe_io`` entry point, to be discovered by ctapipe.
Additionally, ctapipe now includes preliminary support for discovering ``Reconstructor``
implementations via the ``ctapipe_reco`` entry_point. [`#2101 <https://github.com/cta-observatory/ctapipe/pull/2101>`__]

- Migrate muon analysis into the ``ctapipe-process`` tool:

1. The former ``muon_reconstruction`` tool is dropped and all functionalities are transferred
1. The former ``muon_reconstruction`` tool is dropped and all functionalities are transferred
into the ``ctapipe-process`` tool.

2. The ``process`` tool now has a ``write_muon_parameters`` flag which defaults to ``false``.
Muons are only analyzed and written if the flag is set. Analyzing muons requires DL1 image
parameters, so they are computed in case they are not available from the input even
Muons are only analyzed and written if the flag is set. Analyzing muons requires DL1 image
parameters, so they are computed in case they are not available from the input even
if the user did not explicitly ask for the computation of image parameters.

3. Two instances of ``QualityQuery``, ``MuonProcessor.ImageParameterQuery`` and ``MuonProcessor.RingQuery``
are added to the muon analysis to either preselect images according to image parameters and
to select images according to the initial, geometrical ring fit for further processing.
Deselected events or those where the muon analysis fails are being returned and written
3. Two instances of ``QualityQuery``, ``MuonProcessor.ImageParameterQuery`` and ``MuonProcessor.RingQuery``
are added to the muon analysis to either preselect images according to image parameters and
to select images according to the initial, geometrical ring fit for further processing.
Deselected events or those where the muon analysis fails are being returned and written
filled with invalid value markers instead of being ignored.
Base configure options for the muon analysis were added to the ``base_config.yaml``.

Expand Down Expand Up @@ -269,7 +269,7 @@ API Changes
New Features
------------

- Implement Components and Tools to perform training and application of
- Implement Components and Tools to perform training and application of
machine learning models based on scikit-learn.

Four new tools are implemented:
Expand Down Expand Up @@ -344,8 +344,8 @@ New Features
fine-grained control which information should be included in the output file
and for appending to existing output files. [`#2179 <https://github.com/cta-observatory/ctapipe/pull/2179>`__]

- ``CameraDisplay.overlay_coordinate`` can now be used to
plot coordinates into the camera display, e.g. to show
- ``CameraDisplay.overlay_coordinate`` can now be used to
plot coordinates into the camera display, e.g. to show
the source position or the position of stars in the FoV. [`#2203 <https://github.com/cta-observatory/ctapipe/pull/2203>`__]


Expand Down Expand Up @@ -469,15 +469,15 @@ Some Major changes since last release:
v0.5.3 (unreleased)
===================

* Major speed improvements to calibration code, particuarly
* Major speed improvements to calibration code, particularly
``NeighborPeakIntegrator`` (Jason Watson, #490), which now uses some
compiled c-code for speed.

* ``GeometryConverter`` now works for all cameras (Tino Michael, #)

* Plotting improvements when overlays are used (Max Noe, #489)
* Plotting improvements when overlays are used (MaxNoe, #489)

* Fixes to coordinate ``PlanarRepresentation`` (Max Noe, #506)
* Fixes to coordinate ``PlanarRepresentation`` (MaxNoe, #506)

* HDF5 output for charge resolution calculation (Jason Watons, #488)

Expand All @@ -490,7 +490,7 @@ v0.5.3 (unreleased)
v0.5.2 (2017-07-31)
===================

* improvements to ``core.Container`` (Max Noe)
* improvements to ``core.Container`` (MaxNoe)

* ``TableWriter`` correctly handles units and metadata

Expand Down Expand Up @@ -540,7 +540,7 @@ v0.5.1 (2016-07-20)
* Improvements to ``flow`` framework (Jean Jacquemier)

* Travis CI now builds automatically for multiply python versions and
uploads lates documentation
uploads latest documentation

* use Lanscape.io for code quality

Expand Down
12 changes: 6 additions & 6 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Fixed error when taking log of quantity
* Fixed import problem in hillas intersection test
* minor cleanup of bug
* Inproved documentation for functions guessing the shower maximum given the reconstructed energy
* Improved documentation for functions guessing the shower maximum given the reconstructed energy
* Significantly improved documentation for the ImPACT code
* solving migrad nan issue and change shower max to return depth (not height)
* register outputs from ctapipe-dump-instrument with provenance
Expand All @@ -69,7 +69,7 @@
* Updated viewers to allow backgrounds to be added more easily, updated scaling factors on the Hillas parameters
* Added low gain channel
* Changed scaling values
* Removed unused funtions and added optional fit priors
* Removed unused functions and added optional fit priors
* Added option to use LM minimiser
* Fixed camera rotation problems and added functions to draw likelihood surfaces
* Allowed selection of minimiser to be used for ImPACt
Expand All @@ -84,19 +84,19 @@
* Added comments
* Changed structure such that set parameters function is not need
* Changed structure such that set parameters function is not need
* Added tool for perfomring hillas based reconstruction
* Fixed energy reconstruction and added ouput into the correct format
* Added tool for performing hillas based reconstruction
* Fixed energy reconstruction and added output into the correct format
* Created tool for reco using Hillas parameters
* Added MVA based energy reconstruction algorithm
* Fixed incorrect calculation of impact distance when getting the training parameters
* Added Tool to output Hillas parameters into FITS files
* Code cleanup and addtion of command line options
* Code cleanup and addition of command line options
* Added cut to prevent 0 width events
* Switched to use of FITS templates and fixed use of depth tables
* Store system as class member
* Fixed incorrect inversion of axes
* renamed to work correctly with new ctapipe version
* Fixed mis labelled axes
* Fixed mislabelled axes
* Added ImPACT reconstruction tool
* Added fix for pixel neighbour list
* Added Xmax reconstruction
Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/autosummary/base.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends "autosummary_core/base.rst" %}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
2 changes: 1 addition & 1 deletion docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends "autosummary_core/class.rst" %}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
2 changes: 1 addition & 1 deletion docs/_templates/autosummary/module.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% extends "autosummary_core/module.rst" %}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
{# The template this is inherited from is in astropy/sphinx/ext/templates/autosummary_core. If you want to modify this template, it is strongly recommended that you still inherit from the astropy template. #}
2 changes: 1 addition & 1 deletion docs/api-reference/coordinates/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Getting Started
===============

The coordinate library defines a set of *frames*,
which represent different coordinate reprentations.
which represent different coordinate representations.
Coordinates should be described using an ``astropy.coordinates.SkyCoord`` in the appropriate frame.

The following special frames are defined for CTA:
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/core/corediagram.dot
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ digraph Core {
Component_1 -> Container_1
Container_1 -> Component_2

}
}
2 changes: 1 addition & 1 deletion docs/api-reference/core/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ to provide a common interface and to make use of the configuration system.
For details about creating command-line tools, see :ref:`tools`

The following shows the conceptual difference between `Tools <Tool>`_ and
`Components <Compenent>`_ with overall pipelines and stages.
`Components <Component>`_ with overall pipelines and stages.
Serialization and Deserialization are simply specialized Components that perform data access.

.. image:: tool-component.png
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/image/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Imaging (`~ctapipe.image`)

.. currentmodule:: ctapipe.image

`ctapipe.image` contains all algortihms that operate on Cherenkov camera images.
`ctapipe.image` contains all algorithms that operate on Cherenkov camera images.

A *Cherenkov image* is defined as two pieces of data:

Expand Down
8 changes: 4 additions & 4 deletions docs/api-reference/instrument/config.dot
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ digraph config {


ObsConfig [fillcolor=dodgerblue3, fontcolor=white, style=filled]
SubarrayConfig [fillcolor=dodgerblue3, fontcolor=white, style=filled]
SubarrayConfig [fillcolor=dodgerblue3, fontcolor=white, style=filled]
ArrayTriggerConfig [fillcolor=goldenrod4,
fontcolor=white, style=filled]
TelescopeTriggerConfig [fillcolor=goldenrod4,
fontcolor=white, style=filled]

ObsConfig -> SubarrayConfig [label="obs_id"];
ObsConfig -> ArrayTriggerConfig [label="run_type"];
ArrayTriggerConfig -> TelescopeTriggerConfig [label="run_type,\ntel_id"];
SubarrayConfig -> ArrayConfig [label="site_id,\nversion"]
ArrayTriggerConfig -> TelescopeTriggerConfig [label="run_type,\ntel_id"];
SubarrayConfig -> ArrayConfig [label="site_id,\nversion"]
ArrayConfig -> TelescopeConfig [label="tel_id"];
TelescopeConfig -> CameraConfig [label="tel_id"];
TelescopeConfig -> OpticsConfig [label="tel_id"];


}
}
6 changes: 3 additions & 3 deletions docs/api-reference/io/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Container Classes
=================

Event data that is intended to be read or written from files is stored
in subclasses of `~ctapipe.core.Container`, the structre of which is
in subclasses of `~ctapipe.core.Container`, the structure of which is
defined in the `~ctapipe.containers` module (See reference API below). Each
element in the container is a `~ctapipe.core.Field`, containing the
default value, a description, and default unit if necessary. The
Expand Down Expand Up @@ -156,7 +156,7 @@ In addition to using an `EventSource` to read R0-DL1 data files, one can also ac
`~ctapipe.io.TableLoader` is a a convenient way to load and join together the
tables in a ctapipe output file into one or more high-level tables useful for analysis.
Which information is read and joined is controlled by the TableLoader's configuration
options.
options.

By default, TableLoader will read the dl1 parameters for each telescope
into one big table, joining the simulation information if available:
Expand Down Expand Up @@ -187,7 +187,7 @@ You can also load telescope events for specific selections of telescopes:
Loading the DL1 image data for telescopes with different numbers of pixels
does not work as astropy tables do not support heterogenous data in columns.
does not work as astropy tables do not support heterogeneous data in columns.
In this case, use:

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/reco/ImPACT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ of the brightest 3 camera pixels). The minimisation can then be performed over a
modification factor to the estimated Xmax, greatly reducing the time taken for the fit
procedure.

Fitting is performed using the `iminuit <https://iminuit.readthedocs.io/en/stable/>`_
Fitting is performed using the `iminuit <https://iminuit.readthedocs.io/en/stable/>`_
package (a wrapper around the MINUIT minimiser), providing a fast and reliable minimisation.
The algorithm finds a function minimum in the majority of cases, typically taking
around 500 function calls to reach the minimum.
Expand Down
2 changes: 1 addition & 1 deletion docs/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ References
.. [lts_regression] P. J. Rousseeuw, K. van Driessen, "Computing LTS Regression for Large Data Sets",
Data Mining and Knowledge Discovery, 12, 29-45, DOI: 10.1007/s10618-005-0024-4
.. [hillas_uncertainties] W. Wittek, "Image Parameters", MAGIC-TDAS internal note 02-03, (2002).
.. [hillas_uncertainties] W. Wittek, "Image Parameters", MAGIC-TDAS internal note 02-03, (2002).
.. [cta_sb_ob] Oya et al, Scheduling Block Data Model Specification, CTA-SPE-COM-000000-0003, Issue 1, Rev. c
Expand Down
2 changes: 1 addition & 1 deletion docs/changes/2411.features.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Add option ``override_obs_id`` to ``SimTelEventSource`` which allows
assigning new, unique ``obs_ids`` in case productions re-use CORSIKA run
assigning new, unique ``obs_ids`` in case productions reuse CORSIKA run
numbers.
2 changes: 1 addition & 1 deletion docs/changes/2414.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Add the example config for ctapipe-train-disp-reconstructor
Add the example config for ctapipe-train-disp-reconstructor
to the list of configs generated by ctapipe-quickstart.
2 changes: 1 addition & 1 deletion docs/changes/2421.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Remove warnings about missing R1 or DL0 data when using the CameraCalibrator.
These were previously emitted directly as python warnings and did not use the
These were previously emitted directly as python warnings and did not use the
component logging system, which they now do.
As we do not actually expect R1 to be present it was also moved down to
debug level.
Loading

0 comments on commit 8f71cce

Please sign in to comment.