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

sphinx doc

parent e8ec8607
all :
python install --user
make -C doc 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.
SPHINXBUILD ?= sphinx-build
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
.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
# 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:
# -- 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`
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
set BUILDDIR=_build
if "%1" == "" goto help
if errorlevel 9009 (
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.If you don't have Sphinx installed, grab it from
exit /b 1
goto end
.. toctree::
:maxdepth: 4
msea.Field module
.. automodule:: msea.Field
msea package
.. toctree::
:maxdepth: 4
Module contents
.. automodule:: msea
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):
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 = np.vstack(points)
self._tree = cKDTree(points)
self._projection = domain._projection
def __call__(self, x:np.ndarray, projection:osr.SpatialReference
"""Compute the distance between each point of x and the curves.
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.
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):
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
"""Evaluate the field value on each point of x.
Keyword arguments:
x: the points [n,2]
projection: the coordinate system of the points
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(
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)
bath_field = msea.RasterField("medit.tiff")
dist_coast_field = msea.DistanceField(domain,100,["coast","island"])
dist_porquerolles_field = msea.DistanceField(domain,20,["porquerolles"])
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