Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix open issue regarding warnings for criteria without data (Issue #4) #13

Merged
merged 13 commits into from
Oct 6, 2021

Conversation

PTierz
Copy link
Collaborator

@PTierz PTierz commented Sep 23, 2021

Description

Two outstanding tasks were not completed in Issue #4. These related to: (1) avoiding that the calculate_weighted_analogy_matrix() function had to return a dictionary specifying whether data were available or not for each of the volcanological criteria, for a given target volcano; and (2) avoiding the need to catch PyvolcansError exceptions when either data were missing for a given criterion, or perfect analogues arose for a given target volcano and weighting scheme used. In these situations, warning messages could just be issued using the warnings package.

Commits in branch fix-open-issue are targeted at solving these issues. @mobiuscreek and @volcan01010: could you please check the boxes in Issue #4 and close it once one of you has been able to go through the acceptance criteria below and ensure that they are all satisfied? I can then let @jifarquharson know that Issue #4 has been solved, OK? Very many thanks in advance!

Acceptance criteria

  • pyvolcans Alutu prints the following warning messages: PyVOLCANS: WARNING!!! The following volcanological criteria do not have any data available for the selected target volcano (Alutu) --> eruption_size. Please consider excluding these criteria from your weighting scheme (i.e. setting their weights to zero).
  • pyvolcans Toliman -Ts 1 prints the following warning messages: PyVOLCANS: WARNING!!! The following volcanological criteria do not have any data available for the selected target volcano (Toliman) --> eruption_size, eruption_style. Please consider excluding these criteria from your weighting scheme (i.e. setting their weights to zero). and PyVOLCANS: WARNING!!! All top analogue volcanoes have the same value of total analogy. Please be aware of possible data deficiencies and/or the use of a simplified weighting scheme (see Tierz et al., 2019, for more details).
  • pyvolcans "La Palma" does not print any warning message.

Instead of checking for volcanological criteria without available
data for the particular target volcano in pyvolcans.py, this is now
done inside the `calculate_weighted_analogy_matrix()` function inside
pyvolcans_func.py. In this way, we will not need to return the variable
`my_volcano_data_dictionary` in the aforementioned function (NB. To be
done in the next commit).
…ighted_analogy_matrix()

This change implied further changes on pyvolcans.py and
test_pyvolcans.py. NB. The `check_for_criteria_without_data()`
function does not need to be imported in pyvolcans.py anymore.
A new, very simple function (`format_warning_message()`) has been
created to handle the formatting of the warning messages, instead of
using `warnings.warn()`. In the documentation of the functions that
check for missing-data volcanological criteria and the occurrence of
'perfect analogues', outdated references to the raise of PyvolcansError
have been deleted.
Copy link
Collaborator

@mobiuscreek mobiuscreek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PTierz , looking at this part now, 541-545

Odd suggestion from the link you give. It could be done in a more clear way as iterating through a dictionary with .items() returns key value pairs so you could just have this:

for key, value in my_volcano_data.items():
          if value == 0: 
             my_volcano_list.append(key)

@mobiuscreek
Copy link
Collaborator

mobiuscreek commented Sep 30, 2021

Thank you for the changes! It works as intended and described.

One thing I would probably add is that it would be helpful if the message referred to the criteria in a standardized way, and used the flags:

PyVOLCANS: WARNING!!! The following volcanological criteria do not have any data available for the selected target volcano (Toliman) --> Eruption Size (-Sz), Eruption Style (-St).

That way the user would know what criteria we refer to and could immediately input the correct weightings. Do you think that's reasonable?

Moreover, I don't know if that's a consideration or something we would like to do but for example if I provide:

pyvolcans Toliman -Sz 1 -St 0 or pyvolcans Toliman -G 1 -St 0 -Sz 0

I still get the warning even though I've set the eruption style and size to zero.

  • Do we want this warning to always show up because of the missing data and it doesn't matter if the user has already set the criteria to 0?
  • Following the same logic, the warning doesn't change, it always returns the same criteria. For example in the first case, would we want it to only warn us that the eruption style should be set to zero?

@PTierz PTierz removed the request for review from volcan01010 September 30, 2021 15:49
With this commit, the warning message related to volcanological criteria
for which there is no available data (for the specific target volcano)
is only printed if that particular criterion is used in the weighting
scheme selected by the user: that is, if the weight for that particular
volcanological criterion is greater than zero. Otherwise, no warning
message will appear because, strictly speaking, data are available
for all the selected criteria (those with weight > 0).
@PTierz
Copy link
Collaborator Author

PTierz commented Sep 30, 2021

Hi @PTierz , looking at this part now, 541-545

Odd suggestion from the link you give. It could be done in a more clear way as iterating through a dictionary with .items() returns key value pairs so you could just have this:

for key, value in my_volcano_data.items():
          if value == 0: 
             my_volcano_list.append(key)

Hi @mobiuscreek!

Many thanks for pointing this out! You're right. It could easily be simplified. I did so in commit 4f992dc.

Thanks again!
Pablo

@PTierz
Copy link
Collaborator Author

PTierz commented Sep 30, 2021

Thank you for the changes! It works as intended and described.

One thing I would probably add is that it would be helpful if the message referred to the criteria in a standardized way, and used the flags:

PyVOLCANS: WARNING!!! The following volcanological criteria do not have any data available for the selected target volcano (Toliman) --> Eruption Size (-Sz), Eruption Style (-St).

That way the user would know what criteria we refer to and could immediately input the correct weightings. Do you think that's reasonable?

Moreover, I don't know if that's a consideration or something we would like to do but for example if I provide:

pyvolcans Toliman -Sz 1 -St 0 or pyvolcans Toliman -G 1 -St 0 -Sz 0

I still get the warning even though I've set the eruption style and size to zero.

  • Do we want this warning to always show up because of the missing data and it doesn't matter if the user has already set the criteria to 0?
  • Following the same logic, the warning doesn't change, it always returns the same criteria. For example in the first case, would we want it to only warn us that the eruption style should be set to zero?

Hi @mobiuscreek !

Very many thanks for this comment as well!

Regarding your first point on the formatting of the Warning message, I am not 100% sure whether the effort required to implement those changes, compared with the benefits, could be a bit overkill. What do you think? Of course, I may be missing an extremely easy fix, in which case, please feel free to implement it! :) (many thanks!).

Concerning your second point, this is something that I had already thought about, and I think it makes sense implementing it. I made commit 5876584 to address the issue. Now, the Warning message should only show up when the criterion without available data has a weight > 0 in the weighting scheme selected by the user. To ensure this intended behaviour, could you please check the acceptance criteria below?

Very many thanks in advance!
All the best,
Pablo

Acceptance criteria

  • pyvolcans "Korath Range" -Ts 1 prints the Warning message PyVOLCANS: WARNING!!! All top analogue volcanoes have the same value of total analogy. Please be aware of possible data deficiencies and/or the use of a simplified weighting scheme (see Tierz et al., 2019, for more details).
  • pyvolcans "Korath Range" -Ts 0.5 -G 0.5 does not print any Warning message
  • pyvolcans "Korath Range" -Ts 1/3 -G 1/3 -M 1/3 prints the Warning message PyVOLCANS: WARNING!!! The following selected criteria do not have any data available for the selected target volcano (Korath Range) --> morphology. Please consider excluding these criteria from your weighting scheme (i.e. setting their weights to zero).
  • pyvolcans "Korath Range" -Ts 1/4 -G 1/4 -M 1/4 -Sz 1/4 prints the Warning message PyVOLCANS: WARNING!!! The following selected criteria do not have any data available for the selected target volcano (Korath Range) --> morphology, eruption_size. Please consider excluding these criteria from your weighting scheme (i.e. setting their weights to zero).
  • pyvolcans "Korath Range" prints the Warning PyVOLCANS: WARNING!!! The following selected criteria do not have any data available for the selected target volcano (Korath Range) --> morphology, eruption_size, eruption_style. Please consider excluding these criteria from your weighting scheme (i.e. setting their weights to zero).

@PTierz PTierz requested a review from volcan01010 October 1, 2021 08:31
@mobiuscreek
Copy link
Collaborator

It looks good @PTierz. Thanks for the change. If you run the examples you mentioned above one last time, just to double check that the addition of the flags (-Sz, -St etc. ) in the warning message are correct and work in the last commit we should merge it.

@volcan01010
Copy link
Contributor

I've just been through this and checked the results against the updated criteria. All are matching.

Replacing the formatwarning function allows us to define the warning
style while still raising genuine warnings.  This is useful because
users may want to filter/suppress the messages as we have done with the
FuzzyWuzzy messages.

Renaming the "check_for..." functions to "warn_on..." makes their
purpose more explicit.
@volcan01010
Copy link
Contributor

I tweaked the warning code so that we can capture and handle the warnings. I also added a test and made some minor Flake8 fixes. If you are happy with the changes, I am happy for this to be merged now.

@PTierz
Copy link
Collaborator Author

PTierz commented Oct 6, 2021

Thank you very much, @mobiuscreek, @volcan01010, for all the changes!
I think we can now merge.
All the best,
Pablo

@PTierz PTierz merged commit dbefe96 into main Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants