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

Add linting #6

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
exclude =
.git,
__pycache__,
max-line-length = 115
14 changes: 14 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
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
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args: ["--ignore=E203,W503"]

- repo: https://github.com/timothycrosley/isort
rev: 5.9.3
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Workflows

Repository of workflows for the FXI beamline.

9 changes: 3 additions & 6 deletions end_of_run_workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prefect
from prefect import task, Flow, Parameter
from prefect import Flow, Parameter, task
from prefect.tasks.prefect import create_flow_run


Expand All @@ -15,12 +15,9 @@ def log_completion():
validation_flow = create_flow_run(
flow_name="general-data-validation",
project_name="FXI",
parameters={"beamline_acronym": "fxi" ,"uid": uid}
parameters={"beamline_acronym": "fxi", "uid": uid},
)
export_flow = create_flow_run(
flow_name="export",
project_name="FXI",
parameters={"uid": uid}
flow_name="export", project_name="FXI", parameters={"uid": uid}
)
log_completion(upstream_tasks=[validation_flow, export_flow])

26 changes: 14 additions & 12 deletions export.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import databroker
import datetime
import os
from pathlib import Path

import databroker
import h5py
import numpy as np
import os
import pandas as pd
import prefect

from pathlib import Path
from PIL import Image
from prefect import task, Flow, Parameter
from prefect import Flow, Parameter, task


@task
Expand Down Expand Up @@ -69,9 +69,9 @@ def get_img(run, det="Andor", sli=[]):
"Take in a Header and return a numpy array of detA1 image(s)."
det_name = f"{det}_image"
if len(sli) == 2:
img = np.array(list(run['primary']['data'][det_name])[sli[0] : sli[1]])
img = np.array(list(run["primary"]["data"][det_name])[sli[0] : sli[1]])
else:
img = np.array(list(run['primary']['data'][det_name]))
img = np.array(list(run["primary"]["data"][det_name]))
return np.squeeze(img)


Expand All @@ -92,17 +92,17 @@ def bin_ndarray(ndarray, new_shape=None, operation="mean"):
[262 270 278 286 294]
[342 350 358 366 374]]
"""
if new_shape == None:
if new_shape is None:
s = np.array(ndarray.shape)
s1 = np.int32(s / 2)
new_shape = tuple(s1)
operation = operation.lower()
if not operation in ["sum", "mean"]:
if operation not in ["sum", "mean"]:
raise ValueError("Operation not supported.")
if ndarray.ndim != len(new_shape):
raise ValueError("Shape mismatch: {} -> {}".format(ndarray.shape, new_shape))
compression_pairs = [(d, c // d) for d, c in zip(new_shape, ndarray.shape)]
flattened = [l for p in compression_pairs for l in p]
flattened = [ell for p in compression_pairs for ell in p]
ndarray = ndarray.reshape(flattened)
for i in range(len(new_shape)):
op = getattr(ndarray, operation)
Expand Down Expand Up @@ -727,7 +727,8 @@ def export_raster_2D_2(run, binning=4, filepath="", **kwargs):
y_list[j] * pix * img_sizeY / 1000,
]
pos_file.append(
f"{x_list[i]:3.0f}\t{y_list[j]:3.0f}\t{x_list[i]*pix*img_sizeX/1000:3.3f}\t\t{y_list[j]*pix*img_sizeY/1000:3.3f}\n"
f"{x_list[i]:3.0f}\t{y_list[j]:3.0f}\t{x_list[i]*pix*img_sizeX/1000:3.3f}\t\t"
+ f"{y_list[j]*pix*img_sizeY/1000:3.3f}\n"
)
index = index + 1
s = img_patch.shape
Expand Down Expand Up @@ -804,7 +805,8 @@ def export_raster_2D(run, binning=4, filepath="", **kwargs):
y_list[j] * pix * img_sizeY / 1000,
]
pos_file.append(
f"{x_list[i]:3.0f}\t{y_list[j]:3.0f}\t{x_list[i]*pix*img_sizeX/1000:3.3f}\t\t{y_list[j]*pix*img_sizeY/1000:3.3f}\n"
f"{x_list[i]:3.0f}\t{y_list[j]:3.0f}\t{x_list[i]*pix*img_sizeX/1000:3.3f}\t\t"
+ f"{y_list[j]*pix*img_sizeY/1000:3.3f}\n"
)
index = index + 1
s = img_patch.shape
Expand Down
64 changes: 0 additions & 64 deletions load_scan.py

This file was deleted.

8 changes: 5 additions & 3 deletions print_scanid.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import databroker
import prefect
from prefect import task, Flow
from prefect import Flow, task


@task
def print_scanid():
client = databroker.from_profile("nsls2", username=None)
scan_id = client['fxi'][-1].start['scan_id']
scan_id = client["fxi"][-1].start["scan_id"]
logger = prefect.context.get("logger")
logger.info(f"Scan ID: {scan_id}")


with Flow("scan_id") as flow:
print_scanid()

#flow.register(project_name='TST',
# flow.register(project_name='TST',
# labels=['fxi-2022-2.2'],
# add_default_labels=False,
# set_schedule_active=False)
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.black]
line-length = 88
exclude = '''
(
/(
| \.git
)/
)
'''
Loading