Skip to content

Python wrappers #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,302 changes: 1,302 additions & 0 deletions Examples/Notebooks/PyGeoTessExplorerLight_Examples.ipynb

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions Examples/Notebooks/PyPCalc_EX01.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7da98c8c",
"metadata": {},
"source": [
"## Example 01"
]
},
{
"cell_type": "markdown",
"id": "485d2c22",
"metadata": {},
"source": [
"This notebook is designed to replicate example 1 from the PCalc user's manual"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cba5c210",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, \"../../python\")\n",
"\n",
"\n",
"jarfile = '../../target/salsa3d-software-1.2022.5-jar-with-dependencies.jar'\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from PyPCalc import PCalc\n",
"PCalc.print_example01_info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d96db269",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# PCalc objects are best initialized after setting your desired configuration and properties.\n",
"# configuration refers to how the python wrapper class interacts with the base pcalc jar file\n",
"# properties define the pcalc propeties that are used when the jar is executed\n",
"\n",
"config = PCalc.initialize_configuration(captureOutput=True, use_slbm=False, \n",
" returnObject='points',\n",
" jarFile = jarfile)\n",
"\n",
"props = PCalc.initialize_properties(\n",
" application = 'model_query',\n",
" workDir = '.',\n",
" geotessModel=\"../data/AK135.geotess\",\n",
" inputType = 'file',\n",
" inputFile = \"../data/example_coords.xyz\",\n",
" inputAttributes = 'latitude longitude depth',\n",
" batchSize = 10,\n",
" outputFile = \"<property:workDir>/pcalc_query_file_output.dat\",\n",
" logFile = \"<property:workDir>/pcalc_log.txt\",\n",
" terminalOutput = True,\n",
" separator = 'space',\n",
" outputAttributes = 'pslowness')\n",
"\n",
"# Creates the PCalc object using the define properties and configuration dictionaries.\n",
"calc = PCalc(config = config, properties = props)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7b81a21",
"metadata": {},
"outputs": [],
"source": [
"# Set properties and configuration aspects can be viewed:\n",
"print(\"PCalc properties:\")\n",
"calc.viewSetProperties()\n",
"print(\"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\")\n",
"print(\"PyPCalc Configuration:\")\n",
"calc.viewSetConfiguration()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ff14c62",
"metadata": {},
"outputs": [],
"source": [
"# In order to actually run pcalc, first write the properties file and then execute\n",
"calc.writePropertiesFile()\n",
"r, data = calc.execute()\n",
"# The execute method calls the PCalc jar file and returns the terminal output as the first value (r)\n",
"# and the data file that is generated as output is read in to Python as the second value (data)\n",
"\n",
"print(r.stdout)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ab4f0ff",
"metadata": {},
"outputs": [],
"source": [
"# For this case, we've set the 'returnObject' in the configuration to points\n",
"# This creates a list of values from the class PointMeasurement that just contains the data contained \n",
"# the output file. Alternatives include 'dataFrame' to get the raw pandas dataFrame object\n",
"# or 'array' to get a numpy array\n",
"#data[0].toString()\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a0f88ce",
"metadata": {},
"outputs": [],
"source": [
"# If you want to create your own input file rather than the included ../data/example_coords.xyz, you can use the write \n",
"# method of the PointMeasurement object as:\n",
"fp = open(\"tmp.dat\", \"w\")\n",
"for pt in data:\n",
" pt.write(fp, mode='longitude latitude depth', separator = 'tab')\n",
"fp.close()\n",
"!head tmp.dat"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ec04f1a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
141 changes: 141 additions & 0 deletions Examples/Notebooks/PyPCalc_EX02.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "c60ce11d",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, \"../../python\")\n",
"\n",
"\n",
"jarfile = '../../target/salsa3d-software-1.2022.5-jar-with-dependencies.jar'\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from PyPCalc import PCalc\n",
"PCalc.print_example02_info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f081092b",
"metadata": {},
"outputs": [],
"source": [
"config = PCalc.initialize_configuration(captureOutput=True, use_slbm=False, returnObject='dataFrame',\n",
" jarFile = jarfile)\n",
"\n",
"props = PCalc.initialize_properties(\n",
" application = 'model_query',\n",
" workDir = '.',\n",
" geotessModel=\"../data/AK135.geotess\",\n",
" inputType = 'greatcircle',\n",
" gcStart = \"0 0\",\n",
" gcDistance = 180,\n",
" gcAzimuth = 0,\n",
" gcSpacing = 10,\n",
" gcPositionParameters = 'x, y, distance, depth',\n",
" depthSpecificationMethod = 'maxDepthSpacing',\n",
" maxDepthSpacing = 100,\n",
" maxDepth = 'top of m660',\n",
" outputFile = \"<property:workDir>/pcalc_query_greatcircle_output.dat\",\n",
" logFile = \"<property:workDir>/pcalc_log.txt\",\n",
" terminalOutput = True,\n",
" outputHeader = True,\n",
" separator = 'tab',\n",
" outputAttributes = 'pslowness')\n",
"\n",
"calc = PCalc(config = config, properties = props)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ff120d98",
"metadata": {},
"outputs": [],
"source": [
"# Set properties and configuration aspects can be viewed:\n",
"print(\"PCalc properties:\")\n",
"calc.viewSetProperties()\n",
"print(\"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\")\n",
"print(\"PyPCalc Configuration:\")\n",
"calc.viewSetConfiguration()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64db4ce4",
"metadata": {},
"outputs": [],
"source": [
"# In order to actually run pcalc, first write the properties file and then execute\n",
"calc.writePropertiesFile()\n",
"r, data = calc.execute()\n",
"# The execute method calls the PCalc jar file and returns the terminal output as the first value (r)\n",
"# and the data file that is generated as output is read in to Python as the second value (data)\n",
"\n",
"print(r.stdout)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a4f5417",
"metadata": {},
"outputs": [],
"source": [
"# This time, the configuration set the returnObject to dataFrame.\n",
"# This is a structure from the Pandas library that organizes tables nicely\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86657193",
"metadata": {},
"outputs": [],
"source": [
"data.boxplot()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4c5957a5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading