Discussion:
[Meep-discuss] materials_library module
John Weiner
2018-09-16 19:36:09 UTC
Permalink
Dear meep users, maintainers and developers,

Today I was experimenting with the materials_library.py which can be found in the /examples subdirectory, installed via the conda package. As a first step I tried to run one of the examples that uses the library, refl-quartz.py.

The first two lines of this script are:

import meep as mp
from meep.materials import fused_quartz

which, according to the docs, should work. When I run the script, however, I get an error message,

Traceback (most recent call last):
File "refl-quartz.py", line 2, in <module>
from meep.materials import fused_quartz
ModuleNotFoundError: No module named ‘meep.materials’

I tried using a few other “home-made” scripts with the same result. Apparently the module cannot be found or I am using the wrong syntax.

The python version of meep is installed in the miniconda3/ directory, following the instructions by Chris Hogan, and the mp environment is activated. Everything else works as it should, and I have run several of the other tutorials (refl-angular.py, bent_waveguide.py) without any problems. The problem therefore seems to be confined to the meep.materials module.

I would greatly appreciate any suggestion that might relieve my perplexity.

Best regards,

John
Thomas AUZINGER
2018-09-16 20:36:08 UTC
Permalink
Dear John,

I had the same problem and after some attempts to find a reproducible
way to identify the path where the materials library should be located,
I gave up and pulled the file directly from its repository. For this, I
import os
import urllib.request
    # Download materials library directly from online repository.
    module_name = 'materials_library.py'
    url =
('https://github.com/stevengj/meep/raw/master/python/examples/' +
           module_name)
    filepath = os.path.join(folderpath, module_name)
            content = urllib.request.urlopen(url).read()
            print('Failed to download materials library.')
            raise
            library_file.write(content)
In the file where you want to use the library, you add
import os
import meep as mp
import ABOVE_SCRIPT
ABOVE_SCRIPT.download_material_library(os.path.dirname(__file__))
disable=wrong-import-position
You just have to select names for ABOVE_SCRIPT and CURRENT_PACKAGE. The
last line should import materials_library, which was downloaded by the
command above it.
This script checks if materials_library already exists and avoids
redownloading it. Thus, the file can become outdated. Just delete it to
redownload it.

Cheers,
Thomas
Dear meep users, maintainers and developers,
Today I was experimenting with the materials_library.py which can be
found in the /examples subdirectory, installed via the conda package.
 As a first step I tried to run one of the examples that uses the
library, refl-quartz.py.
import meep as mp
from meep.materials import fused_quartz
which, according to the docs, should work.  When I run the script,
however, I get an error message,
File "refl-quartz.py", line 2, in <module>
from meep.materials import fused_quartz
ModuleNotFoundError: No module named ‘meep.materials’
I tried using a few other “home-made” scripts with the same result.
 Apparently the module cannot be found or I am using the wrong syntax.
The python version of meep is installed in the miniconda3/ directory,
following the instructions by Chris Hogan, and the mp environment is
activated.  Everything else works as it should, and I have run several
of the other tutorials (refl-angular.py, bent_waveguide.py) without
any problems.  The problem therefore seems to be confined to the
meep.materials module.
I would greatly appreciate any suggestion that might relieve my perplexity.
Best regards,
John
_______________________________________________
meep-discuss mailing list
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss
John Weiner
2018-09-16 20:40:50 UTC
Permalink
Thanks Thomas for this script. I will try it out ASAP and report the results.

Best regards,

John
Post by Thomas AUZINGER
Dear John,
import os
import urllib.request
# Download materials library directly from online repository.
module_name = 'materials_library.py'
url = ('https://github.com/stevengj/meep/raw/master/python/examples/ <https://github.com/stevengj/meep/raw/master/python/examples/>' +
module_name)
filepath = os.path.join(folderpath, module_name)
content = urllib.request.urlopen(url).read()
print('Failed to download materials library.')
raise
library_file.write(content)
In the file where you want to use the library, you add
import os
import meep as mp
import ABOVE_SCRIPT
ABOVE_SCRIPT.download_material_library(os.path.dirname(__file__))
from CURRENT_PACKAGE import materials_library # pylint: disable=wrong-import-position
You just have to select names for ABOVE_SCRIPT and CURRENT_PACKAGE. The last line should import materials_library, which was downloaded by the command above it.
This script checks if materials_library already exists and avoids redownloading it. Thus, the file can become outdated. Just delete it to redownload it.
Cheers,
Thomas
Dear meep users, maintainers and developers,
Today I was experimenting with the materials_library.py which can be found in the /examples subdirectory, installed via the conda package. As a first step I tried to run one of the examples that uses the library, refl-quartz.py.
import meep as mp
from meep.materials import fused_quartz
which, according to the docs, should work. When I run the script, however, I get an error message,
File "refl-quartz.py", line 2, in <module>
from meep.materials import fused_quartz
ModuleNotFoundError: No module named ‘meep.materials’
I tried using a few other “home-made” scripts with the same result. Apparently the module cannot be found or I am using the wrong syntax.
The python version of meep is installed in the miniconda3/ directory, following the instructions by Chris Hogan, and the mp environment is activated. Everything else works as it should, and I have run several of the other tutorials (refl-angular.py, bent_waveguide.py) without any problems. The problem therefore seems to be confined to the meep.materials module.
I would greatly appreciate any suggestion that might relieve my perplexity.
Best regards,
John
_______________________________________________
meep-discuss mailing list
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss <http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss>
Christopher Hogan
2018-09-17 13:18:48 UTC
Permalink
Hi John,

As of meep 1.6, the materials_library.py file has been integrated into the
meep package itself, and can be accessed via meep.materials. It is likely
that you have an older version of the pymeep package installed. You can
update to 1.6 with the command `conda update -c chogan -c conda-forge
pymeep`. The old materials_library.py now lives at meep/python/materials.py
in the repo.

Chris
Post by John Weiner
Thanks Thomas for this script. I will try it out ASAP and report the results.
Best regards,
John
Dear John,
I had the same problem and after some attempts to find a reproducible way
to identify the path where the materials library should be located, I gave
up and pulled the file directly from its repository. For this, I wrote the
import os
import urllib.request
# Download materials library directly from online repository.
module_name = 'materials_library.py'
url = ('https://github.com/stevengj/meep/raw/master/python/examples/'
+
module_name)
filepath = os.path.join(folderpath, module_name)
content = urllib.request.urlopen(url).read()
print('Failed to download materials library.')
raise
library_file.write(content)
In the file where you want to use the library, you add
import os
import meep as mp
import ABOVE_SCRIPT
ABOVE_SCRIPT.download_material_library(os.path.dirname(__file__))
disable=wrong-import-position
You just have to select names for ABOVE_SCRIPT and CURRENT_PACKAGE. The
last line should import materials_library, which was downloaded by the
command above it.
This script checks if materials_library already exists and avoids
redownloading it. Thus, the file can become outdated. Just delete it to
redownload it.
Cheers,
Thomas
Dear meep users, maintainers and developers,
Today I was experimenting with the materials_library.py which can be found
in the /examples subdirectory, installed via the conda package. As a first
step I tried to run one of the examples that uses the library,
refl-quartz.py.
import meep as mp
from meep.materials import fused_quartz
which, according to the docs, should work. When I run the script,
however, I get an error message,
File "refl-quartz.py", line 2, in <module>
from meep.materials import fused_quartz
ModuleNotFoundError: No module named ‘meep.materials’
I tried using a few other “home-made” scripts with the same result.
Apparently the module cannot be found or I am using the wrong syntax.
The python version of meep is installed in the miniconda3/ directory,
following the instructions by Chris Hogan, and the mp environment is
activated. Everything else works as it should, and I have run several of
the other tutorials (refl-angular.py, bent_waveguide.py) without any
problems. The problem therefore seems to be confined to the meep.materials
module.
I would greatly appreciate any suggestion that might relieve my perplexity.
Best regards,
John
_______________________________________________
_______________________________________________
meep-discuss mailing list
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss
John Weiner
2018-09-17 13:54:04 UTC
Permalink
Dear Chris and Thomas,

Yes! The update did the trick, and now...

import meep as mp
from meep.materials import fused-quartz

in the refl-quartz.py example is working correctly.

The exercise of understanding Thomas’ script for downloading the materials file directly from the repo was very useful for me, because it forced me to understand more clearly the difference between a “module” and a “package” and how the former should be subsumed under the latter.

Thank you both for your patience and explanations.

Best regards,

John
Post by Christopher Hogan
Hi John,
As of meep 1.6, the materials_library.py file has been integrated into the meep package itself, and can be accessed via meep.materials. It is likely that you have an older version of the pymeep package installed. You can update to 1.6 with the command `conda update -c chogan -c conda-forge pymeep`. The old materials_library.py now lives at meep/python/materials.py in the repo.
Chris
Thanks Thomas for this script. I will try it out ASAP and report the results.
Best regards,
John
Post by Thomas AUZINGER
Dear John,
import os
import urllib.request
# Download materials library directly from online repository.
module_name = 'materials_library.py'
url = ('https://github.com/stevengj/meep/raw/master/python/examples/ <https://github.com/stevengj/meep/raw/master/python/examples/>' +
module_name)
filepath = os.path.join(folderpath, module_name)
content = urllib.request.urlopen(url).read()
print('Failed to download materials library.')
raise
library_file.write(content)
In the file where you want to use the library, you add
import os
import meep as mp
import ABOVE_SCRIPT
ABOVE_SCRIPT.download_material_library(os.path.dirname(__file__))
from CURRENT_PACKAGE import materials_library # pylint: disable=wrong-import-position
You just have to select names for ABOVE_SCRIPT and CURRENT_PACKAGE. The last line should import materials_library, which was downloaded by the command above it.
This script checks if materials_library already exists and avoids redownloading it. Thus, the file can become outdated. Just delete it to redownload it.
Cheers,
Thomas
Dear meep users, maintainers and developers,
Today I was experimenting with the materials_library.py which can be found in the /examples subdirectory, installed via the conda package. As a first step I tried to run one of the examples that uses the library, refl-quartz.py.
import meep as mp
from meep.materials import fused_quartz
which, according to the docs, should work. When I run the script, however, I get an error message,
File "refl-quartz.py", line 2, in <module>
from meep.materials import fused_quartz
ModuleNotFoundError: No module named ‘meep.materials’
I tried using a few other “home-made” scripts with the same result. Apparently the module cannot be found or I am using the wrong syntax.
The python version of meep is installed in the miniconda3/ directory, following the instructions by Chris Hogan, and the mp environment is activated. Everything else works as it should, and I have run several of the other tutorials (refl-angular.py, bent_waveguide.py) without any problems. The problem therefore seems to be confined to the meep.materials module.
I would greatly appreciate any suggestion that might relieve my perplexity.
Best regards,
John
_______________________________________________
meep-discuss mailing list
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss <http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss>
_______________________________________________
meep-discuss mailing list
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss <http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss>
Loading...