Skip to content

Commit

Permalink
Shuffle to src-layout, with a) an additional pytools pkg and b) a pyt…
Browse files Browse the repository at this point in the history
…ools dummy module in root for backwards compatibility
  • Loading branch information
alhom committed Dec 18, 2024
1 parent 47c6b39 commit ba4b093
Show file tree
Hide file tree
Showing 123 changed files with 180 additions and 156 deletions.
18 changes: 0 additions & 18 deletions __init__.py

This file was deleted.

41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "analysator"
version = "0.9.6"
authors = [
{ name = "Markku Alho", email = "[email protected]"},
{ name = "Et al"},
]
maintainters = [
{ name = "Markku Alho", email = "[email protected]"},
]
description = "Tools for reading and analysing Vlasiator .vlsv output files."
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: OS Independent",
]
dependencies = [
"numpy",
"scipy",
"matplotlib",
]
[project.optional-dependencies]
isosurface = [
"scikit-image",
]

[project.urls]
Homepage = "https://github.com/fmihpc/analysator"
Issues = "https://github.com/fmihpc/analysator/issues"

[tool.hatch.build.targets.wheel]
packages = ["src/analysator","src/fytools"]

[tool.hatch.build.targets.sdist]
packages = ["src/analysator","src/fytools"]
110 changes: 16 additions & 94 deletions pytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,104 +21,26 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

import filemanagement
import socket, re, os, tempfile, atexit, shutil
from os import path as __path
import warnings
import sys
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=os.environ.get('ANALYSATOR_LOG_LEVEL', 'INFO').upper())

# Input current folder's path
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)))
# Input folder paths
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "miscellaneous")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyCalculations")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyCellDataReduction")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyPlots")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyVisit")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyVlsv")
if os.getenv('PTMAYAVI2') != None:
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyMayaVi")


# Make sure matplotlib has a unique temp directory
mpldir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, mpldir)
os.environ['MPLCONFIGDIR']=mpldir

# Check if user is on taito.csc.fi without loading the mayavi2 module
import numpy as np
import matplotlib
if matplotlib.__version__=="0.99.1.1" and np.__version__=="1.4.1":
logging.info('Warning, according to loaded numpy and matplotlib versions, user appears to be')
logging.info('either using csc.taito.fi without loading the mayavi2 module, or by invoking')
logging.info('the system python interpeter by calling "./scriptname.py" instead of "python ./scriptname.py"')

# Run TeX typesetting through the full TeX engine instead of python's own mathtext. Allows
# for changing fonts, bold math symbols etc, but may cause trouble on some systems.
if not os.getenv('PTNOLATEX'):
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble'] = r'\boldmath'
# matplotlib.rcParams['mathtext.fontset'] = 'stix'
# matplotlib.rcParams['font.family'] = 'STIXGeneral'
# Matplotlib suppressed logging messages came out after enabling logging.INFO: font.family must be one of (serif, sans-serif, cursive, monospace) when text.usetex is True. serif will be used by default.
matplotlib.rcParams['font.family'] = 'serif'
logging.info("Using LaTeX formatting")
# matplotlib.rcParams['text.dvipnghack'] = 'True' # This hack might fix it on some systems

# Set backends
if matplotlib.get_backend()[:9] == 'module://':
logging.info("Using backend "+matplotlib.get_backend())
backend_interactive = matplotlib.get_backend()
backend_noninteractive = matplotlib.get_backend()
elif not os.getenv('PTBACKEND'):
backend_interactive = 'TkAgg'
backend_noninteractive = 'Agg'
# Slurp and exec the analysator.py file here to get all functionalities under the pytools alias if needed
if 'analysator' not in sys.modules.keys():
warnings.warn("Please update your import command to `import analysator as pt`. `pytools.py` has been renamed as `analysator.py` for consistency and eventual package publication. `import pytools` and `import pytools as pt` will work via the dirty hack here in `pytools.py` until some time in the future (v.1 release/package publication?).")
logging.info("Importing analysator.py to pytools")
root = __path.dirname(__file__)
# with open(__path.join(root,'src/analysator/__init__.py'),'r') as f:
# source = f.read()
# exec(source)
# f.close()
# del f
sys.path.append(__path.join(root,"src/"))
from analysator import *
else:
backend_interactive = os.getenv('PTBACKEND')
backend_noninteractive = os.getenv('PTBACKEND')

# Import modules
try:
import calculations
except ImportError as e:
logging.info("Note: Did not import calculations module: " + str(e))

try:
import vlsvfile
except ImportError as e:
logging.info("Note: Did not import vlsvfile module: " + str(e))

import os
import matplotlib.pyplot as plt

if os.getenv('PTNONINTERACTIVE') != None:
# Non-interactive plotting mode
try:
plt.switch_backend(backend_noninteractive)
except:
logging.info("Note: Unable to switch to "+backend_noninteractive+" backend")
else:
# Interactive plotting mode
plt.ion()
try:
plt.switch_backend(backend_interactive)
except:
logging.info("Note: Unable to switch to "+backend_interactive+" backend")

#Only attempt loading MayaVi2 if requested
if os.getenv('PTMAYAVI2') != None:
try:
import grid
except ImportError as e:
logging.info("Note: Did not import (outdated MayaVi2) grid module: " + str(e))

try:
import plot
except ImportError as e:
logging.info("Note: Did not import plot module: " + str(e))

try:
import miscellaneous
except ImportError as e:
logging.info("Note: Did not import miscellaneous: " + str(e))

logging.info("Analysator imported already. Pointing pytools to analysator.")
sys.modules['pytools'] = sys.modules['analysator']
44 changes: 0 additions & 44 deletions pytools_dummy.py

This file was deleted.

122 changes: 122 additions & 0 deletions src/analysator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# __all__ = ["filemanagement"]
print("__init__ invoked")

import analysator.filemanagement as filemanagement
import socket, re, os, tempfile, atexit, shutil
import warnings
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=os.environ.get('ANALYSATOR_LOG_LEVEL', 'INFO').upper())

# Input current folder's path
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)))
# Input folder paths
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "miscellaneous")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyCalculations")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyCellDataReduction")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyPlots")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyVisit")
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyVlsv")
if os.getenv('PTMAYAVI2') != None:
filemanagement.sys.path.insert(0, filemanagement.os.path.dirname(filemanagement.os.path.abspath(__file__)) + "/" + "pyMayaVi")


# Make sure matplotlib has a unique temp directory
mpldir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, mpldir)
os.environ['MPLCONFIGDIR']=mpldir

# Check if user is on taito.csc.fi without loading the mayavi2 module
import numpy as np
import matplotlib
if matplotlib.__version__=="0.99.1.1" and np.__version__=="1.4.1":
logging.info('Warning, according to loaded numpy and matplotlib versions, user appears to be')
logging.info('either using csc.taito.fi without loading the mayavi2 module, or by invoking')
logging.info('the system python interpeter by calling "./scriptname.py" instead of "python ./scriptname.py"')

# Run TeX typesetting through the full TeX engine instead of python's own mathtext. Allows
# for changing fonts, bold math symbols etc, but may cause trouble on some systems.
if not os.getenv('PTNOLATEX'):
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble'] = r'\boldmath'
# matplotlib.rcParams['mathtext.fontset'] = 'stix'
# matplotlib.rcParams['font.family'] = 'STIXGeneral'
# Matplotlib suppressed logging messages came out after enabling logging.INFO: font.family must be one of (serif, sans-serif, cursive, monospace) when text.usetex is True. serif will be used by default.
matplotlib.rcParams['font.family'] = 'serif'
logging.info("Using LaTeX formatting")
# matplotlib.rcParams['text.dvipnghack'] = 'True' # This hack might fix it on some systems

# Set backends
if matplotlib.get_backend()[:9] == 'module://':
logging.info("Using backend "+matplotlib.get_backend())
backend_interactive = matplotlib.get_backend()
backend_noninteractive = matplotlib.get_backend()
elif not os.getenv('PTBACKEND'):
backend_interactive = 'TkAgg'
backend_noninteractive = 'Agg'
else:
backend_interactive = os.getenv('PTBACKEND')
backend_noninteractive = os.getenv('PTBACKEND')

# Import modules
try:
import calculations
except ImportError as e:
logging.info("Note: Did not import calculations module: " + str(e))

try:
import vlsvfile
except ImportError as e:
logging.info("Note: Did not import vlsvfile module: " + str(e))

import os
import matplotlib.pyplot as plt

if os.getenv('PTNONINTERACTIVE') != None:
# Non-interactive plotting mode
try:
plt.switch_backend(backend_noninteractive)
except:
logging.info("Note: Unable to switch to "+backend_noninteractive+" backend")
else:
# Interactive plotting mode
plt.ion()
try:
plt.switch_backend(backend_interactive)
except:
logging.info("Note: Unable to switch to "+backend_interactive+" backend")

#Only attempt loading MayaVi2 if requested
if os.getenv('PTMAYAVI2') != None:
try:
import grid
except ImportError as e:
logging.info("Note: Did not import (outdated MayaVi2) grid module: " + str(e))

try:
import plot
except ImportError as e:
logging.info("Note: Did not import plot module: " + str(e))

try:
import miscellaneous
except ImportError as e:
logging.info("Note: Did not import miscellaneous: " + str(e))



# from analysator.pytools import *
# import warnings
# warnings.filterwarnings("once", category=DeprecationWarning)
# warnings.filterwarnings("once", category=PendingDeprecationWarning)
# warnings.filterwarnings("once", category=FutureWarning)


# # from pytools import vslvfile

# from os import path as __path
# root = __path.dirname(__file__)
# with open(__path.join(root,'pytools.py'),'r') as f:
# source = f.read()
# exec(source)
# f.close()
# del f
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/pytools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from analysator import *

0 comments on commit ba4b093

Please sign in to comment.