Skip to content

Commit

Permalink
Update length scale measurement scripts to use new imageruler (#64)
Browse files Browse the repository at this point in the history
* Use new imageruler (#1)

* Use new imageruler

* Fix eof errors

* Manually install deps

* Fix typo

* Add slow_light_waveguide test

* binarize

* Rename

* Fix binarization

* Report feature size in nm

* Fix eof
  • Loading branch information
mfschubert authored Apr 10, 2024
1 parent c94e6bc commit 2683d5a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 24 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/measure_length_scales.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
pull_request:
push:
branches:
- main
schedule:
- cron: "0 13 * * 1" # Every Monday at 9AM EST

jobs:
measure-length-scales:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install numpy
pip install imageruler
pip install ceviche-challenges
- name: cavity_design
run: |
cd cavity_design
python minimum_lengthscales_run.py
cd ..
- name: Metagrating3D
run: |
cd Metagrating3D
python minimum_lengthscales_run.py
cd ..
- name: RGB_metalens
run: |
cd RGB_metalens
python minimum_lengthscales_run.py
cd ..
- name: slow_light_waveguide
run: |
cd slow_light_waveguide
python minimum_lengthscales_run.py
cd ..
- name: waveguide_mode_converter
run: |
cd waveguide_mode_converter
python run.py designs/converter_generator_circle_6_x47530832_w1_s796.csv
cd ..
17 changes: 10 additions & 7 deletions Metagrating3D/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
file_name = str(file)
if file_name[-3:] == 'csv':
design_pattern = np.loadtxt(path+file_name, delimiter=',')
design_dimension = np.ndim(design_pattern)
if design_pattern.ndim == 1:
design_pattern = design_pattern[:, np.newaxis]
pixel_size = px / design_pattern.shape[0]

if design_dimension == 2: design_size = (px, py)
elif design_dimension == 1: design_size = px
else: AssertionError("Invalid dimension of the design pattern.")

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size, periodic_axes=(0,1))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(
binary_design_pattern, periodic=(True, True)
)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
14 changes: 10 additions & 4 deletions RGB_metalens/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
if file_name[-3:] == 'csv':
design_pattern = np.genfromtxt(path+file_name, delimiter=',')

if file_name[0].upper() == 'M': design_size = 20*np.array(design_pattern.shape)
elif file_name[0].upper() in ('R', 'W'): design_size = 10*np.array(design_pattern.shape)
else: AssertionError("Unknown file name.")
if file_name[0].upper() == 'M':
pixel_size = 20
elif file_name[0].upper() in ('R', 'W'):
pixel_size = 10
else:
raise AssertionError("Unknown file name.")

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size)
binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
8 changes: 6 additions & 2 deletions cavity_design/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import imageruler

print('Design file, solid minimum lengthscale (nm), void minimum lengthscale (nm), minimum lengthscale (nm)')
design_size = (2000, 2000)
pixel_size = 5

for path in ['Mo/', 'Göktuğ/']:
files = os.listdir(path)
Expand All @@ -13,5 +13,9 @@
file_name = str(file)
if file_name[-3:] == 'csv':
design_pattern = np.genfromtxt(path+file_name, delimiter=',')
solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size)

binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
11 changes: 5 additions & 6 deletions slow_light_waveguide/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
files.sort()
print('Design file, solid minimum lengthscale (a), void minimum lengthscale (a), minimum lengthscale (a)')

design_size = (1, 10.2)

for file_name in ['Design_Dnum_2.csv', 'HigRes_DesMatch_Opt_Dnum_2.csv']:
design_pattern = np.loadtxt(path+file_name, delimiter=',')
design_dimension = np.ndim(design_pattern)
design_permittivity = np.loadtxt(path+file_name, delimiter=',')

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size, periodic_axes=(0,1))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
midpoint = (np.amax(design_permittivity) + np.amin(design_permittivity)) / 2
binary_design_pattern = design_permittivity > midpoint
solid_mls, void_mls = imageruler.minimum_length_scale(binary_design_pattern, periodic=(True, True))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
13 changes: 8 additions & 5 deletions waveguide_mode_converter/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
INPUT_PORT_IDX = 0
OUTPUT_PORT_IDX = 1

pixel_size = 10

parser = argparse.ArgumentParser()
parser.add_argument(
'file',
Expand Down Expand Up @@ -58,10 +60,11 @@
reflection_dB_worst = np.max(s_params_dB[:, INPUT_PORT_IDX])
transmission_dB_worst = np.min(s_params_dB[:, OUTPUT_PORT_IDX])

length_scale = imageruler.minimum_length(
model.density(design),
tuple(v * params.resolution.to_value(u.nm) for v in model.shape))

binary_design_pattern = model.density(design) > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(
f'{os.path.basename(filepath)}, {length_scale}, {reflection_dB_worst:.2f}, {transmission_dB_worst:.2f}'
f'{os.path.basename(filepath)}, ({solid_mls}, {void_mls}), '
f'{reflection_dB_worst:.2f}, {transmission_dB_worst:.2f}'
)

0 comments on commit 2683d5a

Please sign in to comment.