Skip to content

Wrapper for gmtselect #1427

Closed
Closed

Description

@weiji14

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:

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

  1. added
    feature request
    on Aug 10, 2021
  2. added 2 commits that reference this issue on Aug 10, 2021
  3. added this to the 0.5.0 milestone on Aug 10, 2021
  4. self-assigned this
    on Aug 10, 2021
  5. seisman commented on Mar 9, 2022

    @seisman
    Member

    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.

  6. weiji14 commented on Mar 13, 2022

    @weiji14
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions