You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another way is using dict, e.g. gmt.conf['PAR1']=value1, which seems more pythonic. But we need call gmt set for each assignment. I'm not sure if it's technically possible.
Using the dictionary syntax is doable through __getitem__ but it's probably not worth the added complexity.
I like the set function but not really the upper case arguments to other functions. A better way to have temporary settings would be through a context manger:
withpygmt.set(bla=something):
pygmt.surface(...)
That would make the documentation of other methods easier because they don't take GMT level configuration parameters. These are all handled by set and can be set globally or temporally.
It seems to me like the most common use case of gmt set is for global changes at the beginning of a script. Wouldn't using a context manager cause the whole script to be indented?
In spite of the apparent added complexity (I'm sorry to comment on something I know so little about here) I feel that a dictionary of values would certainly be most suitable. As @seisman has written it above, this would be essentially analogous to what matplotlib does with matplotlib.rcParams, e.g.
If we were using this dictionary framework I think it would be less weird to use upper case arguments, since they're constants anyhow. This would make it simpler since we wouldn't have to come up with new, lower-case names for all of the default params, and folks could cross over from classic GMT more easily.
Wouldn't using a context manager cause the whole script to be indented?
Yep, that would be terrible. The way the new matplotlib styling works is that you can set a style globally or use a context manager to temporarily change the style. We can tell whether the context manager is called inside a with block. So you could:
pygmt.set(PARAMETER=value) # Global# Locally set a value that will revert back to the defaultwithpygmt.set(PROJ_ELLIPSOID=value):
...
pygmt.whatever(...)
What do you think?
If we were using this dictionary framework I think it would be less weird to use upper case arguments
That's a good point. But the set function would be using **kwargs anyway, which is basically a dict.
This would make it simpler since we wouldn't have to come up with new, lower-case names for all of the default params
That was never my intension (sorry for not making it clear). We should keep the same parameter names with upper case letters.
folks could cross over from classic GMT more easily
If that's the case, then calling pygmt.set(...) at the beginning of the script is probably closer to what people do in bash scripts, right?
Okay, thanks for the clarification. I think the code block in your comment above represents an ideal implementation since users have both temp and global options.
Activity
leouieda commentedon Feb 9, 2019
Using the dictionary syntax is doable through
__getitem__but it's probably not worth the added complexity.I like the
setfunction but not really the upper case arguments to other functions. A better way to have temporary settings would be through a context manger:That would make the documentation of other methods easier because they don't take GMT level configuration parameters. These are all handled by
setand can be set globally or temporally.liamtoney commentedon Feb 9, 2019
It seems to me like the most common use case of
gmt setis for global changes at the beginning of a script. Wouldn't using a context manager cause the whole script to be indented?In spite of the apparent added complexity (I'm sorry to comment on something I know so little about here) I feel that a dictionary of values would certainly be most suitable. As @seisman has written it above, this would be essentially analogous to what matplotlib does with
matplotlib.rcParams, e.g.If we were using this dictionary framework I think it would be less weird to use upper case arguments, since they're constants anyhow. This would make it simpler since we wouldn't have to come up with new, lower-case names for all of the default params, and folks could cross over from classic GMT more easily.
leouieda commentedon Feb 18, 2019
Yep, that would be terrible. The way the new matplotlib styling works is that you can set a style globally or use a context manager to temporarily change the style. We can tell whether the context manager is called inside a
withblock. So you could:What do you think?
That's a good point. But the
setfunction would be using**kwargsanyway, which is basically a dict.That was never my intension (sorry for not making it clear). We should keep the same parameter names with upper case letters.
If that's the case, then calling
pygmt.set(...)at the beginning of the script is probably closer to what people do in bash scripts, right?liamtoney commentedon Feb 18, 2019
Okay, thanks for the clarification. I think the code block in your comment above represents an ideal implementation since users have both temp and global options.