Skip to content
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

Integrating GPlately for Plate Reconstruction and Feature Extraction #810

Merged
merged 4 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Testing/
doc/doxygen/
*.xcf
tests/unit_tests/approval_tests/received/*
contrib/gplate/data
contrib/gplate/plate-model-repo
contrib/pmm.log
108 changes: 108 additions & 0 deletions contrib/gplate/geojson2json.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Geojson2json.py is a simple script that directly converts GeoJSON files extracted using the GPlates GUI to the World Builder-compatible JSON format. Currently, it supports continental plate geometries. \n",
"\n",
"The script reads the GeoJSON file, processes polygon features, and assigns default or provided values for \n",
"maximum depth and compositions. The output JSON file follows the World Builder structure, making it ready \n",
"for use in geodynamic modeling applications.\n",
"\n",
"Future improvements may integrate this script with GPlate2GWB for a more streamlined workflow.\n",
"\n",
"Usage:\n",
" python geojson2json.py\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"# Configuration defined by the user\n",
"geojson_file = \"reconstructed_400.00Ma.geojson\" # Input GeoJSON file\n",
"output_file = \"world_builder_model.json\" # Output JSON file\n",
"default_max_depth = 350e3\n",
"default_compositions = [0]\n",
"\n",
"try:\n",
" # Load GeoJSON file\n",
" with open(geojson_file, 'r') as f:\n",
" geojson_data = json.load(f)\n",
"\n",
" features = []\n",
"\n",
" for feature in geojson_data.get('features', []):\n",
" if feature.get('geometry', {}).get('type') == 'Polygon':\n",
" name = feature.get('properties', {}).get('NAME', 'Unknown')\n",
" coordinates = [list(coord) for coord in feature['geometry']['coordinates'][0]]\n",
"\n",
" # Use provided properties or fall back to defaults\n",
" max_depth = feature.get('properties', {}).get('MAX_DEPTH', default_max_depth)\n",
" compositions = feature.get('properties', {}).get('COMPOSITIONS', default_compositions)\n",
"\n",
" feature_data = {\n",
" \"model\": \"continental plate\",\n",
" \"name\": name,\n",
" \"max depth\": max_depth,\n",
" \"coordinates\": coordinates,\n",
" \"composition models\": [\n",
" {\n",
" \"model\": \"uniform\",\n",
" \"compositions\": compositions,\n",
" \"max depth\": max_depth\n",
" }\n",
" ]\n",
" }\n",
" features.append(feature_data)\n",
"\n",
" output_data = {\n",
" \"version\": \"1.1\",\n",
" \"interpolation\": \"continuous monotone spline\",\n",
" \"coordinate system\": {\n",
" \"model\": \"spherical\",\n",
" \"depth method\": \"starting point\"\n",
" },\n",
" \"features\": features\n",
" }\n",
"\n",
" # Save output to JSON file\n",
" with open(output_file, 'w') as out_f:\n",
" json.dump(output_data, out_f, indent=4)\n",
"\n",
" print(f\"Conversion successful! Output saved to {output_file}\")\n",
"\n",
"except Exception as e:\n",
" print(f\"Error processing file: {e}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "extra_postprocess",
"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.15"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
366 changes: 366 additions & 0 deletions contrib/gplate/gplately2gwb.ipynb

Large diffs are not rendered by default.

Loading