Skip to content

Commit 54c5e11

Browse files
committed
Updating the pygeos documentation
1 parent 58d45ce commit 54c5e11

File tree

1 file changed

+36
-71
lines changed

1 file changed

+36
-71
lines changed

pygeos_package/pygeos/pygeos_documentation.rst

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@
22
Python Input Processing: pygeos
33
###############################################################################
44

5-
Pygeos is a python-based module designed to construct input files for GEOSX.
6-
It allows users to create xml files that include child files, parameters, units, and symbolic math.
7-
It also includes helper-functions for validating input files and constructing tables.
5+
Pygeos is a python module that enables advanced .xml features in GEOSX.
6+
It allows users to include child files, parameters, units, and symbolic math.
87

98

109
Setup
1110
=================================
12-
The pygeos module is located here: `src/coreComponents/python/modules/pygeos_package` .
13-
The module is compabitable with python 2/3, and its dependencies include the `numpy` and `lxml` packages.
14-
It can easily be installed using tools such as pip:
11+
The pygeos module is located in the GEOSX repository: `src/coreComponents/python/modules/pygeos_package` .
12+
The module is compabitable with python 2/3, and depends on the `lxml`, `numpy`, and `re` packages.
13+
It can be installed into an existing python distribution via pip:
1514

1615
`pip install src/coreComponents/python/modules/pygeos_package`
1716

1817

1918
Virtual Python Environment
2019
---------------------------------
2120

22-
On systems with a shared python installation, we reccomend that users install the package within a virtual python environment.
21+
On systems with a shared python installation, we recommend that users install the package within a virtual python environment.
2322
A script designed to automatically setup a virtual environment, install the dependencies, and install pygeos is included in `scripts/setupVirtualPythonEnvironment.bash` .
2423
The options for the script include:
2524

2625
- -p/--python_root : This specifies the root path for the parent python environment
2726
- -o/--output_path : This specifies location where the virtual environment will be installed
2827

29-
The default settings for the script will build a virtual environment for the python-3.6.4 installation on LC systems, and will place the environment in `~/Python/virtual/geosx`
28+
The default settings for the script will build a virtual environment for the python-3.6.4 installation on LC systems, and will place the environment in `~/Python/virtual/geosx` . The script will also install pygeos and its pre-requisites.
3029

31-
To use the load the python environment, run the following: `source ~/Python/virtual/geosx/bin/activate` .
32-
Within the environment, the commands `python` and `pip` will point to the correct versions.
33-
To exit the virtual environment, run the command: `deactivate` .
30+
To use the virtual environment, do one of the following:
3431

32+
1) Load the startup script: `source ~/Python/virtual/geosx/bin/activate` . This will add the (geosx) decorator to your shell, and will set the proper aliases for python, pip, etc. To exit the environment, run `deactivate`.
33+
2) Access the bin directory of the virtual python environment directly (e.g. `~/Python/virtual/geosx/bin/python some_script.py` ).
3534

3635

37-
XML Preprocessing
36+
37+
Advanced XML Features
3838
=================================
3939

40-
The xml preprocessor is designed to take an raw input file, and generate an new file that can be directly read by GEOSX.
40+
The xml preprocessor in pygeos is designed to take an raw input file, and generate an new file that can be directly read by GEOSX.
4141
The syntax for the advanced xml format is given below.
4242
During the processing the order of operations are:
4343

@@ -49,14 +49,29 @@ During the processing the order of operations are:
4949

5050

5151

52-
Use Example
52+
Command-line Example
5353
------------------------------
5454

55-
`pygeos.preprocessGEOSXML(input, schema='')` is used to process the input xml.
56-
The name of the newly generated, preprocessed xml file will be returned by this function call.
57-
By default it will have the name 'prep_' + a randomly generated string.
55+
Pygeos can be called from the command line to process .xml files via the script.
56+
(Note: this be on your path if you are in a virtual environment. Otherwise, it can be called directly from the bin directory of your python distribution.)
57+
The following will read a raw .xml file, generate a processed version, and return the new file name.
58+
59+
pygeos input_file.xml
60+
61+
Optional arguments include:
62+
- -o / --output = The desired name for the output file (otherwise, it is randomly generated)
63+
- -s / --schema = The location of a schema to validate the final .xml file
64+
- -v / --verbose = Increase module verbosity
65+
66+
This can be embedded within a call to GEOSX:
67+
68+
srun -n 16 geosx -i \`pygeos input_file.xml\`
69+
70+
71+
Script-based Example
72+
------------------------------
5873

59-
The following is a example python script that will read process an xml file specified via the command line.
74+
The pygeos module can also be called from within a python script. For example:
6075

6176
.. code-block:: python
6277
@@ -150,7 +165,7 @@ Examples:
150165
Symbolic Math
151166
------------------------------
152167
Input xml files can also include symbolic mathematical expressions.
153-
These are indicated with curly braces, and use a python syntax.
168+
These are placed within pairs of backticks (\`), and use a python syntax.
154169
Parameters and units are evaluated before symbolic expressions.
155170
Note: symbolic expressions are sanitized by removing any residual alpha characters, but this can be relaxed if more complicated function are needed.
156171

@@ -166,64 +181,14 @@ Examples:
166181
<Parameter name='d' value='1.23E-4 [km**2]'/>
167182
</Parameters>
168183
<Nodesets>
169-
<Nodeset name='perf' xmin='{$a$ - 0.2*$b$} -1e6 -1e6' xmax='{$c$**2 / $d$} 1e6 1e6' />
184+
<Nodeset name='perf' xmin='`$a$ - 0.2*$b$` -1e6 -1e6' xmax='`$c$**2 / $d$` 1e6 1e6' />
170185
</Nodesets>
171186
172187
173188
Validation
174189
------------------------------
175-
Unmatched special characters ($, [, }, etc.) mean that parameters, units, or symbolic math were not specified correctly.
190+
Unmatched special characters ($, [, \`, etc.) mean that parameters, units, or symbolic math were not specified correctly.
176191
If the code detects these, it will throw an error.
177192
The XML is validated against the input schema to check if all of the required field are present, and that input parameters match their expected types.
178193

179194

180-
181-
Input Table Generation
182-
=================================
183-
184-
The pygeos package also includes some tools to convert numpy arrays into GEOSX input tables, and vice-versa.
185-
186-
The following example shows how to write a series of structrued tables using a list of spatial axes and a dictionary of table values:
187-
188-
.. code-block:: python
189-
190-
import numpy as np
191-
import pygeos
192-
193-
# Config
194-
N = (10, 20, 30)
195-
196-
# Generate coordinate axes
197-
# These correspond to each axis of the numpy tables
198-
# The example function accepts up to four axes, and
199-
# will assign them the names x, y, z, and t in order
200-
spatial = [np.linspace(0, 1, N[0]),
201-
np.linspace(0, 1, N[1]),
202-
np.linspace(0, 1, N[2])]
203-
204-
# Generate the property dictionary
205-
properties = {'random_variable_A': np.randn(N),
206-
'random_variable_B': np.randn(N),
207-
'random_variable_C': np.randn(N)}
208-
209-
# Write the tables
210-
# The files will be written to the current directory,
211-
# and will have the .txt extension
212-
pygeos.writeGEOSTable(spatial, properties)
213-
214-
215-
The following shows how to read the geos tables written in the previous example:
216-
217-
. code-block:: python
218-
219-
import numpy as np
220-
import pygeos
221-
222-
spatial_names = ['x', 'y', 'z']
223-
property_names = ['random_variable_A', 'random_variable_B', 'random_variable_C']
224-
225-
spatial, properties = pygeos.readGEOSTable(spatial_names, property_names)
226-
227-
228-
229-

0 commit comments

Comments
 (0)