Skip to content

Commit

Permalink
Add T&S pre-commit settings to ts_imsim.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkalmbach committed Nov 7, 2023
1 parent 56936d3 commit b3e5030
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 17 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: ChangelogUpdated
on:
pull_request:
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
branches:
- develop
jobs:
build:
name: Check Actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Changelog check
uses: Zomzog/[email protected]
with:
fileName: doc/versionHistory.rst
checkNotification: Simple
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: lint

on:
- push
- pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Install
run: |
$CONDA/bin/conda install -c lsstts ts-pre-commit-config -y
$CONDA/bin/conda install -c conda-forge pre-commit -y
- name: Run pre commit checks
run: $CONDA/bin/pre-commit run --all
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ config.log
*Lib.py

# Pre-commit configs
.pre-commit-config.yaml
.flake8
.isort.cfg
.mypy.ini

# Built by sconsUtils
Expand All @@ -37,3 +35,4 @@ pytest_session.txt

# MacOS metadata
.DS_Store
.clang-format
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/lsst-ts/pre-commit-xmllint
rev: v1.0.0
hooks:
- id: format-xmllint

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
exclude: conda/meta.yaml|^policy/config/[input|image|output|stamp|opd]
- id: check-xml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
hooks:
- id: ruff
8 changes: 8 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ignore = ["E203", "E226", "E228", "E999", "N802", "N803", "N806", "N812", "N813", "N815", "N816", "N999"]
line-length = 110
exclude = ["__init__.py", "doc/conf.py"]
select = ["E", "F", "N", "W"]
[pycodestyle]
max-doc-length = 79
[pydocstyle]
convention = "numpy"
6 changes: 0 additions & 6 deletions .ts_pre_commit_config.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions doc/versionHistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
Version History
##################

-------------
0.6.1
-------------

* Add T&S pre-commit settings to ts_imsim.

-------------
0.6.0
-------------
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ts/imsim/closedLoopTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def _generate_images(
imsim_config_yaml["output"]["opd"]["file_name"],
)
if os.path.exists(imsimOpdPath):
self.log.info(f"OPD already created, moving to analysis.")
self.log.info("OPD already created, moving to analysis.")
else:
self.log.info(
f"Writing Imsim Configuration file to {imsim_config_path}"
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/ts/imsim/imsimCmpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ def add_config_header(self, obs_metadata: ObsMetadata) -> str:
Header information for ImSim config
"""
header_text = " header:\n"
header_text += f" mjd: *mjd\n"
header_text += " mjd: *mjd\n"
header_text += (
f" observationStartMJD: {obs_metadata.mjd - (15/(60*60*24))}\n"
)
header_text += f" seqnum: *seqnum\n"
header_text += f" band: *band\n"
header_text += " seqnum: *seqnum\n"
header_text += " band: *band\n"
header_text += f" fieldRA: {obs_metadata.ra}\n"
header_text += f" fieldDec: {obs_metadata.dec}\n"
header_text += f" rotTelPos: {obs_metadata.rotator_angle}\n"
Expand Down Expand Up @@ -602,8 +602,8 @@ def _map_opd_to_zk(self, rot_opd_in_deg: float, num_opd: int) -> np.ndarray:
opd_rot = opd.copy()
# Since to rotate the opd we need to substitue the nan values
# for zeros, we need to find the minimum value of the opd
# excluding the nan values. Then after the rotation we will discard
# the values that are smaller than the minimum value.
# excluding the nan values. Then after the rotation we will
# discard the values that are smaller than the minimum value.
# Note that we use order = 0 to avoid interpolation errors.
min_value = np.nanmin(np.abs(opd_rot))
opd_rot[np.isnan(opd_rot)] = 0.0
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/ts/imsim/opdMetrology.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os

import numpy as np
import yaml
from astropy.io import fits
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/ts/imsim/utils/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def __enter__(self) -> None:

def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None:
for key in self._overrides:
# Restore original values, delete or keep as they are based on the original state
# Restore original values, delete or keep as they are
# based on the original state.
if key in self._originals:
os.environ[key] = self._originals[key]
else:
Expand Down

0 comments on commit b3e5030

Please sign in to comment.