Commit 43545191 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

sphinx doc

parent e8ec8607
all :
python setup.py install --user
make -C doc html
html:
make -C doc html
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
# -- Project information -----------------------------------------------------
project = 'msea'
copyright = '2020, Jonathan Lambrechts'
author = 'Jonathan Lambrechts'
# The full version, including alpha/beta/rc tags
release = '0.1'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc','sphinx.ext.napoleon']
napoleon_google_docstring = True
napoleon_numpy_docstring = False
napoleon_include_special_with_doc = True
autoclass_content = 'both'
html_show_sourcelink = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
Welcome to msea's documentation!
================================
.. include:: modules.rst
.. toctree::
:maxdepth: 2
:caption: Contents:
* :ref:`genindex`
..
* :ref:`modindex`
* :ref:`search`
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
msea
====
.. toctree::
:maxdepth: 4
msea
msea.Field module
=================
.. automodule:: msea.Field
:members:
:undoc-members:
:show-inheritance:
msea package
============
Submodules
----------
.. toctree::
:maxdepth: 4
msea.Field
Module contents
---------------
.. automodule:: msea
:members:
:undoc-members:
:show-inheritance:
from ._private import Domain
import numpy as np
from osgeo import osr
class Distance:
"""Callable evaluating the distance to a set of discretized curves.
The curves are discretized as sets of points, then the distance to the
closest point is computed.
"""
def __init__(self, domain:Domain, sampling:float, tags=None):
"""
Args:
domain: a Domain object containing the set of curves
sampling: the interval between two consecutive sampling points.
tags: List of physical tags specifying the curve from the domain.
if None, all curves are taken into account (default: None)
"""
points = []
for curve in domain._curves:
if (tags is None) or (curve.tag in tags):
points.append(curve.sample(sampling))
points = np.vstack(points)
self._tree = cKDTree(points)
self._projection = domain._projection
def __call__(self, x:np.ndarray, projection:osr.SpatialReference
)->np.ndarray:
"""Compute the distance between each point of x and the curves.
Args:
x: the points [n,2]
projection: the coordinate system of the points, should be
the same coordinate system as the domain, otherwise no
conversion is done and an exception is raised.
Returns:
The distance expressed in the domain unit. [n]
"""
if not projection.IsSame(self._projection):
raise ValueError("incompatible projection")
x = x[:, :2]
return self._tree.query(x)[0]
class Raster:
"""Callable to evaluate a raster field loaded from a file."""
def __init__(self, filename:str):
"""
Args:
filename: A geotiff file or any other raster file supported by gdal.
"""
src_ds = gdal.Open(filename)
self._geo_matrix = src_ds.GetGeoTransform()
self._data = src_ds.GetRasterBand(1).ReadAsArray()
assert(self._geo_matrix[2] == 0.)
assert(self._geo_matrix[4] == 0.)
self._projection = src_ds.GetProjection()
def __call__(self, x:np.ndarray, projection:osr.SpatialReference
)->np.ndarray:
"""Evaluate the field value on each point of x.
Keyword arguments:
x: the points [n,2]
projection: the coordinate system of the points
Returns:
The field value on points x. [n]
"""
x = _ensure_valid_points(x, projection, self._proection)
gm = self._geo_matrix
xi = (x[:, 0]-gm[3])/gm[5]
eta = (x[:, 1]-gm[0])/gm[1]
return self._data[xi.astype(int), eta.astype(int)]
from . import Field
from ._private import Domain, CurveType, convert_msh_gis
__all__ = ["Field","Domain","CurveType","convert_msh_gis"]
This diff is collapsed.
......@@ -26,7 +26,7 @@ setuptools.setup(
include_package_data=True,
url="https://www.migflow.be",
packages=["msea"],
package_dir={"msea":"src"},
package_dir={"msea":"msea"},
#ext_modules=[CMakeExtension("msealib")],
#ext_modules=[setuptools.Extension("seameshlib",["seamesh.c"])],
package_data={"msea":["*.so"]},
......
from .msea import *
......@@ -2,9 +2,9 @@ import msea
import numpy as np
from osgeo import osr
def mesh_size(x) :
s_coast = np.clip((dist_coast_field(x)-400)*0.5,200,5000)
s_porquerolles = np.clip((dist_porquerolles_field(x)-200)*0.5,50,5000)
def mesh_size(x,projection) :
s_coast = np.clip((dist_coast_field(x,projection)-400)*0.5,200,5000)
s_porquerolles = np.clip((dist_porquerolles_field(x,projection)-200)*0.5,50,5000)
return np.minimum(s_coast,s_porquerolles)
domain_srs = osr.SpatialReference()
......@@ -16,8 +16,8 @@ domain = msea.Domain(domain_srs)
domain.add_shapefile("test/data_no_duplicate.shp","physical",curve_type=msea.POLYLINE)
#domain.add_shapefile("test/interior.shp",None,True,curve_type=msea.POLYLINE)
#domain.add_interior_points("test/interior.shp")
bath_field = msea.RasterField("medit.tiff")
dist_coast_field = msea.DistanceField(domain,100,["coast","island"])
dist_porquerolles_field = msea.DistanceField(domain,20,["porquerolles"])
domain.unrefine_boundaries(8e5,4.68e6,20,mesh_size)
domain.build_topology()
msea.mesh_gmsh(domain,"test.msh",mesh_size)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment