generated from feelpp/feelpp-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
265 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
python/shadingmask/__init__.py → ktirio/shadingmask/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import matplotlib.cm as cm | ||
from pathlib import Path | ||
import os | ||
import plotly.graph_objs as go | ||
|
||
def plotShadingMask(csv_filename,save=True): | ||
|
||
# The CSV file must contain a comma-separated matrix of size | ||
# azimuth x altitude | ||
shading_test_values = np.genfromtxt(csv_filename, delimiter=',') | ||
|
||
if save: | ||
fig = plt.figure() | ||
|
||
# azimuth-latitude coordinates | ||
altitude = np.linspace(0, 90, shading_test_values.shape[1]+1) | ||
azimuth = np.linspace(0, 2*np.pi, shading_test_values.shape[0]+1) | ||
|
||
# Coordinate grid for the pcolormesh | ||
r, th = np.meshgrid(altitude, azimuth) | ||
|
||
ax1 = plt.subplot(projection="polar") | ||
plt.grid(False) | ||
|
||
im = plt.pcolormesh(th, r, shading_test_values, cmap=cm.gray_r , vmin=0, vmax=1) | ||
|
||
# Setting colorbar ticks | ||
v1 = np.linspace(0, 1, 11) | ||
cbar = plt.colorbar(im,ticks=v1) | ||
cbar.ax.set_yticklabels(["{:4.2f}".format(i) for i in v1]) # add the labels | ||
|
||
# Grid on azimuth: 0 is in the North position, | ||
# the axis is reverted with respect to usual polar coordinates | ||
# steps of 15° in the plot | ||
plt.thetagrids([i*15 for i in range(0,24)]) | ||
ax1.set_theta_direction(-1) | ||
ax1.set_theta_zero_location("N") | ||
|
||
# Grid on altitude: 0 is in the outer circle, | ||
# steps inwards of 10° in the plot | ||
plt.rgrids([i*10 for i in range(0,10)]) | ||
ax1.set_rlim(bottom=90, top=0) | ||
|
||
plt.savefig('Shading_mask'+Path(csv_filename).stem+'.png') | ||
plt.close() | ||
else: | ||
|
||
hovertemplate = ('Altitude: %{r}<br>' | ||
'Azimuth: %{theta}<br>' | ||
'Solar mask: %{customdata}<br>' | ||
'<extra></extra>') | ||
|
||
# azimuth-altitude coordinates | ||
r, theta = np.mgrid[0:90:shading_test_values.shape[1]+1j, 0:360:shading_test_values.shape[0]+1j] | ||
|
||
# Plotly polar representation of the shading mask | ||
fig = go.Figure(go.Barpolar( | ||
r=r.ravel(), | ||
theta=theta.ravel(), | ||
hovertemplate=hovertemplate, | ||
customdata=shading_test_values.ravel(order='F'), | ||
marker=dict( | ||
colorscale='gray', | ||
showscale=True, | ||
color=shading_test_values.ravel(order='F'), | ||
reversescale=True) | ||
) | ||
) | ||
|
||
fig.update_layout( | ||
title='', | ||
polar=dict( | ||
angularaxis=dict(tickvals=np.arange(0, 360, 15), | ||
direction='clockwise'), | ||
radialaxis=dict(angle=60, | ||
tickvals=[], | ||
autorange="reversed"), | ||
bargap=0 | ||
), | ||
|
||
) | ||
return fig | ||
|
||
|
||
def plotShadingMaskDir(directory_path): | ||
for root, dirs, files in os.walk(directory_path): | ||
for file in files: | ||
if file.endswith(".csv"): | ||
plotShadingMask(os.path.join(root,file)) |
File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions
11
python/tests/test_surface.py → ktirio/tests/test_surface.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
from setuptools import setup, find_namespace_packages | ||
from pybind11.setup_helpers import Pybind11Extension | ||
|
||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
from setuptools import Extension | ||
from setuptools.command.build_ext import build_ext | ||
|
||
|
||
# ext_modules = [ | ||
# # Pybind11Extension("ktirio._shadingmask", | ||
# # ["ktirio/shadingmask/shadingmask.cpp"] | ||
# # ), | ||
# ] | ||
|
||
|
||
# Convert distutils Windows platform specifiers to CMake -A arguments | ||
PLAT_TO_CMAKE = { | ||
"win32": "Win32", | ||
"win-amd64": "x64", | ||
"win-arm32": "ARM", | ||
"win-arm64": "ARM64", | ||
} | ||
|
||
# A CMakeExtension needs a sourcedir instead of a file list. | ||
# The name must be the _single_ output extension from the CMake build. | ||
# If you need multiple extensions, see scikit-build. | ||
class CMakeExtension(Extension): | ||
def __init__(self, name: str, sourcedir: str = "") -> None: | ||
super().__init__(name, sources=[]) | ||
self.sourcedir = os.fspath(Path(sourcedir).resolve()) | ||
|
||
|
||
class CMakeBuild(build_ext): | ||
def build_extension(self, ext: CMakeExtension) -> None: | ||
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+ | ||
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) | ||
extdir = ext_fullpath.parent.resolve() | ||
|
||
# Using this requires trailing slash for auto-detection & inclusion of | ||
# auxiliary "native" libs | ||
|
||
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug | ||
cfg = "Debug" if debug else "Release" | ||
|
||
# CMake lets you override the generator - we need to check this. | ||
# Can be set with Conda-Build, for example. | ||
cmake_generator = os.environ.get("CMAKE_GENERATOR", "") | ||
|
||
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON | ||
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code | ||
# from Python. | ||
cmake_args = [ | ||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", | ||
f"-DPYTHON_EXECUTABLE={sys.executable}", | ||
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm | ||
f"-DCMAKE_CXX_COMPILER=clang++" | ||
] | ||
build_args = [] | ||
# Adding CMake arguments set as environment variable | ||
# (needed e.g. to build for ARM OSx on conda-forge) | ||
if "CMAKE_ARGS" in os.environ: | ||
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] | ||
|
||
# In this example, we pass in the version to C++. You might not need to. | ||
# cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] | ||
|
||
if self.compiler.compiler_type != "msvc": | ||
# Using Ninja-build since it a) is available as a wheel and b) | ||
# multithreads automatically. MSVC would require all variables be | ||
# exported for Ninja to pick it up, which is a little tricky to do. | ||
# Users can override the generator with CMAKE_GENERATOR in CMake | ||
# 3.15+. | ||
if not cmake_generator or cmake_generator == "Ninja": | ||
try: | ||
import ninja | ||
|
||
ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" | ||
cmake_args += [ | ||
"-GNinja", | ||
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", | ||
] | ||
except ImportError: | ||
pass | ||
|
||
else: | ||
# Single config generators are handled "normally" | ||
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) | ||
|
||
# CMake allows an arch-in-generator style for backward compatibility | ||
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"}) | ||
|
||
# Specify the arch if using MSVC generator, but only if it doesn't | ||
# contain a backward-compatibility arch spec already in the | ||
# generator name. | ||
if not single_config and not contains_arch: | ||
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]] | ||
|
||
# Multi-config generators have a different way to specify configs | ||
if not single_config: | ||
cmake_args += [ | ||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}" | ||
] | ||
build_args += ["--config", cfg] | ||
|
||
if sys.platform.startswith("darwin"): | ||
# Cross-compile support for macOS - respect ARCHFLAGS if set | ||
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", "")) | ||
if archs: | ||
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))] | ||
|
||
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level | ||
# across all generators. | ||
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: | ||
# self.parallel is a Python 3 only way to set parallel jobs by hand | ||
# using -j in the build_ext call, not supported by pip or PyPA-build. | ||
if hasattr(self, "parallel") and self.parallel: | ||
# CMake 3.12+ only. | ||
build_args += [f"-j{self.parallel}"] | ||
|
||
build_temp = Path(self.build_temp) / ext.name | ||
if not build_temp.exists(): | ||
build_temp.mkdir(parents=True) | ||
|
||
subprocess.run( | ||
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True | ||
) | ||
subprocess.run( | ||
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True | ||
) | ||
|
||
setup( | ||
name='shadingmask', | ||
version='0.1.0', | ||
description='Ktirio module shadingmask', | ||
author="Christophe Prud'homme, Luca Berti, Vincent Chabannes", | ||
author_email='your.email@example.com', | ||
packages=find_namespace_packages(include=['ktirio.*']), | ||
# ext_modules=ext_modules, | ||
ext_modules=[CMakeExtension("ktirio._shadingmask")], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
python_requires='>=3.7', | ||
install_requires=[ | ||
# List your dependencies here | ||
|
||
], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
], | ||
) |
Oops, something went wrong.