GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add the Session.virtualfile_from_stringio method to allow StringIO input for certain functions/methods by seisman · Pull Request #3326 · GenericMappingTools/pygmt Conversation
|
Actually, when calling a GMT module, we usually know the expected number of numeric columns (for example, 0 for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if line.startswith(">"): # Segment header | ||
| if header is not None: # Only one segment is allowed now. | ||
| raise GMTInvalidInput("Only one segment is allowed.") | ||
| header = line | ||
| continue |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Need a test to check that multi-segment inputs fail.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's likely we have to allow multi-segments in StringIO.
Here is a CLI version for typesetting a paragraph of text. It seems the first line must be a line not starting with # and is ignored. Not sure why it was designed like this. I'll open another POC PR for Figure.text and see how it works.
gmt text -R0/3/0/5 -JX3i -h1 -M -N -F+f12,Times-Roman+jLT -pdf figure << EOF
This is an unmarked header record not starting with #
> 0 -0.5 13p 3i j
@%5%Figure 1.@%% This illustration shows nothing useful, but it still needs
a figure caption. Highlighted in @;255/0/0;red@;; you can see the locations
of cities where it is @\_impossible@\_ to get any good Thai food; these are to be avoided.
EOF
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Correction: I didn't see the -h1 option in the CLI version, which skips the first line. Without -h1, the CLI version still works:
gmt text -R0/3/0/5 -JX3i -M -N -F+f12,Times-Roman+jLT -pdf figure << EOF
> 0 -0.5 13p 3i j
@%5%Figure 1.@%% This illustration shows nothing useful, but it still needs
a figure caption. Highlighted in @;255/0/0;red@;; you can see the locations
of cities where it is @\_impossible@\_ to get any good Thai food; these are to be avoided.
EOF
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here is a POC example to show how to support paragraph mode via StringIO:
In [1]: import io In [2]: stringio = io.StringIO( ...: "> 0 -0.5 13p 3i j\n" ...: "@%5%Figure 1.@%% This illustration shows nothing useful, but it still needs\n" ...: "a figure caption. Highlighted in @;255/0/0;red@;; you can see the locations\n" ...: "of cities where it is @_impossible@_ to get any good Thai food; these are to be avoided.\n" ...: ) In [3]: import pygmt In [4]: fig = pygmt.Figure() In [5]: from pygmt.clib import Session In [6]: with Session() as lib: ...: with lib.virtualfile_in(data=stringio) as vintbl: ...: lib.call_module(module="text", args=f"{vintbl} -R0/3/0/5 -JX3i -M -N -F+f12,Times-Roman+jLT") ...: In [7]: fig.show()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
StringIO objects containing multi-segments are supported in the latest version.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| def virtualfile_in( # noqa: PLR0912 | ||
| self, | ||
| check_kind=None, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Then the question is, how can we add StringIO support to specific functions only (e.g.,
Figure.legend)?
Maybe legend should have a special check_kind? E.g. if check_kind("legend"): valid_kinds += ("stringio", ...)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See #3438 for the POC PR for Figure.legend. Since we already checked the data kind before entering the session, we can have check_kind=False in Figure.legend.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This reverts commit 486fce7.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @seisman for adding multi-segment support! I just have one concern/thought about non-ASCII character support, but that could be handled later (if needed).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "GMT_IS_PLP", # items could be any one of POINT, LINE, or POLY | ||
| "GMT_IS_SURFACE", # items are 2-D grid | ||
| "GMT_IS_VOLUME", # items are 3-D grid | ||
| "GMT_IS_TEXT", # Text strings which triggers ASCII text reading |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is only ASCII supported for now? What about other encodings?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
GMT only accepts ASCII text strings. Any non-ASCII characters should be written in the form of octal codes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.