Not sure if this will end up as a post or just be added to an ealier one.

Bug

I was attempting to repeat a gnarly style image with transforms but it was not repeating properly. Here’s the image I wanted to repeat, followed by what I was getting. The repeat image was to be 6 x 6 inches and 300 dpi with a base margin of 0.5 inches.

gnarly image with transforms that I want to repeat at a different size and dpi
Gnarly spirograph image with transforms to be repeated
the first, bad attempt at repeating the above image with the revised parameters
Failed attempt to repeat the above image with the revised paramaters

I spent at least an hour or two trying to get it to work. No such luck. Finally gave up. Though I really should have figured it out. But, I was more caught up in the fact that it wasn’t working than in trying to logically get to a solution.

I woke up in the middle of that night (likely around 02:00) and the answer just popped into my head. Quite an amazing feeling, as when it came to my mind, it was instantly obvious that was the issue.

Solution

I have been adding image types to the repeat path basically one at a time. Refactoring the functions involved in generating the repeat to get the new image type to work. I apparently did not adequately test my refactoring for the gnarly spirograph image type.

You may recall that for the gnarly type images I drop some rows (randomly selected number) from the top or bottom of the image’s dataset. In my haste to get the repeat function working for this type of image, I failed to include the code to make that happen when generating the repeat. That was why my attempt to regenerate the above image failed. And why there were so many more lines plotted in the attempted repeat. I had failed to drop the top row of data. That extra data in the image really should have told me what was happening. But sometimes our minds just aren’t open enough to the moment. Expect age makes that worse.

So, I added the following code to the set_rpt_data() function.

if 'gnarly' in r.d_rpt[r.do_nbr]['i_typ']:
    g.r_skp = int(r.d_rpt[r.do_nbr]['drows'])
    g.drp_f = True if r.d_rpt[r.do_nbr]['torb'] == 'top' else False

And bingo.

I also, as I was looking around, noticed one other possible issue. So, in the get_curve_data() function, I changed if i_type == 'mosaic': to if 'mosaic' in i_type:. The former was not accounting for mosaic type images with transforms. I already had the latter in an if block lower down in the function (which was what alerted me to the potential problem).

And here’s the proper repeat with the larger margins. (Size and dpi reduced for display on the web page.)

a successful attempt at repeating the above image with the revised parameters
Successful attempt to repeat the above image with the revised paramaters

And, I am truly pleased as I am thinking this will likely be an image I will get printed and framed. Though I may yet lighten the curve colours a touch.

Another Bug

Turns out that in my repeat code for the gnarly image type with transforms, I was not using the alpha value from the original image! So in the transform plotting loop I replaced ax.plot(dt_x[i], dt_y[i], lw=g.ln_w, alpha=1) with ax.plot(dt_x[i], dt_y[i], lw=g.ln_w, alpha=g.alph). Not really sure why I had that alpha=1 in there. I had also changed the list of colour starting indices during my messing around. So, I have set that back to its original value.

There are still some colour differences in the repeat image. But, it is close enough to the original for me to be happy with the result.

repeat attempt after fixing the alpha argument value
Repeat attempt after fixing the alpha argument value

Changing Colour Maps on Repeat — Another Bug

I had thought I was done with this post. Had even added the closing section. But, then while trying to change a spirograph’s colour map when generating a repeat I ran into a problem.

Here’s the values I was using trying to force the repeat route code to select a new colour cycle and starting colour index for each transform. I found Set3 to be too pale, so wanted to try Set2. The value of the previous c_cyc field was based on Set3, so I needed to remove it. And, I also wanted the code to use different starting colour indexes. At least until I found a repeat image I liked.

    # 'cmap': 'Set3',
    'cmap': 'Set2',
    'c_cyc': [],
    'c_lpha': 1.0,
    'c_ndx': 61,

This approach has worked in the past, for other image types. But for the mosaic with tranforms I was trying to repeat…

  File "R:\learn\py_play\sp_fa\main.py", line 1251, in sp_repeat
    set_rpt_data()
  File "R:\learn\py_play\sp_fa\main.py", line 1027, in set_rpt_data
    g.c_ndx = [rng.integers(0, c_len-2) for _ in range(int(r.d_rpt[r.do_nbr]['ntr']))]
  File "R:\learn\py_play\sp_fa\main.py", line 1027, in <listcomp>
    g.c_ndx = [rng.integers(0, c_len-2) for _ in range(int(r.d_rpt[r.do_nbr]['ntr']))]
  File "_generator.pyx", line 543, in numpy.random._generator.Generator.integers

  File "_bounded_integers.pyx", line 1247, in numpy.random._bounded_integers._rand_int64

ValueError: high <= 0

Here’s the bit of code that needed fixing. More specifically the line setting the value for c_len.

  if r.d_rpt[r.do_nbr]['i_typ'][-2:] == '_t' and isinstance(g.c_ndx, int):
    c_len = len(g.cycle)
    g.c_ndx = [rng.integers(0, c_len-2) for _ in range(int(r.d_rpt[r.do_nbr]['ntr']))]
    g.c_ndx[-1] = r.d_rpt[r.do_nbr]['c_ndx']

I changed that to:

    c_len = len(g.cycle) if g.cycle else r.d_rpt[r.do_nbr]['c_frq']

And, that appeared to fix things. Here’s the version of the various repeat attempts that I have currently settled on (modified for display on this web page).

repeat attempt after allowing for colour map changes
Selected repeat attempt after sorting out changing colour maps

A nice, gentle image. Should look good on the wall.

Done

I (for a second time) think that’s it for this one. Focused. Not too long. And relatively successful. A good day or two!