Browse Source

Merge branch 'master' into js

Konstantin Ladutenko 5 years ago
parent
commit
52d62c8923

+ 4 - 5
Makefile

@@ -1,14 +1,14 @@
 PYTHON=`which python3`
 DESTDIR=/
 PROJECT=python-scattnlay
-VERSION=2.2
+VERSION=2.3
 BUILDIR=$(CURDIR)/debian/$(PROJECT)
 SRCDIR=$(CURDIR)/src
 MULTIPREC=100
 CXX_NMIE_HEADERS=$(SRCDIR)/nmie.hpp $(SRCDIR)/nmie-impl.cc $(SRCDIR)/nmie-precision.hpp
 
 all:
-	@echo "make src - Create source package for Python extension"
+	@echo "make source - Create source package for Python extension"
 	@echo "make ext - Create Python extension in place"
 	@echo "make install - Install Python extension on local system"
 	@echo "make rpm - Generate a rpm package for Python extension"
@@ -17,7 +17,7 @@ all:
 	@echo "make clean - Delete temporal files"
 #	make standalone
 
-src:
+source:
 	$(PYTHON) setup.py sdist $(COMPILE) --dist-dir=../
 
 ext: $(SRCDIR)/nmie.cc $(SRCDIR)/nmie-pybind11.cc $(SRCDIR)/pb11_wrapper.cc
@@ -30,10 +30,9 @@ rpm:
 	#$(PYTHON) setup.py bdist_rpm --post-install=rpm/postinstall --pre-uninstall=rpm/preuninstall
 	$(PYTHON) setup.py bdist_rpm --dist-dir=../
 
-deb:
+deb: source
 	# build the source package in the parent directory
 	# then rename it to project_version.orig.tar.gz
-	$(PYTHON) setup.py sdist $(COMPILE) --dist-dir=../ --prune
 	rename -f 's/$(PROJECT)-(.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
 	# build the package
 	dpkg-buildpackage -i -I -rfakeroot

+ 4 - 1
README.md

@@ -51,13 +51,14 @@ And to compile the Debian package you need some tools:
 
 Compilation options
 
- - **make src** - Create source package for Python extension
+ - **make source** - Create source package for Python extension
  - **make ext** - Create Python extension using C++ code
  - **make install** - Install Python extension on local system
  - **make rpm** - Generate a rpm package for Python extension
  - **make deb** - Generate a deb package for Python extension
  - **make standalone** - Create standalone programs (scattnlay and fieldnlay)
  - **make clean** - Delete temporal files
+  
 
 Binary install:
 --------------
@@ -78,6 +79,8 @@ You can also install it from PyPi via
 sudo pip install python-scattnlay
 ```
 
+You can also ```git clone``` and ```pip install -e .``` to develop python package.
+
 Use:
 ----
 

+ 5 - 0
debian/changelog

@@ -1,3 +1,8 @@
+python-scattnlay (2.3.0-1) bionic; urgency=low
+
+  * Updated for Bionic Beaver (2.3.0-1)
+ -- Ovidio Peña Rodríguez <ovidio@bytesfall.com>  Fri, 04 Oct 2019 10:43:00 +0100
+
 python-scattnlay (2.2.0-1) xenial; urgency=low
 
   * Updated for Xenial Xerus (2.2.0-1)

BIN
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/R0.5mkm.jpg


BIN
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/R0.5mkm_mp.jpg


BIN
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/R1mkm.jpg


BIN
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/R1mkm_mp.jpg


BIN
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/R3mkm_mp.jpg


+ 84 - 0
examples/Opt.Commun.-2010-Geints-Nanojets_of_dielectric_microspheres/fig1.py

@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+#
+#    Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
+#    Copyright (C) 2013-2015  Konstantin Ladutenko <kostyfisik@gmail.com>
+#
+#    This file is part of python-scattnlay
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    The only additional remark is that we expect that all publications
+#    describing work using this software, or all commercial products
+#    using it, cite at least one of the following references:
+#    [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
+#        a multilayered sphere," Computer Physics Communications,
+#        vol. 180, Nov. 2009, pp. 2348-2354.
+#    [2] K. Ladutenko, U. Pal, A. Rivera, and O. Pena-Rodriguez, "Mie
+#        calculation of electromagnetic near-field for a multilayered
+#        sphere," Computer Physics Communications, vol. 214, May 2017,
+#        pp. 225-230.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http:#www.gnu.org/licenses/>.
+
+import scattnlay
+from scattnlay import fieldnlay
+from scattnlay import scattnlay
+import numpy as np
+from matplotlib import pyplot as plt
+
+npts = 151
+factor = 3. # plot extent compared to sphere radius
+index_H2O = 1.33+0.j
+
+WL = 0.532 #mkm
+total_r = 3 #mkm
+
+nm = 1.0 # host medium
+x = 2.0 * np.pi * np.array([total_r / 4.0 * 3.0, total_r], dtype=np.float64) / WL
+m = np.array((index_H2O, index_H2O), dtype=np.complex128) / nm
+
+print("x =", x)
+print("m =", m)
+terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
+    np.array([x]), np.array([m]))
+print("Qsca = " + str(Qsca))
+terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
+    np.array([x]), np.array([m]), mp=True)
+print("mp Qsca = " + str(Qsca))
+
+scan = np.linspace(-factor*x[-1], factor*x[-1], npts)
+zero = np.zeros(npts*npts, dtype = np.float64)
+
+coordX, coordZ = np.meshgrid(scan, scan)
+coordX.resize(npts * npts)
+coordZ.resize(npts * npts)
+coordY = zero
+
+terms, E, H = fieldnlay(
+    np.array([x]), np.array([m]),
+    coordX, coordY, coordZ,
+    mp=True
+)
+Ec = E[0, :, :]
+Er = np.absolute(Ec)
+Eabs2 = (Er[:, 0]**2 + Er[:, 1]**2 + Er[:, 2]**2)
+Eabs_data = np.resize(Eabs2, (npts, npts))
+label = r'$|E|^2$'
+plt.imshow(Eabs_data,
+           cmap='jet',
+           vmin=0., vmax=14
+
+           )
+print(np.min(Eabs_data), np.max(Eabs_data))
+plt.savefig("R"+str(total_r)+"mkm_mp.jpg")
+# plt.show()

+ 32 - 30
examples/field-Ag-flow.py

@@ -34,25 +34,26 @@ from fieldplot import fieldplot
 
 import numpy as np
 import cmath
+
 # # a)
-#WL=400 #nm
-#core_r = WL/20.0
-#epsilon_Ag = -2.0 + 10.0j
+# WL=400 #nm
+# core_r = WL/20.0
+# epsilon_Ag = -2.0 + 10.0j
 
 # # b)
-#WL=400 #nm
-#core_r = WL/20.0
-#epsilon_Ag = -2.0 + 1.0j
+# WL=400 #nm
+# core_r = WL/20.0
+# epsilon_Ag = -2.0 + 1.0j
 
 # c)
-WL=354 #nm
-core_r = WL/20.0
+WL = 354  # nm
+core_r = WL / 20.0
 epsilon_Ag = -2.0 + 0.28j
 
 # d)
-#WL=367 #nm
-#core_r = WL/20.0
-#epsilon_Ag = -2.71 + 0.25j
+# WL=367 #nm
+# core_r = WL/20.0
+# epsilon_Ag = -2.71 + 0.25j
 
 # WL=500 #nm
 # core_r = 615.0
@@ -64,36 +65,37 @@ index_Ag = np.sqrt(epsilon_Ag)
 # n2 = 0.565838 + 7.23262j
 nm = 1.0
 
-x = 2.0*np.pi*np.array([core_r/4.0*3.0, core_r], dtype = np.float64)/WL
+x = 2.0 * np.pi * np.array([core_r / 4.0 * 3.0, core_r], dtype=np.float64) / WL
 
-m = np.array((index_Ag, index_Ag), dtype = np.complex128)/nm
+m = np.array((index_Ag, index_Ag), dtype=np.complex128) / nm
 
-print( "x =", x)
-print( "m =", m)
+print("x =", x)
+print("m =", m)
 
-comment='bulk-WL'+str(WL)+'nm_r'+str(core_r)+'nm_epsilon'+str(epsilon_Ag)+'-flow'
-WL_units='nm'
+comment = 'bulk-WL' + str(WL) + 'nm_r' + str(core_r) + 'nm_epsilon' + str(epsilon_Ag) + '-flow'
+WL_units = 'nm'
 npts = 251
-factor=2.1
+factor = 2.1
 flow_total = 9
-#flow_total = 21
-#flow_total = 0
-crossplane='XZ'
-#crossplane='YZ'
+# flow_total = 21
+# flow_total = 0
+crossplane = 'XZ'
+# crossplane='YZ'
 # crossplane='XY'
 
 # Options to plot: Eabs, Habs, Pabs, angleEx, angleHy
-field_to_plot='Pabs'
-#field_to_plot='angleEx'
+field_to_plot = 'Pabs'
+# field_to_plot='angleEx'
 
 
 import matplotlib.pyplot as plt
-fig, axs = plt.subplots(1,1)#, sharey=True, sharex=True)
+
+fig, axs = plt.subplots(1, 1)  # , sharey=True, sharex=True)
 fig.tight_layout()
-fieldplot(fig, axs, x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total,
-          subplot_label=' ',is_flow_extend=False)
+fieldplot(fig, axs, x, m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total,
+          subplot_label=' ', is_flow_extend=False)
 
-#fieldplot(x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total, is_flow_extend=False)
+# fieldplot(x,m, WL, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total, is_flow_extend=False)
 
 # for ax in axs:
 #     ax.locator_params(axis='x',nbins=5)
@@ -101,8 +103,8 @@ fieldplot(fig, axs, x,m, WL, comment, WL_units, crossplane, field_to_plot, npts,
 
 fig.subplots_adjust(hspace=0.3, wspace=-0.1)
 
-plt.savefig(comment+"-R"+str(int(round(x[-1]*WL/2.0/np.pi)))+"-"+crossplane+"-"
-                    +field_to_plot+".pdf",pad_inches=0.02, bbox_inches='tight')
+plt.savefig(comment + "-R" + str(int(round(x[-1] * WL / 2.0 / np.pi))) + "-" + crossplane + "-"
+            + field_to_plot + ".pdf", pad_inches=0.02, bbox_inches='tight')
 
 plt.draw()
 

+ 4 - 5
setup.py

@@ -30,7 +30,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-__version__ = '2.2'
+__version__ = '2.3'
 __title__ = 'Calculation of the scattering of EM radiation by a multilayered sphere'
 __mod__ = 'python-scattnlay'
 __author__ = 'Ovidio Peña Rodríguez'
@@ -38,8 +38,8 @@ __email__ = 'ovidio@bytesfall.com'
 __url__ = 'https://github.com/ovidiopr/scattnlay'
 __download_url__ = 'https://github.com/ovidiopr/scattnlay/archive/v2.2.0.tar.gz'
 
-from distutils.core import setup
-from distutils.extension import Extension
+from setuptools import setup
+from setuptools.extension import Extension
 import numpy as np
 import pybind11 as pb
 
@@ -60,8 +60,7 @@ O. Pena, U. Pal, Comput. Phys. Commun. 180 (2009) 2348-2354.""",
       download_url = __download_url__,
       license = 'GPL',
       platforms = 'any',
-      packages = ['scattnlay'#, 'scattnlay_dp', 'scattnlay_mp'
-                  ],
+      packages = ['scattnlay'],#, 'scattnlay_dp', 'scattnlay_mp'],
       ext_modules = [Extension("scattnlay_dp",
                                ["src/nmie.cc", "src/nmie-pybind11.cc", "src/pb11_wrapper.cc"],
                                language = "c++",

+ 15 - 7
tests/python/test04_field.py

@@ -47,7 +47,7 @@
 from scattnlay import fieldnlay
 import numpy as np
 
-nL = 2
+nL = 10
 Xmax = 60.0
 
 x = np.array([np.linspace(Xmax/nL, Xmax, nL)], dtype = np.float64)
@@ -56,7 +56,7 @@ m = np.array((np.sqrt((2.0 - (x[0]/Xmax - 0.5/nL)**2.0))), dtype = np.complex128
 print "x =", x
 print "m =", m
 
-npts = 500
+npts = 100
 
 scan = np.linspace(-3*Xmax, 3*Xmax, npts)
 
@@ -65,12 +65,20 @@ coordX.resize(npts*npts)
 coordY.resize(npts*npts)
 coordZ = np.zeros(npts*npts, dtype = np.float64)
 
+#idx = np.where(np.sqrt(coordX**2 + coordY**2) < 10.)
+#coordX = np.delete(coordX, idx)
+#coordY = np.delete(coordY, idx)
+#coordZ = np.delete(coordZ, idx)
+
 terms, E, H = fieldnlay(x, m, coordX, coordY, coordZ)
+print "E", E
 
 Er = np.absolute(E)
+print "Er", Er
 
 # |E|/|Eo|
 Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
+print "Eh", Eh
 
 result = np.vstack((coordX, coordY, coordZ, Eh)).transpose()
 
@@ -112,12 +120,12 @@ try:
     plt.xlabel('X')
     plt.ylabel('Y')
 
-    # This part draws the nanoshell
-#    from matplotlib import patches
+    # This part draws the lens
+    from matplotlib import patches
 
-#    s1 = patches.Arc((0, 0), 2.0*x[0, 0], 2.0*x[0, 0], angle=0.0, zorder=2,
-#                      theta1=0.0, theta2=360.0, linewidth=1, color='#00fa9a')
-#    ax.add_patch(s1)
+    s1 = patches.Arc((0, 0), 2.0*Xmax, 2.0*Xmax, angle=0.0, zorder=2,
+                      theta1=0.0, theta2=360.0, linewidth=1, color='#00fa9a')
+    ax.add_patch(s1)
 
 #    s2 = patches.Arc((0, 0), 2.0*x[0, 1], 2.0*x[0, 1], angle=0.0, zorder=2,
 #                      theta1=0.0, theta2=360.0, linewidth=1, color='#00fa9a')