Repository navigation
Description
Description of the desired feature
Implement gmtselect which "Select data table subsets based on multiple spatial criteria".
Mentioned at https://twitter.com/ATiredGradStdnt/status/1417189659365498884, also partially used before at https://forum.generic-mapping-tools.org/t/gmt-example-18-with-pygmt-volumes-and-spatial-selections/1585.
This function will probably be named select, i.e. called using pygmt.select(). As a table in, table out function, the implementation would be similar to already wrapped functions like blockmedian/blockmean. The code snippet would look something like so:
Lines 41 to 64 in 31980e8
| with GMTTempFile(suffix=".csv") as tmpfile: | |
| with Session() as lib: | |
| # Choose how data will be passed into the module | |
| table_context = lib.virtualfile_from_data( | |
| check_kind="vector", data=table, x=x, y=y, z=z | |
| ) | |
| # Run blockm* on data table | |
| with table_context as infile: | |
| if outfile is None: | |
| outfile = tmpfile.name | |
| arg_str = " ".join([infile, build_arg_string(kwargs), "->" + outfile]) | |
| lib.call_module(module=block_method, args=arg_str) | |
| # Read temporary csv output to a pandas table | |
| if outfile == tmpfile.name: # if user did not set outfile, return pd.DataFrame | |
| try: | |
| column_names = table.columns.to_list() | |
| result = pd.read_csv(tmpfile.name, sep="\t", names=column_names) | |
| except AttributeError: # 'str' object has no attribute 'columns' | |
| result = pd.read_csv(tmpfile.name, sep="\t", header=None, comment=">") | |
| elif outfile != tmpfile.name: # return None if outfile set, output in outfile | |
| result = None | |
| return result |
Xref table I/O discussion at #1268 and #1318. Best to wrap this module after #1426.
Are you willing to help implement and maintain this feature? Yes
Activity
Wrap gmtselect
Wrap gmtselect
seisman commentedon Mar 9, 2022
Can we close the issue, since the initial wrapper has been done in #1429? Or do we still want to keep this issue open to tracking missing aliases, and gallery examples? Keeping the issue open makes me think that it has not been wrapped.
Related to #1599.
weiji14 commentedon Mar 13, 2022
Ok, closing as initial implementation done at #1429. Tracking progress on project board https://github.com/GenericMappingTools/pygmt/projects/9#card-72007028 instead.