Skip to content

Commit

Permalink
add header, format with black, update action runners, #172
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 29, 2023
1 parent 3a4e966 commit 527a5cc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_macos_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
build_macos_wheels:
name: Build macOS wheels
runs-on: macos-10.15
runs-on: macos-11
strategy:
matrix:
python_version: [ '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9' ]
Expand Down
5 changes: 3 additions & 2 deletions pmcx/pmcx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
except ImportError: # pragma: no cover
print("the pmcx binary extension (_pmcx) is not compiled! please compile first")

# from .utils import detweight
from .utils import detweight, cwdref

# from .files import loadmc2, loadmch, load, save
from .bench import bench

__version__ = "0.0.13"

__all__ = ("gpuinfo", "run", "bench")
__all__ = ("gpuinfo", "run", "bench", "detweight", "cwdref")
2 changes: 1 addition & 1 deletion pmcx/pmcx/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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/>.

"""BJData (Draft 2) and UBJSON encoder"""
"""Built-in benchmark configurations"""

import numpy as np
import copy
Expand Down
73 changes: 47 additions & 26 deletions pmcx/pmcx/utils.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
# Copyright (c) 2023 Kuznetsov Ilya
# Copyright (c) 2023 Qianqian Fang (q.fang <at> neu.edu)
# Copyright (c) 2023 Shijie Yan (yan.shiji <at> northeastern.edu)
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""Utilities for processing MCX input and output data"""


import numpy as np


def detweight(detp, prop):
"""
Recalculate the detected photon weight using partial path data and
Recalculate the detected photon weight using partial path data and
optical properties (for perturbation Monte Carlo or detector readings)
author: Qianqian Fang (q.fang <at> neu.edu)
translated to python: Kuznetsov Ilya
author: Kuznetsov Ilya
Python code was adapted from mcxdetweight.m MATLAB function written by Qianqian Fang (q.fang <at> neu.edu)
input:
detp: the 2nd output from mcxlab. detp must be a dict
prop: optical property list, as defined in the cfg['prop'] field of mcxlab's input
unitinmm: voxel edge-length in mm, should use cfg['unitinmm'] used to generate detp;
unitinmm: voxel edge-length in mm, should use cfg['unitinmm'] used to generate detp;
if ignored, assume to be 1 (mm)
output:
detw: re-caculated detected photon weight based on the partial path data and optical property table
License: GPLv3, see http://mcx.space/ for details
License: GPLv3, see https://mcx.space/ for details
"""

if 'prop' in detp:
prop = detp['prop']
if "prop" in detp:
prop = detp["prop"]

medianum = prop.shape[0]
if medianum <= 1:
raise ValueError('empty property list')
raise ValueError("empty property list")

if unitinmm is None:
if 'unitinmm' in detp:
unitinmm = detp['unitinmm']
if "unitinmm" in detp:
unitinmm = detp["unitinmm"]
else:
unitinmm = 1

if isinstance(detp, dict):
if 'w0' not in detp:
detw = np.ones(detp['ppath'].shape[0])
if "w0" not in detp:
detw = np.ones(detp["ppath"].shape[0])
else:
detw = detp['w0']
detw = detp["w0"]

for i in range(medianum - 1):
detw *= np.exp(-prop[i + 1, 0] * detp['ppath'][:, i] * unitinmm)
detw *= np.exp(-prop[i + 1, 0] * detp["ppath"][:, i] * unitinmm)
else:
raise ValueError('the first input must be a dict with a key named "ppath"')

Expand All @@ -52,8 +73,8 @@ def cwdref(detp, cfg):
"""
Compute CW diffuse reflectance from MC detected photon profiles.
author: Shijie Yan (yan.shiji <at> northeastern.edu)
translated to python: Kuznetsov Ilya
author: Kuznetsov Ilya
Python code was adapted from mcxcwdref.m MATLAB function written by Shijie Yan (yan.shiji <at> northeastern.edu)
input:
detp: profiles of detected photons
Expand All @@ -64,23 +85,23 @@ def cwdref(detp, cfg):
dref: CW diffuse reflectance at detectors
this file is part of Monte Carlo eXtreme (MCX)
License: GPLv3, see http://mcx.sf.net for details
License: GPLv3, see https://mcx.space for details
see Yao2018
"""

unitinmm = 1
if 'unitinmm' in cfg:
unitinmm = cfg['unitinmm']
if "unitinmm" in cfg:
unitinmm = cfg["unitinmm"]

det_weight = detweight(detp, cfg['prop'])
detnum = len(np.unique(detp['detid']))
det_weight = detweight(detp, cfg["prop"])
detnum = len(np.unique(detp["detid"]))
detweightsum = np.zeros(detnum)

for i in range(len(detp['detid'])):
index = int(detp['detid'][i]) - 1
for i in range(len(detp["detid"])):
index = int(detp["detid"][i]) - 1
detweightsum[index] += det_weight[i]

area = np.pi * (cfg['detpos'][:, 3] * unitinmm) ** 2
dref = detweightsum / area / cfg['nphoton']
area = np.pi * (cfg["detpos"][:, 3] * unitinmm) ** 2
dref = detweightsum / area / cfg["nphoton"]

return dref
return dref
2 changes: 1 addition & 1 deletion pymcx
2 changes: 1 addition & 1 deletion src/pybind11
Submodule pybind11 updated 79 files
+65 −61 .clang-tidy
+5 −3 .github/CONTRIBUTING.md
+0 −4 .github/dependabot.yml
+40 −23 .github/workflows/ci.yml
+1 −1 .github/workflows/configure.yml
+6 −4 .github/workflows/format.yml
+7 −5 .github/workflows/pip.yml
+3 −3 .github/workflows/upstream.yml
+14 −11 .pre-commit-config.yaml
+13 −0 CMakeLists.txt
+3 −0 docs/_static/css/custom.css
+0 −11 docs/_static/theme_overrides.css
+2 −2 docs/advanced/cast/custom.rst
+3 −3 docs/advanced/cast/stl.rst
+2 −2 docs/advanced/classes.rst
+2 −2 docs/advanced/pycpp/numpy.rst
+1 −1 docs/advanced/smart_ptrs.rst
+160 −12 docs/changelog.rst
+1 −1 docs/classes.rst
+6 −17 docs/conf.py
+ docs/pybind11-logo.png
+4 −3 docs/requirements.txt
+5 −3 include/pybind11/attr.h
+5 −5 include/pybind11/cast.h
+23 −30 include/pybind11/detail/class.h
+21 −2 include/pybind11/detail/common.h
+1 −1 include/pybind11/detail/init.h
+1 −0 include/pybind11/detail/internals.h
+0 −66 include/pybind11/detail/type_caster_base.h
+9 −3 include/pybind11/detail/typeid.h
+17 −6 include/pybind11/eigen.h
+56 −32 include/pybind11/embed.h
+2 −2 include/pybind11/functional.h
+1 −1 include/pybind11/iostream.h
+19 −8 include/pybind11/numpy.h
+44 −26 include/pybind11/pybind11.h
+338 −64 include/pybind11/pytypes.h
+6 −6 include/pybind11/stl.h
+16 −6 noxfile.py
+2 −1 pybind11/__init__.py
+8 −1 pybind11/__main__.py
+1 −1 pybind11/_version.py
+12 −0 pybind11/commands.py
+2 −1 setup.cfg
+1 −0 setup.py
+1 −0 tests/CMakeLists.txt
+14 −1 tests/conftest.py
+51 −0 tests/cross_module_interleaved_error_already_set.cpp
+68 −58 tests/extra_python_package/test_files.py
+25 −0 tests/pybind11_tests.cpp
+1 −1 tests/requirements.txt
+8 −2 tests/test_builtin_casters.cpp
+2 −2 tests/test_constants_and_functions.cpp
+7 −7 tests/test_custom_type_casters.cpp
+5 −2 tests/test_eigen.cpp
+7 −0 tests/test_eigen.py
+1 −1 tests/test_embed/CMakeLists.txt
+47 −2 tests/test_exceptions.cpp
+99 −3 tests/test_exceptions.py
+10 −1 tests/test_kwargs_and_defaults.cpp
+21 −9 tests/test_methods_and_attributes.py
+2 −0 tests/test_modules.cpp
+30 −0 tests/test_modules.py
+1 −1 tests/test_numpy_array.cpp
+1 −1 tests/test_numpy_dtypes.cpp
+1 −1 tests/test_numpy_vectorize.cpp
+183 −0 tests/test_pytypes.cpp
+129 −0 tests/test_pytypes.py
+2 −2 tests/test_smart_ptr.cpp
+15 −8 tests/test_stl.cpp
+2 −2 tests/test_tagbased_polymorphic.cpp
+2 −3 tests/test_virtual_functions.cpp
+21 −11 tools/FindPythonLibsNew.cmake
+23 −0 tools/JoinPaths.cmake
+7 −0 tools/pybind11.pc.in
+3 −1 tools/pybind11NewTools.cmake
+32 −11 tools/pybind11Tools.cmake
+2 −0 tools/setup_global.py.in
+2 −0 tools/setup_main.py.in

0 comments on commit 527a5cc

Please sign in to comment.