-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change DispersionFitter to a pydantic.BaseModel object. Make eps_data, lossy, freqs, frequency_range into @Property types More error handling in StableDispersiveFitter Allow to load dispersive data directly by providing URL to txt or csv file Allow to filter wavelength range for fitting Add tunable eps_inf as a variable for optimization
- Loading branch information
1 parent
91807c0
commit 74c5eb6
Showing
7 changed files
with
645 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import numpy as np | ||
|
||
from tidy3d.plugins import StableDispersionFitter | ||
from tidy3d.plugins import StableDispersionFitter, DispersionFitter | ||
|
||
|
||
def test_dispersion_load_list(): | ||
"""performs a fit on some random data""" | ||
num_data = 10 | ||
n_data = np.random.random(num_data) | ||
wvls = np.linspace(1, 2, num_data) | ||
fitter = StableDispersionFitter(wvls, n_data) | ||
|
||
# num_poles = 3 | ||
# num_tries = 50 | ||
# tolerance_rms = 1e-3 | ||
# local_run = True | ||
# best_medium, best_rms = fitter.fit( | ||
# num_tries=num_tries, num_poles=num_poles, tolerance_rms=tolerance_rms, local_run=True | ||
# ) | ||
# print(best_rms) | ||
# print(best_medium.eps_model(1e12)) | ||
fitter = StableDispersionFitter(wvl_um=wvls, n_data=n_data) | ||
|
||
|
||
def test_dispersion_load_file(): | ||
"""loads dispersion model from nk data file""" | ||
fitter = StableDispersionFitter.from_file("tests/data/nk_data.csv", skiprows=1, delimiter=",") | ||
|
||
# num_poles = 3 | ||
# num_tries = 50 | ||
# tolerance_rms = 1e-3 | ||
# local_run = True | ||
# best_medium, best_rms = fitter.fit( | ||
# num_tries=num_tries, num_poles=num_poles, tolerance_rms=tolerance_rms, local_run=True | ||
# ) | ||
# print(best_rms) | ||
# print(best_medium.eps_model(1e12)) | ||
|
||
def test_dispersion_load_url(): | ||
"""performs a fit on some random data""" | ||
|
||
# both n and k | ||
url_csv = "https://refractiveindex.info/data_csv.php?datafile=data/main/Ag/Johnson.yml" | ||
url_txt = "https://refractiveindex.info/data_txt.php?datafile=data/main/Ag/Johnson.yml" | ||
fitter = DispersionFitter.from_url(url_csv, delimiter=",") | ||
fitter = StableDispersionFitter.from_url(url_csv, delimiter=",") | ||
fitter_txt = DispersionFitter.from_url(url_txt, delimiter="\t") | ||
fitter_txt = StableDispersionFitter.from_url(url_txt, delimiter="\t") | ||
fitter_txt.wvl_range = [0.3, 0.8] | ||
assert len(fitter_txt.freqs) < len(fitter.freqs) | ||
|
||
# only k | ||
url_csv = "https://refractiveindex.info/data_csv.php?datafile=data/main/N2/Peck-0C.yml" | ||
url_txt = "https://refractiveindex.info/data_txt.php?datafile=data/main/N2/Peck-0C.yml" | ||
fitter = DispersionFitter.from_url(url_csv, delimiter=",") | ||
fitter_txt = DispersionFitter.from_url(url_txt, delimiter="\t") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_dispersion_load_url() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# import the specific classes / functions needed for the plugins | ||
|
||
from .dispersion.fit import DispersionFitter | ||
from .dispersion.fit_web import StableDispersionFitter | ||
from .dispersion.fit_web import StableDispersionFitter, AdvancedFitterParam | ||
from .mode.mode_solver import ModeSolver | ||
from .near2far.near2far import Near2Far |
Oops, something went wrong.