Skip to content

Conversation

megies
Copy link
Member

@megies megies commented Oct 26, 2023

What does this PR do?

This PR fixes two partially interacting problems with how Stream "dayplots" (helicorder plots) are ticked and labeled on the x-Axis.

1. Tick Positioning

When "number_of_ticks" is not set, in many cases with sensible choice of "interval" parameter, bad automatic choice of number of x ticks were made. E.g. with "interval=10", 10 x ticks were used (should be 11), so that all ticks fall on decimal numbers.

2. Tick Labeling

The labeling of x-ticks was forced to "%i" % x, i.e. forcibly cutting of any decimals. In principle it is desirable to show "3" instead of "3.0" for the ticks but combined with the former problem leading to many cases of oddly placed ticks this was leading to plots having wrong labeling in many cases (e.g. labels 0, 1, 2, 3, ..., 12, 13, 15 with ticks not actually placed at these integers numbers).

Examples

1. Automatic routine selecting number of ticks giving picking bad number of ticks

Notice how tick labels jump from "8" to "10" on last tick label. Ticks are actually not at the integer number positions that are suggested by the labels, but rather oddly placed due to only 10 ticks for a range 0-10 (should be 11 ticks).

from obspy import UTCDateTime
from obspy.imaging.tests.test_waveform import TestWaveformPlot
start = UTCDateTime(0)
st = TestWaveformPlot()._create_stream(start, start + 3 * 3600, 100)

st.plot(type='dayplot', interval=10)

Before:
Figure_1

After: 11 ticks are chosen and now ticks actually are at the integer positions
Figure_1a

2. User chooses weird number of ticks and labeling is wrong

User chooses weird parameters, but at first glance the plot looks OK, since it does not show correct labels, all labels are decimal numbers at weird positions.

st.plot(type='dayplot', number_of_ticks=10)

Before:
Figure_2
After: ticks are still placed oddly due to user explicit choice, but now it is clear that ticks are off
Figure_2a

Why was it initiated? Any relevant Issues?

Got contacted in private mail with an example of this problem

PR Checklist

  • Correct base branch selected? master for new features, maintenance_... for bug fixes
  • This PR is not directly related to an existing issue (which has no PR yet).
  • While the PR is still work-in-progress, the no_ci label can be added to skip CI builds
  • If the PR is making changes to documentation, docs pages can be built automatically.
    Just add the build_docs tag to this PR.
    Docs will be served at docs.obspy.org/pr/{branch_name} (do not use master branch).
    Please post a link to the relevant piece of documentation.
  • If all tests including network modules (e.g. clients.fdsn) should be tested for the PR,
    just add the test_network tag to this PR.
  • All tests still pass.
  • Any new features or fixed regressions are covered via new tests.
  • Any new or changed features are fully documented.
  • Significant changes have been added to CHANGELOG.txt .
  • First time contributors have added your name to CONTRIBUTORS.txt .
  • If the changes affect any plotting functions you have checked that the plots
    from all the CI builds look correct. Add the "upload_plots" tag so that plotting
    outputs are attached as artifacts.
  • New modules, add the module to CODEOWNERS with your github handle
  • Add the yellow ready for review label when you are ready for the PR to be reviewed.

@megies megies added the .imaging Issues with our plotting functionalities label Oct 26, 2023
@megies megies added this to the 1.4.1 milestone Oct 26, 2023
@megies megies added bug confirmed bug ready for review PRs that are ready to be reviewed to get marked ready to merge labels Oct 26, 2023
showing labels with integer numbers when the location of the label is
actually at an odd position with decimal numbers.
Only cut of '.0' if actually the tick is at an integer position
e.g. for time going from 0-10 minutes we need 11 ticks, not 10, to place
them on integer numbers
don't fix to 5 ticks if less then 5 were determined somehow, just keep
multiplying with 2 so we keep the ticks at sane positions
count = 10 wasnt used as a default here due to faulty logic
@megies megies force-pushed the fix_dayplot_x_ticks branch from 36f8129 to 6d5e3a5 Compare October 26, 2023 11:06
@megies
Copy link
Member Author

megies commented Oct 26, 2023

Test fail is unrelated, should be good to go

Comment on lines +35 to +44
# To get a thick curve alternate between two curves.
data = np.empty(number_of_samples)
# Check if even number and adjust if necessary.
if number_of_samples % 2 == 0:
data[0::2] = curve
data[1::2] = curve + 0.2
else:
data[-1] = 0.0
data[0:-1][0::2] = curve
data[0:-1][1::2] = curve + 0.2
Copy link
Member

Choose a reason for hiding this comment

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

I know this is just the original code, but isn't it basically:

Suggested change
# To get a thick curve alternate between two curves.
data = np.empty(number_of_samples)
# Check if even number and adjust if necessary.
if number_of_samples % 2 == 0:
data[0::2] = curve
data[1::2] = curve + 0.2
else:
data[-1] = 0.0
data[0:-1][0::2] = curve
data[0:-1][1::2] = curve + 0.2
# To get a thick curve alternate between two curves.
curve[1::2] += 0.2
# Check if even number and adjust if necessary.
if number_of_samples % 2 == 1:
curve[-1] = 0.0

(and then data == curve.)

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like data is twice as long as curve and then curve gets squashed in twice there? in any case, not worth spending time on beautifying this piece of super old test code, I'd say. :)

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@megies megies merged commit e2d4401 into maintenance_1.4.x Nov 16, 2023
@megies megies deleted the fix_dayplot_x_ticks branch November 16, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confirmed bug .imaging Issues with our plotting functionalities ready for review PRs that are ready to be reviewed to get marked ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants