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

Added notebook for generating NIDN results using FDTD #90

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
322 changes: 322 additions & 0 deletions notebooks/5 - Structure and Material Inference FDTD.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "e5c11861",
"metadata": {},
"outputs": [],
"source": [
"# Append root folder in case you haven't installed NIDN\n",
"import sys\n",
"sys.path.append(\"../\")\n",
"\n",
"import nidn"
]
},
{
"cell_type": "markdown",
"id": "9afe0a85",
"metadata": {},
"source": [
"# Single layer , uniform, regression"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "579aae8b",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# Load default cfg as starting point\n",
"cfg = nidn.load_default_cfg()\n",
"\n",
"# Specify your desired range of wavelengths\n",
"cfg.physical_wavelength_range[0] = 3e-7\n",
"cfg.physical_wavelength_range[1] = 9e-7\n",
"cfg.TRCWA_PER_LAYER_THICKNESS = [0.38]\n",
"\n",
"# Let's investigate 50 frequency points\n",
torbjornstoro marked this conversation as resolved.
Show resolved Hide resolved
"cfg.N_freq = 20\n",
"cfg.solver = \"FDTD\"\n",
"cfg.FDTD_niter = 400\n",
"cfg.N_layers = 1\n",
"cfg.FDTD_pulse_type = 'continuous'\n",
"cfg.FDTD_source_type = 'line'\n",
"\n",
"# Currently, the target spectra is set manually as a list of numbers. Choose each 5th value to reduce rom 100 frequency points to 20 frequency points\n",
torbjornstoro marked this conversation as resolved.
Show resolved Hide resolved
"cfg.target_reflectance_spectrum = [0.04456351,0.07616634,0.12983103,0.20348341,0.20803709,0.28212550,0.34838794,0.35148116,0.40294107,0.43659179,0.43804083,0.45265764,0.42395525,0.42250250,0.35184451,0.34927237,0.23594347,0.22968049,0.10109031,0.09566545,0.09204569,0.04801336,0.04943829,0.15785883,0.16480385,0.33755576,0.34852490,0.35598405,0.47175452,0.47543828,0.48079059,0.47670861,0.47495085,0.47283219,0.33080953,0.31996884,0.30833286,0.29704388,0.07221731,0.06803254,0.06279853,0.25093825,0.27168874,0.29327866,0.31555886,0.52987157,0.53266849,0.53949557,0.54329768,0.54590920,0.35588414,0.34058632,0.30762652,0.27317067,0.16839377,0.20723618,0.25279078,0.27902083,0.33203165,0.38699248,0.57960660,0.56132624,0.54713063,0.50812035,0.47987271,0.40737469,0.31942957,0.41918578,0.46946234,0.55008628,0.57858655,0.60237008,0.22992761,0.32204145,0.38371327,0.44023784,0.49577304,0.49328186,0.46340183,0.45237985,0.51436802,0.52561688,0.53433126,0.54193417,0.55985565,0.56738637,0.57371749,0.57877213,0.65791848,0.65526587,0.65189846,0.64806130,0.64002900,0.63579534,0.63167151,0.62771639,0.62199316,0.66017008,0.65453985,0.64911847,][0::5]\n",
"cfg.target_transmittance_spectrum =[0.87536937,0.86225903,0.81306321,0.75287122,0.74871316,0.68198832,0.62422039,0.62128133,0.57431380,0.54036076,0.53893761,0.53746136,0.56318135,0.56430514,0.62822533,0.63025375,0.72190201,0.72902601,0.82516558,0.82823149,0.83023419,0.85988161,0.85803865,0.77452468,0.76844363,0.62843653,0.61871883,0.61209847,0.51762058,0.51417495,0.50911674,0.50285459,0.50413010,0.50572154,0.62959830,0.63739662,0.64559040,0.65416174,0.81584808,0.81671772,0.81649914,0.67631454,0.65980186,0.64488775,0.62678816,0.44563180,0.44270788,0.43865578,0.43446768,0.43148086,0.57915950,0.58924005,0.61020821,0.63242840,0.68207222,0.65677377,0.62419689,0.60660547,0.57197304,0.53173307,0.37738633,0.39192256,0.40217924,0.42987445,0.44531120,0.47829903,0.49511773,0.42511123,0.39097864,0.32282715,0.29403716,0.25334013,0.33381818,0.24619652,0.20109781,0.16036236,0.10121669,0.07910624,0.04449772,0.03074843,0.01117523,0.00339080,0.00167748,0.00077300,0.00015712,0.00006627,0.00003636,0.00001924,0.00000530,0.00000348,0.00000238,0.00000169,0.00000096,0.00000075,0.00000060,0.00000048,0.00000034,0.00000030,0.00000024,0.00000019,][0::5]\n",
"\n",
"nidn.plot_spectrum(cfg,\n",
" cfg.target_reflectance_spectrum,\n",
" cfg.target_transmittance_spectrum)\n",
"\n",
"physical_wls, normalized_freqs = nidn.get_frequency_points(cfg)\n",
"print(\"Physical wavelengths are (in meters):\")\n",
"print(physical_wls)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "970b965a",
"metadata": {},
"outputs": [],
"source": [
"cfg.pop(\"model\",None); # Forget the old model\n",
"\n",
"# Allowed range of epsilon values\n",
"cfg.real_min_eps = 0.00\n",
"cfg.real_max_eps = 20.0\n",
"cfg.imag_min_eps = 0.0\n",
"cfg.imag_max_eps = 6.0\n",
"\n",
"cfg.type = \"regression\" # Choose type as described above\n",
"cfg.iterations = 100 # Set number of training iterations (that is forward model evaluations) to perform"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "367463dd",
"metadata": {},
"outputs": [],
"source": [
"nidn.print_cfg(cfg)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b8c547a",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"nidn.run_training(cfg);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "578b6bdc",
"metadata": {},
"outputs": [],
"source": [
"nidn.plot_spectra(cfg)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66748550",
"metadata": {},
"outputs": [],
"source": [
"nidn.plot_eps_per_point(cfg,compare_to_material=\"titanium_oxide\")"
]
},
{
"cell_type": "markdown",
"id": "6c0b0854",
"metadata": {},
"source": [
"# Single layer , uniform, classification"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09bb33f5",
"metadata": {},
"outputs": [],
"source": [
"cfg.pop(\"model\",None); # Forget the old model\n",
"\n",
"# Allowed range of epsilon values\n",
"cfg.real_min_eps = 0.0\n",
"cfg.real_max_eps = 20.0\n",
"cfg.imag_min_eps = 0.0\n",
"cfg.imag_max_eps = 6.0\n",
"\n",
"cfg.type = \"classification\" # Choose type as described above\n",
"cfg.iterations = 100 # Set number of training iterations (that is forward model evaluations) to perform"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "481b28f2",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"nidn.run_training(cfg);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0bc16df3",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"nidn.plot_spectra(cfg)\n",
"nidn.plot_eps_per_point(cfg)"
]
},
{
"cell_type": "markdown",
"id": "f2b7bf18",
"metadata": {},
"source": [
"## Uniform Three-Layer Ground Truth "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b601e1b4",
"metadata": {},
"outputs": [],
"source": [
"# Load default cfg as starting point\n",
"cfg = nidn.load_default_cfg()\n",
"\n",
"# Set grid specifics\n",
"cfg.Nx = 1\n",
"cfg.Ny = 1\n",
"cfg.N_layers = 3\n",
"cfg.N_freq = 20\n",
"cfg.PER_LAYER_THICKNESS = [1.0]\n",
"cfg.FDTD_pulse_type = 'continuous'\n",
"cfg.FDTD_source_type = 'line'\n",
torbjornstoro marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"# Specify your desired range of wavelengths\n",
"cfg.physical_wavelength_range[0] = 6e-7 \n",
"cfg.physical_wavelength_range[1] = 3e-6\n",
"\n",
"cfg.target_reflectance_spectrum =[0.14366185,0.27504679,0.17564494,0.20414668,0.40380960,0.30072133,0.26199707,0.38340070,0.36834200,0.23065582,0.55063775,0.15905333,0.63662124,0.08958707,0.64845886,0.13649373,0.70790738,0.71218611,0.68279302,0.58548506,]\n",
"cfg.target_transmittance_spectrum =[0.79465473,0.64171370,0.60055604,0.62438044,0.52177391,0.56217832,0.53327435,0.41774403,0.48310163,0.17431544,0.00010415,0.00000067,0.00000009,0.00000003,0.00000001,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,]\n",
"\n",
"cfg.FDTD_niter = 800\n",
"cfg.solver =\"FDTD\"\n",
"\n",
"nidn.plot_spectrum(cfg,\n",
" cfg.target_reflectance_spectrum,\n",
" cfg.target_transmittance_spectrum)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "579f8ada",
"metadata": {},
"outputs": [],
"source": [
"# Allowed range of epsilon values\n",
"cfg.pop(\"model\",None); # Forget the old model\n",
"cfg.real_min_eps = 0.0\n",
"cfg.real_max_eps = 20.0\n",
"cfg.imag_min_eps = 0.0\n",
"cfg.imag_max_eps = 10.0\n",
"\n",
"cfg.type = \"regression\" # Choose type as described above (for now still regression)\n",
"cfg.iterations = 100 # Set number of training iterations (that is forward model evaluations) to perform"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a834af6",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"nidn.run_training(cfg);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a647a1ae",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# The other plots\n",
"nidn.plot_spectra(cfg)\n",
"nidn.plot_eps_per_point(cfg,compare_to_material=[\"titanium_oxide\",\"germanium\",\"tantalum_pentoxide\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e086e94",
"metadata": {},
"outputs": [],
"source": [
"# Allowed range of epsilon values\n",
"cfg.pop(\"model\",None); # Forget the old model\n",
"\n",
"cfg.type = \"classification\" # Choose type as described above (for now still regression)\n",
"cfg.iterations = 100 # Set number of training iterations (that is forward model evaluations) to perform"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0eddee6e",
"metadata": {},
"outputs": [],
"source": [
"nidn.run_training(cfg);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68cbb987",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# The other plots\n",
"nidn.plot_spectra(cfg)\n",
"nidn.plot_eps_per_point(cfg,compare_to_material=[\"titanium_oxide\",\"germanium\",\"tantalum_pentoxide\"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
72 changes: 38 additions & 34 deletions notebooks/Supplementary - Ground-truth Data Generation FDTD.ipynb

Large diffs are not rendered by default.