From 1614959d18003ca3a8088cca188ef61da725a6e7 Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Thu, 26 Mar 2020 18:52:19 -0700 Subject: [PATCH] get_ldos_freqs method for Python LDOS objects (#1156) --- doc/docs/Python_User_Interface.md | 4 ++-- python/meep.i | 1 + python/simulation.py | 6 +++++- python/tests/ldos.py | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/docs/Python_User_Interface.md b/doc/docs/Python_User_Interface.md index d69bda767..cdbdf1ea7 100644 --- a/doc/docs/Python_User_Interface.md +++ b/doc/docs/Python_User_Interface.md @@ -1417,9 +1417,9 @@ Meep can also calculate the LDOS (local density of states) spectrum, as describe — Create an LDOS object with frequency bandwidth `df` centered at `fcen`, at `nfreq` frequency points. This can be passed to the `dft_ldos` step function below, and has the properties `freq_min`, `nfreq` and `dfreq`. -**`freqs()`** +**`get_ldos_freqs(ldos)`** — -Method of `Ldos` that returns a list of the frequencies that this `Ldos` instance is computing the spectrum for. +Given an LDOS object, returns a list of the frequencies that it is computing the spectrum for. **`dft_ldos(fcen=None, df=None, nfreq=None, ldos=None)`** — diff --git a/python/meep.i b/python/meep.i index f4180caf8..819a91a6d 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1454,6 +1454,7 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where get_fluxes, get_force_freqs, get_forces, + get_ldos_freqs, get_magnetic_energy, get_near2far_freqs, get_total_energy, diff --git a/python/simulation.py b/python/simulation.py index 46ad912a1..3a9476d48 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -2961,7 +2961,7 @@ def _ldos(sim, todo): sim.ldos_data = mp._dft_ldos_ldos(ldos) sim.ldos_Fdata = mp._dft_ldos_F(ldos) sim.ldos_Jdata = mp._dft_ldos_J(ldos) - display_csv(sim, 'ldos', zip(ldos.freq, sim.ldos_data)) + display_csv(sim, 'ldos', zip(mp.get_ldos_freqs(ldos), sim.ldos_data)) return _ldos @@ -2969,6 +2969,10 @@ def scale_flux_fields(s, flux): flux.scale_dfts(s) +def get_ldos_freqs(l): + return [l.freq[i] for i in range(l.freq.size())] + + def get_flux_freqs(f): return [f.freq[i] for i in range(f.freq.size())] diff --git a/python/tests/ldos.py b/python/tests/ldos.py index 481a7fcb5..f61684d0b 100644 --- a/python/tests/ldos.py +++ b/python/tests/ldos.py @@ -1,4 +1,3 @@ -import math import unittest import meep as mp @@ -43,7 +42,7 @@ def test_ldos_user_object(self): ) self.assertAlmostEqual(self.sim.ldos_data[0], 1.011459560620368) - self.assertEqual(ldos.freq.size(), 1) + self.assertEqual(len(mp.get_ldos_freqs(ldos)), 1) def test_invalid_dft_ldos(self): with self.assertRaises(ValueError):