Skip to content

Commit

Permalink
257 feature type re assignment (#262)
Browse files Browse the repository at this point in the history
* filter the feature collection by feature type

* check in some experimental code

* set VerifyInformationModel.yes when adding property

* use setuptools-git-versioning

* minor changes according to JC comments

* add warning about inaccurate git version number

* move some code out of __init__.py

* add reset_feature_type sub-command

* add test_reset_feature_type.sh

* update links

* update readme

* find out why the pytest hangs on Windows

* find out why the pytest hangs on Windows - 2

* test if setuptools-git-versioning caused pytest hang

* test if setuptools-git-versioning caused pytest hang 1

* test if setuptools-git-versioning caused pytest hang 2

* remove the damned unicode emoji

* bing back good stuff

* update warning message again

* update test scripts
  • Loading branch information
michaelchin authored Aug 28, 2024
1 parent e15e361 commit cbcce99
Show file tree
Hide file tree
Showing 15 changed files with 675 additions and 175 deletions.
79 changes: 64 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,68 +296,117 @@ Other documentation versions:

GPlately comes with a suite of useful command line tools. These tools are designed as GPlately subcommands. Run `gplately -h` to show the list of tools.

- **list**
### **list**

Display a list of available plate models from GPlates server. These model names can then be used by the Plate Model Manager to download model files over Internet. Run `gplately list -h` for details.

Examples:

- `gplately list`
(list all available plate models from GPlates server)

- `gplately list -m merdith2021`
(show details about model merdith2021)

If you are using GPlately Docker image

- `docker run gplates/gplately gplately list`
- `docker run gplates/gplately gplately list -m merdith2021`

- **combine**
### **combine**

Combine multiple feature collections into one. Run `gplately combine -h` for details.

- **filter**
### **filter**

Filter feature collection by various criteria. Run `gplately filter -h` for details.

Examples:

- `gplately filter input_file output_file -n Africa "North America"`
(get features whose name contains "Africa" or "North America")

- `gplately filter input_file output_file -p 701 714 715 101`
(get features whose plate ID is one of 701 714 715 101)

- `gplately filter input_file output_file --min-birth-age 500`
(get features whose birth age is older than 500Myr)

- `gplately filter input_file output_file --max-birth-age 500`
(get features whose birth age is younger than 500Myr)

- `gplately filter input_file output_file -n Africa "North America" -p 701 714 715 101 --min-birth-age 500`
(get features whose name conains "Africa" or "North America" and plate ID is one of 701 714 715 101 and birth age is older than 500Myr)

- `gplately filter input_file output_file -t gpml:Basin`
(get all gpml:Basin features)

- `gplately filter input_file output_file -t "gpml:IslandArc|gpml:Basin"`
(get all gpml:Basin and gpml:IslandArc features)

If you are using Docker, prefix `docker run gplates/gplately ` to the command, such as `docker run gplates/gplately gplately filter input_file output_file -t gpml:Basin`.

See https://github.com/GPlates/gplately/blob/master/tests-dir/unittest/test_feature_filter.sh for more examples.

### **reset_feature_type**

Reset the feature type for the selected features. Run `gplately reset_feature_type -h` for details.

Examples:

- `gplately reset_feature_type -s gpml:ClosedContinentalBoundary -t gpml:UnclassifiedFeature input_file output_file`
(change all gpml:ClosedContinentalBoundary to gpml:UnclassifiedFeature)
- `gplately reset_feature_type -s "gpml:ContinentalFragment|gpml:Coastline" -t gpml:UnclassifiedFeature input_file output_file`
(change all gpml:ContinentalFragment and gpml:Coastline to gpml:UnclassifiedFeature)
- `gplately reset_feature_type -s ".*" -t gpml:UnclassifiedFeature input_file output_file`
(change all feature types to gpml:UnclassifiedFeature)

If you are using Docker, prefix `docker run gplates/gplately ` to the command, such as `docker run gplates/gplately gplately reset_feature_type -s ".*" -t gpml:UnclassifiedFeature input_file output_file`.

Filter feature collection by various criteria. See scripts/test_feature_filter.sh for usage examples. Run `gplately filter -h` for details.
See https://github.com/GPlates/gplately/blob/master/tests-dir/unittest/test_reset_feature_type.sh for more examples.

- **agegrid (ag)**
### **agegrid (ag)**

Create age grids for a plate model. Run `gplately agegrid -h` for details.

- **fix_crossovers**
### **fix_crossovers**

Loads one or more input rotation files, fixes any crossovers and saves the rotations to output rotation files. Run `gplately fix_crossovers -h` for details.

- **remove_rotations**
### **remove_rotations**

Remove one or more plate IDs from a rotation model (consisting of one or more rotation files). Run `gplately remove_rotations -h` for details.

- **cleanup_topologies**
### **cleanup_topologies**

Remove any regular features not referenced by topological features. Run `gplately cleanup_topologies -h` for details.

- **convert_xy_to_gplates**
### **convert_xy_to_gplates**

Converts geometry in one or more input ascii files (such as '.xy' files) to output files suitable for loading into GPlates. Run `gplately convert_xy_to_gplates -h` for details.

- **diagnose_rotations**
### **diagnose_rotations**

Diagnose one or more rotation files to check for inconsistencies. Run `gplately diagnose_rotations -h` for details.

- **resolve_topologies**
### **resolve_topologies**

Resolve topological plate polygons (and deforming networks) and saves (to separate files) the resolved topologies, and their boundary sections as subduction zones, mid-ocean ridges (ridge/transform) and others (not subduction zones or mid-ocean ridges). Run `gplately resolve_topologies -h` for details.

- **rotation_tools**
### **rotation_tools**

Calculate stage rotations between consecutive finite rotations in plate pairs. Run `gplately rotation_tools -h` for details.

- **separate_ridge_transform_segments**
### **separate_ridge_transform_segments**

Split the geometries of isochrons and mid-ocean ridges into ridge and transform segments. Run `gplately separate_ridge_transform_segments -h` for details.

- **subduction_convergence**
### **subduction_convergence**

Find the convergence rates along trenches (subduction zones) over time. Run `gplately subduction_convergence -h` for details.

- **gpmdb**
### **gpmdb**

Retrieve paleomagnetic data from https://www.gpmdb.net, create GPlates-compatible VGP features and save the VGP features in a .gpmlz file. Run `gplately gpmdb -h` for details.
88 changes: 12 additions & 76 deletions gplately/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,90 +199,26 @@
- [__11 - AndesFluxes__](11-AndesFluxes.html): Demonstrates how the reconstructed subduction history along the Andean margin can be potentially used in the plate kinematics anylysis and data mining.
"""
from .utils import dev_warning
from .utils.check_pmm import ensure_plate_model_manager_compatible
from .utils.log_utils import get_debug_level, setup_logging, turn_on_debug_logging
from .utils.version import get_distribution_version

__version__ = "1.3.0"
REQUIRED_PMM_VERSION = "1.2.0"
REQUIRED_PMM_VERSION = "1.2.0" # TODO: get this from package meta
USING_DEV_VERSION = True ## change this to False before official release

import os

disable_dev_warning = (
"DISABLE_GPLATELY_DEV_WARNING" in os.environ
and os.environ["DISABLE_GPLATELY_DEV_WARNING"].lower() == "true"
)
if USING_DEV_VERSION and not disable_dev_warning:
print()
print("##########################################################################")
print(
"""
WARNING:
You are using a DEV version GPlately. Some functionalities have not been tested thoroughly.
The DEV version may break your code or produce wrong results due to its unstable nature(DEV in progress).
You might also need to install the DEV version plate_model_manager
from https://github.com/michaelchin/plate-model-manager to use this DEV version GPlately.
To disable this warning, set USING_DEV_VERSION to False in __init__.py or
set DISABLE_GPLATELY_DEV_WARNING environment variable to true.
`export DISABLE_GPLATELY_DEV_WARNING=true`
"""
)
print("##########################################################################")
print()

import logging

from .utils.log_utils import get_debug_level, setup_logging, turn_on_debug_logging
__version__ = get_distribution_version()

setup_logging()

if get_debug_level() > 0:
turn_on_debug_logging()

del setup_logging
del os

logger = logging.getLogger("gplately")


def install_and_update_pmm():
import subprocess
import sys

subprocess.call(
[sys.executable, "-m", "pip", "install", "plate-model-manager", "--upgrade"]
)


def check_version(installed_version, required_version):
"""return True if the installed_version is good enough, otherwise False"""
installed_version_numbers = installed_version.split(".")
required_version_numbers = required_version.split(".")
if int(installed_version_numbers[0]) > int(required_version_numbers[0]):
return True
elif int(installed_version_numbers[0]) == int(required_version_numbers[0]):
if int(installed_version_numbers[1]) > int(required_version_numbers[1]):
return True
elif int(installed_version_numbers[1]) == int(required_version_numbers[1]):
if int(installed_version_numbers[2]) >= int(required_version_numbers[2]):
return True
return False


try:
import plate_model_manager
except (ImportError, ModuleNotFoundError):
logger.info("The plate_model_manager is not installed, installing it now!")
install_and_update_pmm()
import plate_model_manager


if not check_version(plate_model_manager.__version__, REQUIRED_PMM_VERSION):
logger.info("The plate_model_manager is outdated, updating it now!")
install_and_update_pmm()
import importlib

importlib.reload(plate_model_manager)
if USING_DEV_VERSION:
dev_warning.print_dev_warning(__version__)
dev_warning.print_using_source_code_warning(__version__)
del dev_warning

ensure_plate_model_manager_compatible(REQUIRED_PMM_VERSION)
del ensure_plate_model_manager_compatible

from . import (
data,
Expand Down
5 changes: 4 additions & 1 deletion gplately/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from gplately import __version__

from .commands import create_age_grids, feature_filter, list_models
from .commands import create_age_grids, feature_filter, list_models, reset_feature_type
from .ptt import (
cleanup_topologies,
convert_xy_to_gplates,
Expand Down Expand Up @@ -93,6 +93,9 @@ def main():
# add "feature filter" sub-command
feature_filter.add_parser(subparser)

# add "reset feature type" sub-command
reset_feature_type.add_parser(subparser)

# add "create age grids" sub-command
create_age_grids.add_parser(subparser)

Expand Down
Loading

0 comments on commit cbcce99

Please sign in to comment.