Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 25, 2023
1 parent 922a9a2 commit 42a1af1
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 100 deletions.
2 changes: 1 addition & 1 deletion docs/guide/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tutorial
========
========
10 changes: 5 additions & 5 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
black>=22.10.0
flake8>=3.9.2
tox>=3.24.3
pytest>=6.2.5
pytest-cov>=2.12.1
mypy>=0.910
black>=22.10.0
pre-commit>=2.1.0
openpyxl>=3.0.10
pre-commit>=2.1.0
pytest>=6.2.5
pytest-cov>=2.12.1
tox>=3.24.3
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import annotations

from setuptools import setup

if __name__ == "__main__":
if __name__ == '__main__':
setup()
3 changes: 1 addition & 2 deletions src/femto/pgmcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

@dataclasses.dataclass(repr=False)
class PGMCompiler:

filename: str #: File name of the PGM file.
laser: str = 'PHAROS' #: Name of the laser source.
export_dir: str = '' #: Directory in which the G-Code files will be exported.
Expand Down Expand Up @@ -745,7 +744,7 @@ def write(self, points: npt.NDArray[np.float32]) -> None:

# Convert points if G-Code commands
args = [self._format_args(x, y, z, f) for (x, y, z, f) in zip(x_gc, y_gc, z_gc, f_gc)]
for (arg, s) in itertools.zip_longest(args, s_gc):
for arg, s in itertools.zip_longest(args, s_gc):
if s == 0 and self._shutter_on is True:
self.instruction('\n')
self.dwell(self.short_pause)
Expand Down
85 changes: 31 additions & 54 deletions src/femto/spreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
from __future__ import annotations

import time

from xlsxwriter import Workbook

from dataclasses import dataclass
from pathlib import Path

from femto import __file__ as fpath
import numpy as np

from types import TracebackType
from femto.waveguide import Waveguide
from femto.marker import Marker
from femto.helpers import flatten
from femto.writer import WaveguideWriter, MarkerWriter

from typing import Any
from typing import cast
from typing import Union
from typing import Any
import nptyping as nptyp

from dataclasses import dataclass

import femto.device
import nptyping as nptyp
import numpy as np
from femto import __file__ as fpath
from femto.helpers import flatten
from femto.marker import Marker
from femto.waveguide import Waveguide
from femto.writer import MarkerWriter
from femto.writer import WaveguideWriter
from xlsxwriter import Workbook


def generate_all_cols_data() -> nptyp.NDArray[
Any,
nptyp.Structure["tagname: Str, fullname: Str, unit: Str, width: Int, format: Str"],
]:
def generate_all_cols_data() -> (
nptyp.NDArray[
Any,
nptyp.Structure[tagname:Str, fullname:Str, unit:Str, width:Int, format:Str],
]
):
"""
Create the available columns array from a file.
Expand Down Expand Up @@ -81,7 +78,6 @@ def get_path(key, d, path=None, prev_k=None):
nothing = True
if hasattr(d, 'items'):
for k, v in d.items():

if k == key:
prev_k.append(k)
path.append(' '.join(prev_k))
Expand Down Expand Up @@ -113,7 +109,7 @@ class Parameter:
"""Class that handles preamble parameters."""

n: str # Full name
v: str = "" # Value
v: str = '' # Value
loc: tuple[int, int] = (0, 0) # Location (1-indexing)
sz: tuple[int, int] = (0, 0) # Size (for merged cells)
fmt: str = 'parval' # Format
Expand All @@ -135,10 +131,10 @@ class Spreadsheet:
"""Class representing the spreadsheet with all entities to fabricate."""

device: femto.device.Device | None = None
columns_names: str = ""
book_name: str | Path = "my_fabrication.xlsx"
sheet_name: str = "Fabrication"
font_name: str = "DejaVu Sans Mono"
columns_names: str = ''
book_name: str | Path = 'my_fabrication.xlsx'
sheet_name: str = 'Fabrication'
font_name: str = 'DejaVu Sans Mono'
font_size: int = 11
suppr_redd_cols: bool = True
static_preamble: bool = False
Expand Down Expand Up @@ -203,12 +199,10 @@ def __post_init__(
self.columns_names = scn
self.suppr_redd_cols = True
print(
(
'Columns_names not given in spreadsheet initialization.'
f' Will proceed with standard columns names \'{scn}\' '
'and activate the suppr_redd_cols flag to deal with '
'reddundant columns.'
)
'Columns_names not given in spreadsheet initialization.'
f' Will proceed with standard columns names \'{scn}\' '
'and activate the suppr_redd_cols flag to deal with '
'reddundant columns.'
)

if 'name' not in self.columns_names:
Expand All @@ -223,7 +217,6 @@ def __post_init__(

ac = generate_all_cols_data()
if self.new_columns:

for elem in self.new_columns:
tns = ac['tagname']
if elem[0] in tns:
Expand Down Expand Up @@ -370,7 +363,7 @@ def _write_saints_list(self, column: int = 156) -> None:
None.
"""
with open(Path(fpath).parent / 'utils' / 'saints_data.txt', 'r') as f:
with open(Path(fpath).parent / 'utils' / 'saints_data.txt') as f:
for i in range(367):
s = f.readline().strip('\n')
# print(f'writing day {i}\t{s}')
Expand Down Expand Up @@ -412,10 +405,7 @@ def _dtype(self, tagname):

return dt

def _get_structure_list(
self, str_list: list[Union[Waveguide, Marker]] | None = None
) -> list[Union[Waveguide, Marker]]:

def _get_structure_list(self, str_list: list[Waveguide | Marker] | None = None) -> list[Waveguide | Marker]:
assert isinstance(self.device, femto.device.Device)

if str_list is None:
Expand Down Expand Up @@ -514,11 +504,9 @@ def _build_struct_list(
table_lines = np.zeros(n_structures, dtype=dtype)

for i, ent in enumerate(structures):

sline = []

for t in tagnames:

if t in 'yin yout':
item = coords(ent)[type(ent)][t]
else:
Expand All @@ -536,7 +524,6 @@ def _build_struct_list(
ignored_fields = []

for i, t in enumerate(tagnames):

if t.lower() == 'name':
# the name of the structure is always present
keep.append(i)
Expand All @@ -546,7 +533,7 @@ def _build_struct_list(
ignored_fields.append(t)
continue

if np.all(table_lines[t] == table_lines[t][0]) and suppr_redd_cols and table_lines[t][0] != "":
if np.all(table_lines[t] == table_lines[t][0]) and suppr_redd_cols and table_lines[t][0] != '':
# eliminate reddundancies if explicitly requested
ignored_fields.append(t)

Expand All @@ -570,10 +557,8 @@ def _build_struct_list(
if ignored_fields and verbose:
fields_left_out = ', '.join(ignored_fields)
print(
(
f'For all entities, the fields {fields_left_out} were not '
'defined, so they will not be shown as table columns.'
)
f'For all entities, the fields {fields_left_out} were not '
'defined, so they will not be shown as table columns.'
)

self.keep = keep
Expand All @@ -594,7 +579,6 @@ def _prepare_columns(self, columns=None) -> None:
self.columns_data = columns

for i, col in enumerate(columns):

fmt = col['format']
w = col['width']

Expand Down Expand Up @@ -643,7 +627,6 @@ def _create_numerical_format(self, fmt_string) -> None:
self.formats[fmt_string] = wb.add_format({'align': 'center', 'valign': 'vcenter', 'num_format': fmt_string})

def _fill_spreadsheet(self):

self.struct_data = self.struct_data[self.columns_data['tagname']]

self.ws.set_row(7, 50)
Expand All @@ -654,7 +637,6 @@ def _fill_spreadsheet(self):
self._add_line((7, 5), titles, fmt='title')

for i, sdata in enumerate(self.struct_data):

sdata = [
s
if (isinstance(s, (np.int64, np.float64)) and s < 1e5) or (not isinstance(s, (np.int64, np.float64)))
Expand All @@ -669,7 +651,6 @@ def _fill_spreadsheet(self):
)

def _write_header(self) -> None:

ws = self.ws

ws.set_column(1, 1, 15)
Expand All @@ -686,7 +667,6 @@ def _write_header(self) -> None:
ws.merge_range(2, 3, 2, nc_f + 4, self.description, self.formats['parval'])

def _write_preamble(self) -> None:

ws = self.ws

row = 8
Expand All @@ -703,7 +683,6 @@ def _write_preamble(self) -> None:

for sg, parameters in self.preamble.dict.items():
for tname, p in parameters.items():

if np.any(p.sz):
ws.merge_range(*p.loc, *(p.loc + p.sz), '', self.formats['parname'])

Expand Down Expand Up @@ -768,7 +747,6 @@ def _add_line(


def main() -> None:

import numpy as np
from itertools import product
from femto.device import Device
Expand Down Expand Up @@ -809,7 +787,6 @@ def main() -> None:
all_fabb = Device(**PARS_GC)

for i_guide, (p, v, ns) in enumerate(product(powers, speeds, scans)):

start_pt = [LS, 2 + i_guide * 0.08, PARS_WG.depth]
wg = Waveguide(**PARS_WG, speed=v, scan=ns)
# wg.power = p # Can NOT be added inside of the arguments of Waveguide
Expand Down
2 changes: 1 addition & 1 deletion src/femto/trench.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def main() -> None:
# b = T._trench_list[0]
# b = T.trenchbed[0]
for tr in T._trench_list:
for (x, y) in tr.toolpath():
for x, y in tr.toolpath():
plt.plot(x, y)

plt.axis('equal')
Expand Down
4 changes: 2 additions & 2 deletions src/femto/utils/spreadsheet_columns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ speed, Speed, mm/s, 6, 0.0
scan, Scans, , 5, 0
depth, Depth, mm, 8, 0.000
radius, R, mm, 5, 0.00
int_dist, Cdist, um, 8, 0.0000
int_dist, Cdist, um, 8, 0.0000
wl, λ, um, 8, 0.000
int_length, Clength, mm, 8, 0.000
int_length, Clength, mm, 8, 0.000
arm_length, Alength, mm, 8, 0.000
yin, Yin, mm, 8, 0.0000
yout, Yout, mm, 8, 0.0000
Expand Down
3 changes: 1 addition & 2 deletions src/femto/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def export_array2d(
]

gcode_instr = []
for (line, dec) in itertools.zip_longest(instr, listcast(forced_deceleration)):
for line, dec in itertools.zip_longest(instr, listcast(forced_deceleration)):
if bool(dec):
gcode_instr.append(f'G9 G1 {line}\n')
else:
Expand Down Expand Up @@ -810,7 +810,6 @@ def _export_trench_column(self, column: UTrenchColumn, column_path: pathlib.Path

# Bed script
for i, bed_block in enumerate(column.trenchbed):

x_bed_block = np.array([])
y_bed_block = np.array([])
f_decel = np.array([])
Expand Down
3 changes: 1 addition & 2 deletions tests/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def list_wg() -> list[Waveguide]:
def list_mk() -> list[Marker]:
PARAM_MK = dotdict(scan=1, speed=2, speed_pos=5, speed_closed=5, depth=0.000, lx=1, ly=1)
markers = []
for (x, y) in zip(range(4, 8), range(3, 7)):
for x, y in zip(range(4, 8), range(3, 7)):
m = Marker(**PARAM_MK)
m.cross([x, y])
markers.append(m)
Expand Down Expand Up @@ -292,7 +292,6 @@ def test_plot3d_save_true(device, list_wg, list_mk, list_tcol) -> None:


def test_device_pgm(device, list_wg, list_mk) -> None:

device.extend(list_wg)
device.extend(list_mk)
device.pgm()
Expand Down
Loading

0 comments on commit 42a1af1

Please sign in to comment.