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
{{ message }}
Repository navigation
Raise a GMTInvalidInput exception for only x,y input to blockmedian and blockmean #1447
Currently, no exception is raised in the blockmedian and blockmean functions if the x and y parameters are used but not the z parameter. This should be disallowed because these functions require three columns. For example, GMT will raise an error if a textfile with only two columns is used.
The simplest method to fix this problem would be to add the equivalent of these lines of code (using table rather than data) to the start of the _blockm function:
raiseGMTInvalidInput("Must provide z with x and y.")
Another option could be to extend the virtualfile_from_data function to (optionally) check the number of columns. This would limit redundancy relative to using the same code block for all functions operating on x,y,z data (e.g., blockm*, surface, nearneighbor). If the test were in virtualfile_from_data, we could also reduce the tests required because the exception would not need to be tested in each module that requires three columns.
Are you willing to help implement and maintain this feature? Glad to help someone else with this issue
I think I can try to do that, I can try to extend virtualfile_from_data. but I didn't understand how would I know if virtualfile_from_data is called from a function that required z values(e.g blockmean) or called from a function that required only x, y data like plot?
I think I can try to do that, I can try to extend virtualfile_from_data. but I didn't understand how would I know if virtualfile_from_data is called from a function that required z values(e.g blockmean) or called from a function that required only x, y data like plot?
One option would be to add an optional keyword parameter z_required to virtualfile_from_data so that this can be specified for each function. This could be passed to data_kind so that the checking is done in the same block as the checking of x and y.
But, I am actually not sure if making this code specific to x, y and z is the best way to go or if we should instead have a more general function that can be used to check that if any one of a set of parameters is not None, all are not None. This way, the function could be used for other GMT parameters that need to be paired (relates to #256). While I think this would likely be more useful, I have not looked into the implementation.
I'm wondering if we should use a minimum_cols parameter, rather than a required_z parameter. Note that sometimes functions may need more than 4 columns. For example, the blockmean modules can accept another column for weighting (not implemented in PyGMT yet).
I think minimum_cols is not practical for two reasons.
As I mentioned we want to raise a descriptive error message rather than a vague(e.g Must provided both x, y, and z. rather than let's say Not all necessary data were provided.
Let's say some function needs both x, y, z, and some other column a to know that it needs 4 columns are not enough to check that they are all provided (e.g to check a is not None) I need to know to check specifically a.
I think the z column is widely used in many functions so it is sensible to have a general propose code that checks for that, for other columns that are more function-specific we should check in the function itself(and raise a specific descriptive error). We could implement some helper function as @meghanrjones suggested
But, I am actually not sure if making this code specific to x, y and z is the best way to go or if we should instead have a more general function that can be used to check that if any one of a set of parameters is not None, all are not None. This way, the function could be used for other GMT parameters that need to be paired (relates to #256). While I think this would likely be more useful, I have not looked into the implementation.
Activity
seisman commentedon Aug 18, 2021
Sounds a better option to me.
yohaimagen commentedon Aug 26, 2021
I think I can try to do that, I can try to extend
virtualfile_from_data. but I didn't understand how would I know ifvirtualfile_from_datais called from a function that required z values(e.gblockmean) or called from a function that required onlyx,ydata likeplot?maxrjones commentedon Aug 27, 2021
One option would be to add an optional keyword parameter
z_requiredtovirtualfile_from_dataso that this can be specified for each function. This could be passed todata_kindso that the checking is done in the same block as the checking ofxandy.But, I am actually not sure if making this code specific to
x,yandzis the best way to go or if we should instead have a more general function that can be used to check that if any one of a set of parameters is not None, all are not None. This way, the function could be used for other GMT parameters that need to be paired (relates to #256). While I think this would likely be more useful, I have not looked into the implementation.yohaimagen commentedon Aug 28, 2021
I think those are separate issues.
to raise a descriptive error message we will still need to do something like the following in
data_kindparameter_set_not_nonecan be implemented with something likemaxrjones commentedon Aug 30, 2021
OK, do you want to address the first of these two separate issues using z_required? If so, I can assign the issue to you.
yohaimagen commentedon Sep 1, 2021
can do both if you think both of them are necessary, let's start with the first one I'll open a PR.
seisman commentedon Sep 1, 2021
I'm wondering if we should use a
minimum_colsparameter, rather than arequired_zparameter. Note that sometimes functions may need more than 4 columns. For example, the blockmean modules can accept another column for weighting (not implemented in PyGMT yet).yohaimagen commentedon Sep 2, 2021
I think
minimum_colsis not practical for two reasons.Must provided both x, y, and z.rather than let's sayNot all necessary data were provided.x, y, z, and some other columnato know that it needs 4 columns are not enough to check that they are all provided (e.g to checka is not None) I need to know to check specificallya.I think the
zcolumn is widely used in many functions so it is sensible to have a general propose code that checks for that, for other columns that are more function-specific we should check in the function itself(and raise a specific descriptive error). We could implement some helper function as @meghanrjones suggested