Skip to content

Commit

Permalink
Merge pull request #100 from Jashcraf/use_pathlib
Browse files Browse the repository at this point in the history
Use pathlib, added test to make sure materials work and modified setup.cfg to install material data too
  • Loading branch information
Jashcraf authored Dec 22, 2023
2 parents 843aa0c + 538268f commit 39e04b5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:
jobs:
build:

runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
Expand All @@ -35,7 +35,7 @@ jobs:
run: |
# Replace `linux` below with the appropriate OS
# Options are `alpine`, `linux`, `macos`, `windows`
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/macos/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
16 changes: 4 additions & 12 deletions poke/materials.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import numpy as np
from scipy.interpolate import interp1d
import os
import poke.materials as matdata

# TODO: Add an _actual_ pathfinder
matfilepath = os.path.abspath(__file__)[:-12]
from pathlib import Path

# Silica == Fused Silica
avail_materials = ['Al','Ag', # metals
Expand All @@ -15,9 +11,10 @@
]

def get_abs_path(file):
fullpth = matfilepath+'material_data/'+file
fullpth = Path(__file__).parent/'material_data'/file
return fullpth


def create_index_model(material,verbose=False):
"""creates an interpolated material based on data available from refractiveindex.info
Expand Down Expand Up @@ -106,9 +103,4 @@ def create_index_model(material,verbose=False):
else:
index_model = n_model

return index_model





return index_model
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ install_requires =
python_requires = >= 3.8
setup_requires = setuptools_scm
[options.package_data]
poke = material_data/*.csv
35 changes: 16 additions & 19 deletions tests/test_materials.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import numpy as np
import poke.materials as mat
import pytest
import os

# def test_create_index_model():
def test_create_index_model():

# # TODO: The file import system doesn't work on the GH Actions test
# TODO: The file import system doesn't work on the GH Actions test

# # prealloc lists
# reference = []
# test = []
# prealloc lists
reference = []
test = []

# # pick a complex material and a dielectric
# materials = ['Al','HfO2']
# pick a complex material and a dielectric
materials = ['Al','HfO2']

# # load refractive indices from a certain wavelength
# wvl = [0.51660,0.5060]
# ns = [0.51427,1.9083754098692]
# ks = [4.95111,0]
# for material,wave,n,k in zip(materials,wvl,ns,ks):
# n_callable = mat.create_index_model(material)
# load refractive indices from a certain wavelength
wvl = [0.51660,0.5060]
ns = [0.51427,1.9083754098692]
ks = [4.95111,0]
for material,wave,n,k in zip(materials,wvl,ns,ks):
n_callable = mat.create_index_model(material)

# reference.append(n + 1j*k)
# test.append(n_callable(wave))
reference.append(n + 1j*k)
test.append(n_callable(wave))

# # np.testing.assert_allclose(reference,test)
# pass
return np.testing.assert_allclose(reference,test)

0 comments on commit 39e04b5

Please sign in to comment.