mrghg / py12box_invert

MIT License
3 stars 0 forks source link

Difference operator: annual difference #11

Closed mrghg closed 3 years ago

mrghg commented 3 years ago

I've modified the difference operator so that it constrains the growth between quantities separated by one year. Previously, it was between consecutive years/months/seasons, whereas the IDL code had it so that it'd constrain each month/season to the same month/season in the following/previous year.

Any chance you could write a test for this? It particularly needs checking for the final year...

mrghg commented 3 years ago

Also, I've only put the difference_operator function in the rigby14 method, but I think you also use it in some of the other methods too...

lukewestern commented 3 years ago

I'm a little confused by this difference operator. Currently it's:

    D = np.zeros((nx, nx))
    for xi in range(nx):
        if (xi % (nx/4)) < (nx/4 - freq):
            D[xi, xi] = -1.
            D[xi, xi + freq] = 1.
    return D

But in the x matrix, the emissions are [box0,box1,box2,box3,....]. So should this operate on the xi+4*freq element, as that would be the jump to the same box in the following year? Currently, if it was for a yearly inversion, xi+freq would just go to the next box, rather than the same box in the following year. Then something like:

    D = np.zeros((nx, nx))
    for xi in range(nx- 4*freq):
        D[xi, xi] = -1.
        D[xi, xi + 4*freq] = 1.    
    return D

might be more appropriate?

mrghg commented 3 years ago

You're right. The above commit should fix this. I've also added a test

lukewestern commented 3 years ago

Nice! It all looks good to me.