diff --git a/.gitignore b/.gitignore index f58549b..6452740 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -optool +env/ optool.dSYM optool.egg-info penmp @@ -20,7 +20,6 @@ __pycache__ auto/ *.html *.tex -*.tex *.aux *.log *.dvi @@ -31,4 +30,6 @@ tmp.py optool.pdf optool_sd.dat optool_lam.dat -plotsd.py \ No newline at end of file +plotsd.py +*.swp +dist diff --git a/CONTENT b/CONTENT index 57d65c7..7316034 100644 --- a/CONTENT +++ b/CONTENT @@ -1,32 +1,33 @@ List of files in the optool distribution ======================================== -CONTENT This file -INSTALL Brief installation instructions (also in UserGuide) -LICENSE License information -Makefile Makefile to aid compilation and installation -README.org Short introduction, source for githup site -UserGuide.org The User guide, an Emacs Org-mode file -UserGuide.pdf PDF version of UserGuide.org -code4reading Directory with code snippets to read optool output -codemeta.jason Matadata for optool -lnk_data Directory with refractive index data -maint Directory with scripts aiding maintenance -optool.f90 Main code file for optool -optool_guts.f90 Code that does the grunt work for computing opacities -optool_fractal.f90 Code implementing modified mean field theory -optool_geofractal.f90 Code computing geometric aggregate cross sections -optool_manual.f90 The Manual extracted from UserGuide.org, baked into f90 -optool_refind.f90 Refractive index data as fortran code -optool Binary program, only present after running "make" -optool.py Python module for working with optool -setup.py Code for python module installation -optool2tex Perl program to turn optool command into LaTeX text -optool-complete Code for shell-completion of switches and arguments -optool.bib BibTeX file with all relevant references +CONTENT This file +INSTALL Brief installation instructions (also in UserGuide) +LICENSE License information +README.org Short introduction, source for github site +UserGuide.org The User guide, an Emacs Org-mode file +UserGuide.pdf PDF version of UserGuide.org +codemeta.jason Metadata for optool +pyproject.toml Code for python module installation +src/optool/Makefile Makefile to aid compilation and installation +src/optool/__init__.py Python file for initializing the module +src/optool/code4reading Directory with code snippets to read optool output +src/optool/lnk_data Directory with refractive index data +src/optool/maint Directory with scripts aiding maintenance +src/optool/optool.f90 Main code file for optool +src/optool/optool_guts.f90 Code that does the grunt work for computing opacities +src/optool/optool_fractal.f90 Code implementing modified mean field theory +src/optool/optool_geofractal.f90 Code computing geometric aggregate cross sections +src/optool/optool_manual.f90 The Manual extracted from UserGuide.org, baked into f90 +src/optool/optool_refind.f90 Refractive index data as fortran code +src/optool/optool Binary program, only present after running "make" +src/optool/optool.py Python module for working with optool +src/optool/optool2tex Perl program to turn optool command into LaTeX text +src/optool/optool-complete Code for shell-completion of switches and arguments +src/optool/optool.bib BibTeX file with all relevant references -In directory maint +In directory src/optool/maint ================== RELEASE Description of how to produce a release all_k.pdf Plot of k values, made with plotall.py, used in manual @@ -41,7 +42,7 @@ run_examples Script running all examples from the manual selftest.pl Perl program to run a bunch of tests with optool -In directory code4reading +In directory src/optool/code4reading ========================= Makefile Makefile to compile the fortran snippets README Information about how to use the snippets @@ -51,12 +52,12 @@ readfits.f90 Fortran program to read FITS output readfits.py Python program to read FITS output -In directory lnk_data +In directory src/optool/lnk_data ===================== lnk-help.txt The help screen shown by optool -c retired Directory with retired datasets -The refractive index datasets in the lnk_data directory +The refractive index datasets in the src/optool/lnk_data directory ------------------------------------------------------- astrosil-Draine2003.lnk astronomical silicate c-gra-Draine2003.lnk graphite (crystalline) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..149b4e2 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include src/optool * diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..510fa3c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "astro-optool" +version = "1.9.5" +# dynamic = ["version"] +dependencies = [ + "numpy >= 1.18", + "matplotlib >= 2.0", +] +requires-python = ">= 3.7" +authors = [ + {name = "Carsten Dominik", email = "c.dominik@uva.nl"}, + {name = "Michiel Min", email = "M.Min@sron.nl"}, + {name = "Ryo Tazaki", email = "ryo.tazaki1205@gmail.com"}, +] +description = "Optool" +readme = {file = "README.org", content-type = "text/plain"} +license = {file = "LICENSE"} +keywords = ["astrophysics"] + +[project.urls] +Issues = "https://github.com/cdominik/optool/issues" +Repository = "https://github.com/cdominik/optool" diff --git a/setup.py b/setup.py deleted file mode 100644 index edf01de..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from setuptools import setup - -setup( - name='optool', - version='1.9.4', - py_modules=['optool'], - install_requires=[ - 'numpy','matplotlib' - ] -) diff --git a/Makefile b/src/optool/Makefile similarity index 100% rename from Makefile rename to src/optool/Makefile diff --git a/src/optool/__init__.py b/src/optool/__init__.py new file mode 100644 index 0000000..f15ff42 --- /dev/null +++ b/src/optool/__init__.py @@ -0,0 +1,27 @@ +import os +import pathlib +import shutil +import subprocess +from .optool import * + + +MODULE_PATH = pathlib.Path(__file__).parent.resolve() +OPTOOL = shutil.which(f"{MODULE_PATH}/optool") + + +def make_optool(options=None): + os.chdir(MODULE_PATH) + cmd = ["make",] + if options is not None: + cmd.append(options) + subprocess.Popen(cmd).wait() + + +if OPTOOL is None: + q = input( + "Cannot find 'optool' executable, shall I try to compile it using " + "default options (make clean; make multi)? (y/n)" + ) + if q.lower() == "y": + make_optool(options="clean") + make_optool(options="multi") diff --git a/code4reading/Makefile b/src/optool/code4reading/Makefile similarity index 100% rename from code4reading/Makefile rename to src/optool/code4reading/Makefile diff --git a/code4reading/README b/src/optool/code4reading/README similarity index 100% rename from code4reading/README rename to src/optool/code4reading/README diff --git a/code4reading/readascii.f90 b/src/optool/code4reading/readascii.f90 similarity index 100% rename from code4reading/readascii.f90 rename to src/optool/code4reading/readascii.f90 diff --git a/code4reading/readascii.py b/src/optool/code4reading/readascii.py similarity index 100% rename from code4reading/readascii.py rename to src/optool/code4reading/readascii.py diff --git a/code4reading/readfits.f90 b/src/optool/code4reading/readfits.f90 similarity index 100% rename from code4reading/readfits.f90 rename to src/optool/code4reading/readfits.f90 diff --git a/code4reading/readfits.py b/src/optool/code4reading/readfits.py similarity index 100% rename from code4reading/readfits.py rename to src/optool/code4reading/readfits.py diff --git a/lnk_data/ad/README.org b/src/optool/lnk_data/ad/README.org similarity index 100% rename from lnk_data/ad/README.org rename to src/optool/lnk_data/ad/README.org diff --git a/lnk_data/ad/c-gra-x-Draine2003.lnk b/src/optool/lnk_data/ad/c-gra-x-Draine2003.lnk similarity index 100% rename from lnk_data/ad/c-gra-x-Draine2003.lnk rename to src/optool/lnk_data/ad/c-gra-x-Draine2003.lnk diff --git a/lnk_data/ad/c-gra-y-Draine2003.lnk b/src/optool/lnk_data/ad/c-gra-y-Draine2003.lnk similarity index 100% rename from lnk_data/ad/c-gra-y-Draine2003.lnk rename to src/optool/lnk_data/ad/c-gra-y-Draine2003.lnk diff --git a/lnk_data/ad/c-gra-z-Draine2003.lnk b/src/optool/lnk_data/ad/c-gra-z-Draine2003.lnk similarity index 100% rename from lnk_data/ad/c-gra-z-Draine2003.lnk rename to src/optool/lnk_data/ad/c-gra-z-Draine2003.lnk diff --git a/lnk_data/ad/ol-c-mg00-x-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg00-x-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg00-x-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg00-x-Fabian2001.lnk diff --git a/lnk_data/ad/ol-c-mg00-y-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg00-y-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg00-y-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg00-y-Fabian2001.lnk diff --git a/lnk_data/ad/ol-c-mg00-z-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg00-z-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg00-z-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg00-z-Fabian2001.lnk diff --git a/lnk_data/ad/ol-c-mg100-x-Suto2006.lnk b/src/optool/lnk_data/ad/ol-c-mg100-x-Suto2006.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg100-x-Suto2006.lnk rename to src/optool/lnk_data/ad/ol-c-mg100-x-Suto2006.lnk diff --git a/lnk_data/ad/ol-c-mg100-y-Suto2006.lnk b/src/optool/lnk_data/ad/ol-c-mg100-y-Suto2006.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg100-y-Suto2006.lnk rename to src/optool/lnk_data/ad/ol-c-mg100-y-Suto2006.lnk diff --git a/lnk_data/ad/ol-c-mg100-z-Suto2006.lnk b/src/optool/lnk_data/ad/ol-c-mg100-z-Suto2006.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg100-z-Suto2006.lnk rename to src/optool/lnk_data/ad/ol-c-mg100-z-Suto2006.lnk diff --git a/lnk_data/ad/ol-c-mg95-x-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg95-x-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg95-x-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg95-x-Fabian2001.lnk diff --git a/lnk_data/ad/ol-c-mg95-y-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg95-y-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg95-y-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg95-y-Fabian2001.lnk diff --git a/lnk_data/ad/ol-c-mg95-z-Fabian2001.lnk b/src/optool/lnk_data/ad/ol-c-mg95-z-Fabian2001.lnk similarity index 100% rename from lnk_data/ad/ol-c-mg95-z-Fabian2001.lnk rename to src/optool/lnk_data/ad/ol-c-mg95-z-Fabian2001.lnk diff --git a/lnk_data/ad/pyr-c-mg96-x-Jaeger1998.lnk b/src/optool/lnk_data/ad/pyr-c-mg96-x-Jaeger1998.lnk similarity index 100% rename from lnk_data/ad/pyr-c-mg96-x-Jaeger1998.lnk rename to src/optool/lnk_data/ad/pyr-c-mg96-x-Jaeger1998.lnk diff --git a/lnk_data/ad/pyr-c-mg96-y-Jaeger1998.lnk b/src/optool/lnk_data/ad/pyr-c-mg96-y-Jaeger1998.lnk similarity index 100% rename from lnk_data/ad/pyr-c-mg96-y-Jaeger1998.lnk rename to src/optool/lnk_data/ad/pyr-c-mg96-y-Jaeger1998.lnk diff --git a/lnk_data/ad/pyr-c-mg96-z-Jaeger1998.lnk b/src/optool/lnk_data/ad/pyr-c-mg96-z-Jaeger1998.lnk similarity index 100% rename from lnk_data/ad/pyr-c-mg96-z-Jaeger1998.lnk rename to src/optool/lnk_data/ad/pyr-c-mg96-z-Jaeger1998.lnk diff --git a/lnk_data/astrosil-Draine2003.lnk b/src/optool/lnk_data/astrosil-Draine2003.lnk similarity index 100% rename from lnk_data/astrosil-Draine2003.lnk rename to src/optool/lnk_data/astrosil-Draine2003.lnk diff --git a/lnk_data/c-gra-Draine2003.lnk b/src/optool/lnk_data/c-gra-Draine2003.lnk similarity index 100% rename from lnk_data/c-gra-Draine2003.lnk rename to src/optool/lnk_data/c-gra-Draine2003.lnk diff --git a/lnk_data/c-nano-Mutschke2004.lnk b/src/optool/lnk_data/c-nano-Mutschke2004.lnk similarity index 100% rename from lnk_data/c-nano-Mutschke2004.lnk rename to src/optool/lnk_data/c-nano-Mutschke2004.lnk diff --git a/lnk_data/c-org-Henning1996.lnk b/src/optool/lnk_data/c-org-Henning1996.lnk similarity index 100% rename from lnk_data/c-org-Henning1996.lnk rename to src/optool/lnk_data/c-org-Henning1996.lnk diff --git a/lnk_data/c-p-Preibisch1993.lnk b/src/optool/lnk_data/c-p-Preibisch1993.lnk similarity index 100% rename from lnk_data/c-p-Preibisch1993.lnk rename to src/optool/lnk_data/c-p-Preibisch1993.lnk diff --git a/lnk_data/c-z-Zubko1996.lnk b/src/optool/lnk_data/c-z-Zubko1996.lnk similarity index 100% rename from lnk_data/c-z-Zubko1996.lnk rename to src/optool/lnk_data/c-z-Zubko1996.lnk diff --git a/lnk_data/ch3oh-a-Gerakines2020.lnk b/src/optool/lnk_data/ch3oh-a-Gerakines2020.lnk similarity index 100% rename from lnk_data/ch3oh-a-Gerakines2020.lnk rename to src/optool/lnk_data/ch3oh-a-Gerakines2020.lnk diff --git a/lnk_data/ch3oh-c-Gerakines2020.lnk b/src/optool/lnk_data/ch3oh-c-Gerakines2020.lnk similarity index 100% rename from lnk_data/ch3oh-c-Gerakines2020.lnk rename to src/optool/lnk_data/ch3oh-c-Gerakines2020.lnk diff --git a/lnk_data/ch4-a-Gerakines2020.lnk b/src/optool/lnk_data/ch4-a-Gerakines2020.lnk similarity index 100% rename from lnk_data/ch4-a-Gerakines2020.lnk rename to src/optool/lnk_data/ch4-a-Gerakines2020.lnk diff --git a/lnk_data/ch4-c-Gerakines2020.lnk b/src/optool/lnk_data/ch4-c-Gerakines2020.lnk similarity index 100% rename from lnk_data/ch4-c-Gerakines2020.lnk rename to src/optool/lnk_data/ch4-c-Gerakines2020.lnk diff --git a/lnk_data/co-a-Palumbo2006.lnk b/src/optool/lnk_data/co-a-Palumbo2006.lnk similarity index 100% rename from lnk_data/co-a-Palumbo2006.lnk rename to src/optool/lnk_data/co-a-Palumbo2006.lnk diff --git a/lnk_data/co2-a-Gerakines2020.lnk b/src/optool/lnk_data/co2-a-Gerakines2020.lnk similarity index 100% rename from lnk_data/co2-a-Gerakines2020.lnk rename to src/optool/lnk_data/co2-a-Gerakines2020.lnk diff --git a/lnk_data/co2-c-Gerakines2020.lnk b/src/optool/lnk_data/co2-c-Gerakines2020.lnk similarity index 100% rename from lnk_data/co2-c-Gerakines2020.lnk rename to src/optool/lnk_data/co2-c-Gerakines2020.lnk diff --git a/lnk_data/co2-w-Warren1986.lnk b/src/optool/lnk_data/co2-w-Warren1986.lnk similarity index 100% rename from lnk_data/co2-w-Warren1986.lnk rename to src/optool/lnk_data/co2-w-Warren1986.lnk diff --git a/lnk_data/cor-c-Koike1995.lnk b/src/optool/lnk_data/cor-c-Koike1995.lnk similarity index 100% rename from lnk_data/cor-c-Koike1995.lnk rename to src/optool/lnk_data/cor-c-Koike1995.lnk diff --git a/lnk_data/fe-c-Henning1996.lnk b/src/optool/lnk_data/fe-c-Henning1996.lnk similarity index 100% rename from lnk_data/fe-c-Henning1996.lnk rename to src/optool/lnk_data/fe-c-Henning1996.lnk diff --git a/lnk_data/fes-Henning1996.lnk b/src/optool/lnk_data/fes-Henning1996.lnk similarity index 100% rename from lnk_data/fes-Henning1996.lnk rename to src/optool/lnk_data/fes-Henning1996.lnk diff --git a/lnk_data/h2o-a-Hudgins1993.lnk b/src/optool/lnk_data/h2o-a-Hudgins1993.lnk similarity index 100% rename from lnk_data/h2o-a-Hudgins1993.lnk rename to src/optool/lnk_data/h2o-a-Hudgins1993.lnk diff --git a/lnk_data/h2o-w-Warren2008.lnk b/src/optool/lnk_data/h2o-w-Warren2008.lnk similarity index 100% rename from lnk_data/h2o-w-Warren2008.lnk rename to src/optool/lnk_data/h2o-w-Warren2008.lnk diff --git a/lnk_data/lnk-help.txt b/src/optool/lnk_data/lnk-help.txt similarity index 100% rename from lnk_data/lnk-help.txt rename to src/optool/lnk_data/lnk-help.txt diff --git a/lnk_data/nh3-m-Martonchik1983.lnk b/src/optool/lnk_data/nh3-m-Martonchik1983.lnk similarity index 100% rename from lnk_data/nh3-m-Martonchik1983.lnk rename to src/optool/lnk_data/nh3-m-Martonchik1983.lnk diff --git a/lnk_data/ol-c-mg00-Fabian2001.lnk b/src/optool/lnk_data/ol-c-mg00-Fabian2001.lnk similarity index 100% rename from lnk_data/ol-c-mg00-Fabian2001.lnk rename to src/optool/lnk_data/ol-c-mg00-Fabian2001.lnk diff --git a/lnk_data/ol-c-mg100-Suto2006.lnk b/src/optool/lnk_data/ol-c-mg100-Suto2006.lnk similarity index 100% rename from lnk_data/ol-c-mg100-Suto2006.lnk rename to src/optool/lnk_data/ol-c-mg100-Suto2006.lnk diff --git a/lnk_data/ol-c-mg95-Fabian2001.lnk b/src/optool/lnk_data/ol-c-mg95-Fabian2001.lnk similarity index 100% rename from lnk_data/ol-c-mg95-Fabian2001.lnk rename to src/optool/lnk_data/ol-c-mg95-Fabian2001.lnk diff --git a/lnk_data/ol-mg40-Dorschner1995.lnk b/src/optool/lnk_data/ol-mg40-Dorschner1995.lnk similarity index 100% rename from lnk_data/ol-mg40-Dorschner1995.lnk rename to src/optool/lnk_data/ol-mg40-Dorschner1995.lnk diff --git a/lnk_data/ol-mg50-Dorschner1995.lnk b/src/optool/lnk_data/ol-mg50-Dorschner1995.lnk similarity index 100% rename from lnk_data/ol-mg50-Dorschner1995.lnk rename to src/optool/lnk_data/ol-mg50-Dorschner1995.lnk diff --git a/lnk_data/pyr-c-mg96-Jaeger1998.lnk b/src/optool/lnk_data/pyr-c-mg96-Jaeger1998.lnk similarity index 100% rename from lnk_data/pyr-c-mg96-Jaeger1998.lnk rename to src/optool/lnk_data/pyr-c-mg96-Jaeger1998.lnk diff --git a/lnk_data/pyr-mg100-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg100-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg100-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg100-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg40-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg40-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg40-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg40-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg50-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg50-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg50-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg50-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg60-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg60-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg60-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg60-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg70-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg70-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg70-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg70-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg80-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg80-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg80-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg80-Dorschner1995.lnk diff --git a/lnk_data/pyr-mg95-Dorschner1995.lnk b/src/optool/lnk_data/pyr-mg95-Dorschner1995.lnk similarity index 100% rename from lnk_data/pyr-mg95-Dorschner1995.lnk rename to src/optool/lnk_data/pyr-mg95-Dorschner1995.lnk diff --git a/lnk_data/retired/README b/src/optool/lnk_data/retired/README similarity index 100% rename from lnk_data/retired/README rename to src/optool/lnk_data/retired/README diff --git a/lnk_data/retired/ol-c-mg100-Steyer1974.lnk b/src/optool/lnk_data/retired/ol-c-mg100-Steyer1974.lnk similarity index 100% rename from lnk_data/retired/ol-c-mg100-Steyer1974.lnk rename to src/optool/lnk_data/retired/ol-c-mg100-Steyer1974.lnk diff --git a/lnk_data/sic-Draine1993.lnk b/src/optool/lnk_data/sic-Draine1993.lnk similarity index 100% rename from lnk_data/sic-Draine1993.lnk rename to src/optool/lnk_data/sic-Draine1993.lnk diff --git a/lnk_data/sio2-Kitamura2007.lnk b/src/optool/lnk_data/sio2-Kitamura2007.lnk similarity index 100% rename from lnk_data/sio2-Kitamura2007.lnk rename to src/optool/lnk_data/sio2-Kitamura2007.lnk diff --git a/maint/RELEASE b/src/optool/maint/RELEASE similarity index 100% rename from maint/RELEASE rename to src/optool/maint/RELEASE diff --git a/maint/all_k.pdf b/src/optool/maint/all_k.pdf similarity index 100% rename from maint/all_k.pdf rename to src/optool/maint/all_k.pdf diff --git a/maint/bake_manual.el b/src/optool/maint/bake_manual.el similarity index 100% rename from maint/bake_manual.el rename to src/optool/maint/bake_manual.el diff --git a/maint/bake_manual.pl b/src/optool/maint/bake_manual.pl similarity index 100% rename from maint/bake_manual.pl rename to src/optool/maint/bake_manual.pl diff --git a/maint/ingestlnk.pl b/src/optool/maint/ingestlnk.pl similarity index 100% rename from maint/ingestlnk.pl rename to src/optool/maint/ingestlnk.pl diff --git a/maint/inspect.png b/src/optool/maint/inspect.png similarity index 100% rename from maint/inspect.png rename to src/optool/maint/inspect.png diff --git a/maint/notes.org b/src/optool/maint/notes.org similarity index 100% rename from maint/notes.org rename to src/optool/maint/notes.org diff --git a/maint/plotall.py b/src/optool/maint/plotall.py similarity index 100% rename from maint/plotall.py rename to src/optool/maint/plotall.py diff --git a/maint/ref_ind.template b/src/optool/maint/ref_ind.template similarity index 100% rename from maint/ref_ind.template rename to src/optool/maint/ref_ind.template diff --git a/maint/run_examples b/src/optool/maint/run_examples similarity index 100% rename from maint/run_examples rename to src/optool/maint/run_examples diff --git a/maint/selftest.pl b/src/optool/maint/selftest.pl similarity index 100% rename from maint/selftest.pl rename to src/optool/maint/selftest.pl diff --git a/optool-complete b/src/optool/optool-complete similarity index 100% rename from optool-complete rename to src/optool/optool-complete diff --git a/optool.bib b/src/optool/optool.bib similarity index 100% rename from optool.bib rename to src/optool/optool.bib diff --git a/optool.f90 b/src/optool/optool.f90 similarity index 100% rename from optool.f90 rename to src/optool/optool.f90 diff --git a/optool.py b/src/optool/optool.py similarity index 96% rename from optool.py rename to src/optool/optool.py index b4605ca..923dacf 100644 --- a/optool.py +++ b/src/optool/optool.py @@ -1,4 +1,6 @@ -"""NAME +#!/bin/sh python3 +r""" +NAME optool DESCRIPTION @@ -15,7 +17,7 @@ and plot the results import optool - p = optool.particle(ā€™~/bin/optool pyr 0.8 -m ice 0.2 -na 24 -dā€™) + p = optool.particle('~/bin/optool pyr 0.8 -m ice 0.2 -na 24 -d') p.plot() Read opacity files produced earlier by a run of optool. This is @@ -87,11 +89,13 @@ import os import shutil import subprocess -from distutils.spawn import find_executable import tempfile +import pathlib + class particle: - """Run optool and turn output into a python object. + """ + Run optool and turn output into a python object. Provides an interface to the optool program for computing dust opacities. The optool program can be found on GitHub, at this address: @@ -185,7 +189,8 @@ class particle: Compute opacity of a size distribution of elements of SELF """ def __init__(self,cmd,cache='',silent=False): - """Create a new optool.particle opject. + """ + Create a new optool.particle object. Parameters ---------= @@ -199,7 +204,7 @@ def __init__(self,cmd,cache='',silent=False): the second parameter CACHE. cache : str, optional - The diretory to cache the optool output files in, so that + The directory to cache the optool output files in, so that they can be read instead of recomputed the next time the same command is used. The cache is automatically cleared when CMD changes between runs. @@ -226,13 +231,13 @@ def __init__(self,cmd,cache='',silent=False): # No command, just read directory if not silent: print("Reading files in directory:",cache,"...") - # Set cmd to the emty string, to signal not to run a command + # Set cmd to the empty string, to signal not to run a command cmd = '' elif (cache and checkcmd(cache,self.cmd)): # Directory was created by the exact same command - just read if not silent: print("Using result cache in directory:",cache,"...") - # Set cmd to the emty string, to signal not to run a command + # Set cmd to the empty string, to signal not to run a command cmd = '' else: # Convert command string into list if necessary @@ -243,35 +248,39 @@ def __init__(self,cmd,cache='',silent=False): cmd[0] = os.path.expanduser(cmd[0]) # Find the optool executable - bin = find_executable(cmd[0]) - if (not bin): + executable = shutil.which(cmd[0]) + if (not executable): + # Probably the executable is in the same directory as the module + module_path = pathlib.Path(__file__).parent.resolve() + executable = shutil.which(f"{module_path}/{cmd[0]}") + if (not executable): raise RuntimeError("Executable not found: "+cmd[0]) # Wrap the main part into try - finally to make sure we clean up try: if (cache): - dir = cache + directory = cache else: # create temporary directory in /tmp/ - dir = tempfile.mkdtemp(prefix="optool_") + directory = tempfile.mkdtemp(prefix="optool_") if cmd: if cache: # make sure directory is new and empty - shutil.rmtree(dir,ignore_errors=True) - os.mkdir(dir) + shutil.rmtree(directory,ignore_errors=True) + os.mkdir(directory) # Store the command line we are using. We store the # string version of the command, not the list version. - writecmd(dir,self.cmd) + writecmd(directory,self.cmd) # tell optool to use the directory as writing desination - cmd.append('-o'); cmd.append(dir) + cmd.append('-o'); cmd.append(directory) # Run optool to produce the opacities stdout = subprocess.DEVNULL if silent else None stderr = subprocess.DEVNULL if silent else None - cmd[0] = bin; subprocess.Popen(cmd, stdout=stdout, stderr=stderr).wait() + cmd[0] = executable; subprocess.Popen(cmd, stdout=stdout, stderr=stderr).wait() # Check if there is output we can use - scat,ext,translate = check_for_output(dir) + scat,ext,translate = check_for_output(directory) self.scat = scat self.massscale = 1. @@ -283,9 +292,9 @@ def __init__(self,cmd,cache='',silent=False): for i in range(5000): if scat: - file = ("%s/dustkapscatmat_%03d.%s") % (dir,(i+1),ext) + file = ("%s/dustkapscatmat_%03d.%s") % (directory,(i+1),ext) else: - file = ("%s/dustkappa_%03d.%s") % (dir,(i+1),ext) + file = ("%s/dustkappa_%03d.%s") % (directory,(i+1),ext) file = translate.get(file,file) if (not os.path.exists(file)): break nfiles = nfiles+1 @@ -327,11 +336,11 @@ def __init__(self,cmd,cache='',silent=False): finally: if cache: if not silent: - print("Files remain available in directory: "+dir) + print("Files remain available in directory: "+directory) else: if not silent: - print("Cleaning up temporary directory "+dir) - shutil.rmtree(dir) + print("Cleaning up temporary directory "+directory) + shutil.rmtree(directory) def plot(self,minkap=1e0): """Create interactive plots of the opacities in SELF. @@ -441,7 +450,7 @@ def plotpi(self,ymin=None,ymax=None): def select(self,i): """Select just one bin from a multi-particle object. - A multi-particle opject is produced when running optool with + A multi-particle object is produced when running optool with a -d switch. This is useful for doing particle arithmetic, which only works for @@ -1111,18 +1120,18 @@ def logscale_with_sign(array,bottom): array[b] = -np.log10(-array[b]+bottom) + lb return array -def check_for_output(dir): +def check_for_output(directory): # Check for and if necessary rename input files for ext in['dat','inp']: - if (os.path.exists(dir+'/dustkapscatmat_001.'+ext)): + if (os.path.exists(directory+'/dustkapscatmat_001.'+ext)): return True, ext, dict() - elif (os.path.exists(dir+'/dustkappa_001.'+ext)): + elif (os.path.exists(directory+'/dustkappa_001.'+ext)): return False, ext, dict() - elif (os.path.exists(dir+'/dustkapscatmat.'+ext)): - return True, ext, { dir+'/dustkapscatmat_001.'+ext : dir+'/dustkapscatmat.'+ext } - elif (os.path.exists(dir+'/dustkappa.'+ext)): - return False, ext, { dir+'/dustkappa_001.'+ext : dir+'/dustkappa.'+ext } - raise RuntimeError(f"No valid OpTool output files found in directory {dir}") + elif (os.path.exists(directory+'/dustkapscatmat.'+ext)): + return True, ext, { directory+'/dustkapscatmat_001.'+ext : directory+'/dustkapscatmat.'+ext } + elif (os.path.exists(directory+'/dustkappa.'+ext)): + return False, ext, { directory+'/dustkappa_001.'+ext : directory+'/dustkappa.'+ext } + raise RuntimeError(f"No valid OpTool output files found in directory {directory}") def parse_headers(headers,b): # Extract information on run parameters from headers @@ -1268,13 +1277,13 @@ def readoutputfile(file,scat,silent=False): else: return [header,lam,kabs,ksca,phase_g] -def writecmd(dir,cmd): +def writecmd(directory,cmd): """Store the CMD string in file DIR/cmd. """ - if (os.path.isdir(dir)): + if (os.path.isdir(directory)): # Directory does not exist - dir = dir.rstrip('/') - filename = dir+"/cmd" + directory = directory.rstrip('/') + filename = directory+"/cmd" try: wfile = open(filename, 'w') except: @@ -1287,23 +1296,23 @@ def writecmd(dir,cmd): else: return False -def checkcmd(dir,cmd): +def checkcmd(directory,cmd): """Check if new command line is the same as the old one. This functions checks if the directory DIR contains a file - called CMD, and if the first line in thie directory is the + called CMD, and if the first line in this directory is the same as the string passed with the DIR parameter. """ - if (not os.path.isdir(dir)): + if (not os.path.isdir(directory)): # Directory does not exist return False - if (len(os.listdir(dir))<=1): + if (len(os.listdir(directory))<=1): # There are less than one file in the directory. So either the cmd # file does not exist, or no output files are present. return False - dir = dir.rstrip('/') - filename = dir+"/cmd" - if (not os.path.exists(dir+"/cmd")): + directory = directory.rstrip('/') + filename = directory+"/cmd" + if (not os.path.exists(directory+"/cmd")): # The command file does not exist return False try: diff --git a/optool2tex b/src/optool/optool2tex similarity index 100% rename from optool2tex rename to src/optool/optool2tex diff --git a/optool_fractal.f90 b/src/optool/optool_fractal.f90 similarity index 100% rename from optool_fractal.f90 rename to src/optool/optool_fractal.f90 diff --git a/optool_geofractal.f90 b/src/optool/optool_geofractal.f90 similarity index 100% rename from optool_geofractal.f90 rename to src/optool/optool_geofractal.f90 diff --git a/optool_guts.f90 b/src/optool/optool_guts.f90 similarity index 100% rename from optool_guts.f90 rename to src/optool/optool_guts.f90 diff --git a/optool_manual.f90 b/src/optool/optool_manual.f90 similarity index 100% rename from optool_manual.f90 rename to src/optool/optool_manual.f90 diff --git a/optool_refind.f90 b/src/optool/optool_refind.f90 similarity index 100% rename from optool_refind.f90 rename to src/optool/optool_refind.f90