3
\$\begingroup\$

The problem is this. Forecast model data indicates at 0700Z the 1000 milibar temps will be -4C°. The forecaster knows that is incorrect, so they choose to make a correction. This correction should have a diminishing affect across the axes. The forecaster can set the threshold of correction via 2 sliders. time and height axis_0_weight axis_1_weight.

data temps

data = [{'2022-02-19 06:00:00': -61, '2022-02-19 07:00:00': -61, '2022-02-19 08:00:00': -61, '2022-02-19 09:00:00': -62, '2022-02-19 10:00:00': -63, '2022-02-19 11:00:00': -63, '2022-02-19 12:00:00': -64, '2022-02-19 13:00:00': -63, '2022-02-19 14:00:00': -62, '2022-02-19 15:00:00': -63}, {'2022-02-19 06:00:00': -60, '2022-02-19 07:00:00': -60, '2022-02-19 08:00:00': -60, '2022-02-19 09:00:00': -61, '2022-02-19 10:00:00': -60, '2022-02-19 11:00:00': -61, '2022-02-19 12:00:00': -61, '2022-02-19 13:00:00': -61, '2022-02-19 14:00:00': -60, '2022-02-19 15:00:00': -60}, {'2022-02-19 06:00:00': -60, '2022-02-19 07:00:00': -60, '2022-02-19 08:00:00': -60, '2022-02-19 09:00:00': -59, '2022-02-19 10:00:00': -59, '2022-02-19 11:00:00': -60, '2022-02-19 12:00:00': -59, '2022-02-19 13:00:00': -59, '2022-02-19 14:00:00': -59, '2022-02-19 15:00:00': -58}, {'2022-02-19 06:00:00': -57, '2022-02-19 07:00:00': -57, '2022-02-19 08:00:00': -56, '2022-02-19 09:00:00': -55, '2022-02-19 10:00:00': -55, '2022-02-19 11:00:00': -55, '2022-02-19 12:00:00': -55, '2022-02-19 13:00:00': -55, '2022-02-19 14:00:00': -55, '2022-02-19 15:00:00': -55}, {'2022-02-19 06:00:00': -55, '2022-02-19 07:00:00': -54, '2022-02-19 08:00:00': -53, '2022-02-19 09:00:00': -52, '2022-02-19 10:00:00': -53, '2022-02-19 11:00:00': -52, '2022-02-19 12:00:00': -52, '2022-02-19 13:00:00': -52, '2022-02-19 14:00:00': -52, '2022-02-19 15:00:00': -52}, {'2022-02-19 06:00:00': -52, '2022-02-19 07:00:00': -52, '2022-02-19 08:00:00': -51, '2022-02-19 09:00:00': -51, '2022-02-19 10:00:00': -51, '2022-02-19 11:00:00': -50, '2022-02-19 12:00:00': -50, '2022-02-19 13:00:00': -50, '2022-02-19 14:00:00': -50, '2022-02-19 15:00:00': -49}, {'2022-02-19 06:00:00': -50, '2022-02-19 07:00:00': -50, '2022-02-19 08:00:00': -49, '2022-02-19 09:00:00': -49, '2022-02-19 10:00:00': -49, '2022-02-19 11:00:00': -49, '2022-02-19 12:00:00': -48, '2022-02-19 13:00:00': -48, '2022-02-19 14:00:00': -48, '2022-02-19 15:00:00': -47}, {'2022-02-19 06:00:00': -50, '2022-02-19 07:00:00': -50, '2022-02-19 08:00:00': -50, '2022-02-19 09:00:00': -50, '2022-02-19 10:00:00': -50, '2022-02-19 11:00:00': -50, '2022-02-19 12:00:00': -50, '2022-02-19 13:00:00': -49, '2022-02-19 14:00:00': -49, '2022-02-19 15:00:00': -48}, {'2022-02-19 06:00:00': -50, '2022-02-19 07:00:00': -50, '2022-02-19 08:00:00': -50, '2022-02-19 09:00:00': -51, '2022-02-19 10:00:00': -52, '2022-02-19 11:00:00': -51, '2022-02-19 12:00:00': -51, '2022-02-19 13:00:00': -50, '2022-02-19 14:00:00': -49, '2022-02-19 15:00:00': -49}, {'2022-02-19 06:00:00': -51, '2022-02-19 07:00:00': -51, '2022-02-19 08:00:00': -52, '2022-02-19 09:00:00': -53, '2022-02-19 10:00:00': -53, '2022-02-19 11:00:00': -53, '2022-02-19 12:00:00': -53, '2022-02-19 13:00:00': -52, '2022-02-19 14:00:00': -50, '2022-02-19 15:00:00': -49}, {'2022-02-19 06:00:00': -51, '2022-02-19 07:00:00': -53, '2022-02-19 08:00:00': -54, '2022-02-19 09:00:00': -55, '2022-02-19 10:00:00': -54, '2022-02-19 11:00:00': -55, '2022-02-19 12:00:00': -55, '2022-02-19 13:00:00': -54, '2022-02-19 14:00:00': -51, '2022-02-19 15:00:00': -49}, {'2022-02-19 06:00:00': -51, '2022-02-19 07:00:00': -51, '2022-02-19 08:00:00': -51, '2022-02-19 09:00:00': -51, '2022-02-19 10:00:00': -51, '2022-02-19 11:00:00': -51, '2022-02-19 12:00:00': -51, '2022-02-19 13:00:00': -50, '2022-02-19 14:00:00': -49, '2022-02-19 15:00:00': -48}, {'2022-02-19 06:00:00': -50, '2022-02-19 07:00:00': -50, '2022-02-19 08:00:00': -48, '2022-02-19 09:00:00': -48, '2022-02-19 10:00:00': -47, '2022-02-19 11:00:00': -47, '2022-02-19 12:00:00': -47, '2022-02-19 13:00:00': -47, '2022-02-19 14:00:00': -48, '2022-02-19 15:00:00': -47}, {'2022-02-19 06:00:00': -47, '2022-02-19 07:00:00': -47, '2022-02-19 08:00:00': -45, '2022-02-19 09:00:00': -44, '2022-02-19 10:00:00': -44, '2022-02-19 11:00:00': -44, '2022-02-19 12:00:00': -44, '2022-02-19 13:00:00': -44, '2022-02-19 14:00:00': -44, '2022-02-19 15:00:00': -44}, {'2022-02-19 06:00:00': -44, '2022-02-19 07:00:00': -43, '2022-02-19 08:00:00': -43, '2022-02-19 09:00:00': -41, '2022-02-19 10:00:00': -41, '2022-02-19 11:00:00': -40, '2022-02-19 12:00:00': -40, '2022-02-19 13:00:00': -41, '2022-02-19 14:00:00': -41, '2022-02-19 15:00:00': -41}, {'2022-02-19 06:00:00': -40, '2022-02-19 07:00:00': -40, '2022-02-19 08:00:00': -40, '2022-02-19 09:00:00': -39, '2022-02-19 10:00:00': -38, '2022-02-19 11:00:00': -38, '2022-02-19 12:00:00': -37, '2022-02-19 13:00:00': -37, '2022-02-19 14:00:00': -38, '2022-02-19 15:00:00': -38}, {'2022-02-19 06:00:00': -37, '2022-02-19 07:00:00': -37, '2022-02-19 08:00:00': -37, '2022-02-19 09:00:00': -36, '2022-02-19 10:00:00': -36, '2022-02-19 11:00:00': -35, '2022-02-19 12:00:00': -34, '2022-02-19 13:00:00': -34, '2022-02-19 14:00:00': -35, '2022-02-19 15:00:00': -35}, {'2022-02-19 06:00:00': -34, '2022-02-19 07:00:00': -34, '2022-02-19 08:00:00': -34, '2022-02-19 09:00:00': -34, '2022-02-19 10:00:00': -34, '2022-02-19 11:00:00': -33, '2022-02-19 12:00:00': -32, '2022-02-19 13:00:00': -32, '2022-02-19 14:00:00': -32, '2022-02-19 15:00:00': -33}, {'2022-02-19 06:00:00': -31, '2022-02-19 07:00:00': -31, '2022-02-19 08:00:00': -31, '2022-02-19 09:00:00': -31, '2022-02-19 10:00:00': -31, '2022-02-19 11:00:00': -31, '2022-02-19 12:00:00': -30, '2022-02-19 13:00:00': -29, '2022-02-19 14:00:00': -29, '2022-02-19 15:00:00': -31}, {'2022-02-19 06:00:00': -28, '2022-02-19 07:00:00': -28, '2022-02-19 08:00:00': -28, '2022-02-19 09:00:00': -28, '2022-02-19 10:00:00': -28, '2022-02-19 11:00:00': -28, '2022-02-19 12:00:00': -28, '2022-02-19 13:00:00': -27, '2022-02-19 14:00:00': -28, '2022-02-19 15:00:00': -30}, {'2022-02-19 06:00:00': -26, '2022-02-19 07:00:00': -25, '2022-02-19 08:00:00': -25, '2022-02-19 09:00:00': -26, '2022-02-19 10:00:00': -26, '2022-02-19 11:00:00': -26, '2022-02-19 12:00:00': -27, '2022-02-19 13:00:00': -26, '2022-02-19 14:00:00': -27, '2022-02-19 15:00:00': -29}, {'2022-02-19 06:00:00': -23, '2022-02-19 07:00:00': -23, '2022-02-19 08:00:00': -23, '2022-02-19 09:00:00': -23, '2022-02-19 10:00:00': -23, '2022-02-19 11:00:00': -23, '2022-02-19 12:00:00': -24, '2022-02-19 13:00:00': -24, '2022-02-19 14:00:00': -27, '2022-02-19 15:00:00': -28}, {'2022-02-19 06:00:00': -21, '2022-02-19 07:00:00': -21, '2022-02-19 08:00:00': -21, '2022-02-19 09:00:00': -21, '2022-02-19 10:00:00': -21, '2022-02-19 11:00:00': -21, '2022-02-19 12:00:00': -22, '2022-02-19 13:00:00': -23, '2022-02-19 14:00:00': -27, '2022-02-19 15:00:00': -28}, {'2022-02-19 06:00:00': -19, '2022-02-19 07:00:00': -19, '2022-02-19 08:00:00': -19, '2022-02-19 09:00:00': -19, '2022-02-19 10:00:00': -19, '2022-02-19 11:00:00': -19, '2022-02-19 12:00:00': -21, '2022-02-19 13:00:00': -23, '2022-02-19 14:00:00': -26, '2022-02-19 15:00:00': -27}, {'2022-02-19 06:00:00': -17, '2022-02-19 07:00:00': -17, '2022-02-19 08:00:00': -17, '2022-02-19 09:00:00': -17, '2022-02-19 10:00:00': -17, '2022-02-19 11:00:00': -17, '2022-02-19 12:00:00': -19, '2022-02-19 13:00:00': -23, '2022-02-19 14:00:00': -25, '2022-02-19 15:00:00': -27}, {'2022-02-19 06:00:00': -16, '2022-02-19 07:00:00': -15, '2022-02-19 08:00:00': -15, '2022-02-19 09:00:00': -15, '2022-02-19 10:00:00': -15, '2022-02-19 11:00:00': -16, '2022-02-19 12:00:00': -18, '2022-02-19 13:00:00': -21, '2022-02-19 14:00:00': -23, '2022-02-19 15:00:00': -24}, {'2022-02-19 06:00:00': -15, '2022-02-19 07:00:00': -14, '2022-02-19 08:00:00': -14, '2022-02-19 09:00:00': -13, '2022-02-19 10:00:00': -13, '2022-02-19 11:00:00': -15, '2022-02-19 12:00:00': -17, '2022-02-19 13:00:00': -20, '2022-02-19 14:00:00': -21, '2022-02-19 15:00:00': -22}, {'2022-02-19 06:00:00': -14, '2022-02-19 07:00:00': -13, '2022-02-19 08:00:00': -13, '2022-02-19 09:00:00': -12, '2022-02-19 10:00:00': -13, '2022-02-19 11:00:00': -15, '2022-02-19 12:00:00': -17, '2022-02-19 13:00:00': -18, '2022-02-19 14:00:00': -19, '2022-02-19 15:00:00': -20}, {'2022-02-19 06:00:00': -12, '2022-02-19 07:00:00': -13, '2022-02-19 08:00:00': -12, '2022-02-19 09:00:00': -12, '2022-02-19 10:00:00': -13, '2022-02-19 11:00:00': -15, '2022-02-19 12:00:00': -16, '2022-02-19 13:00:00': -16, '2022-02-19 14:00:00': -17, '2022-02-19 15:00:00': -18}, {'2022-02-19 06:00:00': -11, '2022-02-19 07:00:00': -12, '2022-02-19 08:00:00': -12, '2022-02-19 09:00:00': -13, '2022-02-19 10:00:00': -13, '2022-02-19 11:00:00': -15, '2022-02-19 12:00:00': -14, '2022-02-19 13:00:00': -15, '2022-02-19 14:00:00': -15, '2022-02-19 15:00:00': -16}, {'2022-02-19 06:00:00': -10, '2022-02-19 07:00:00': -10, '2022-02-19 08:00:00': -12, '2022-02-19 09:00:00': -13, '2022-02-19 10:00:00': -13, '2022-02-19 11:00:00': -14, '2022-02-19 12:00:00': -13, '2022-02-19 13:00:00': -13, '2022-02-19 14:00:00': -13, '2022-02-19 15:00:00': -15}, {'2022-02-19 06:00:00': -8, '2022-02-19 07:00:00': -9, '2022-02-19 08:00:00': -11, '2022-02-19 09:00:00': -12, '2022-02-19 10:00:00': -12, '2022-02-19 11:00:00': -12, '2022-02-19 12:00:00': -12, '2022-02-19 13:00:00': -11, '2022-02-19 14:00:00': -12, '2022-02-19 15:00:00': -15}, {'2022-02-19 06:00:00': -8, '2022-02-19 07:00:00': -8, '2022-02-19 08:00:00': -9, '2022-02-19 09:00:00': -11, '2022-02-19 10:00:00': -11, '2022-02-19 11:00:00': -11, '2022-02-19 12:00:00': -10, '2022-02-19 13:00:00': -10, '2022-02-19 14:00:00': -10, '2022-02-19 15:00:00': -14}, {'2022-02-19 06:00:00': -9, '2022-02-19 07:00:00': -8, '2022-02-19 08:00:00': -7, '2022-02-19 09:00:00': -9, '2022-02-19 10:00:00': -10, '2022-02-19 11:00:00': -9, '2022-02-19 12:00:00': -9, '2022-02-19 13:00:00': -8, '2022-02-19 14:00:00': -8, '2022-02-19 15:00:00': -12}, {'2022-02-19 06:00:00': -10, '2022-02-19 07:00:00': -8, '2022-02-19 08:00:00': -7, '2022-02-19 09:00:00': -7, '2022-02-19 10:00:00': -9, '2022-02-19 11:00:00': -8, '2022-02-19 12:00:00': -8, '2022-02-19 13:00:00': -7, '2022-02-19 14:00:00': -7, '2022-02-19 15:00:00': -10}, {'2022-02-19 06:00:00': -10, '2022-02-19 07:00:00': -8, '2022-02-19 08:00:00': -7, '2022-02-19 09:00:00': -6, '2022-02-19 10:00:00': -8, '2022-02-19 11:00:00': -7, '2022-02-19 12:00:00': -6, '2022-02-19 13:00:00': -6, '2022-02-19 14:00:00': -5, '2022-02-19 15:00:00': -8}, {'2022-02-19 06:00:00': -10, '2022-02-19 07:00:00': -9, '2022-02-19 08:00:00': -8, '2022-02-19 09:00:00': -6, '2022-02-19 10:00:00': -7, '2022-02-19 11:00:00': -6, '2022-02-19 12:00:00': -5, '2022-02-19 13:00:00': -4, '2022-02-19 14:00:00': -4, '2022-02-19 15:00:00': -6}, {'2022-02-19 06:00:00': -10, '2022-02-19 07:00:00': -9, '2022-02-19 08:00:00': -7, '2022-02-19 09:00:00': -6, '2022-02-19 10:00:00': -5, '2022-02-19 11:00:00': -4, '2022-02-19 12:00:00': -3, '2022-02-19 13:00:00': -3, '2022-02-19 14:00:00': -2, '2022-02-19 15:00:00': -4}, {'2022-02-19 06:00:00': -9, '2022-02-19 07:00:00': -8, '2022-02-19 08:00:00': -6, '2022-02-19 09:00:00': -5, '2022-02-19 10:00:00': -4, '2022-02-19 11:00:00': -3, '2022-02-19 12:00:00': -2, '2022-02-19 13:00:00': -1, '2022-02-19 14:00:00': -1, '2022-02-19 15:00:00': -3}]

index

index = [
    '50mb', '75mb', '100mb', '125mb', '150mb', '175mb', '200mb', '225mb',
    '250mb', '275mb', '300mb', '325mb', '350mb', '375mb', '400mb', '425mb',
    '450mb', '475mb', '500mb', '525mb', '550mb', '575mb', '600mb', '625mb',
    '650mb', '675mb', '700mb', '725mb', '750mb', '775mb', '800mb', '825mb',
    '850mb', '875mb', '900mb', '925mb', '950mb', '975mb', '1000mb'
    ]

main code

import pandas as pd
import numpy as np
CORRECTION=+20

data=...
index=...

def make_matrix(df:pd.DataFrame)->np.ndarray:
    x,y=df.shape
    arr_x,arr_y= np.vstack(np.linspace(0,1,x)),np.linspace(1,0,y)
    matrix = (arr_x+arr_y)-1
    matrix[matrix<0]=0
    return matrix

if __name__ == '__main__':
    celcius_temps = pd.DataFrame.from_records(data,index=index)
    celcius_temps.columns=pd.to_datetime(celcius_temps.columns)
    mat = make_matrix(celcius_temps)
    print(celcius_temps+np.around(mat*CORRECTION,2))

Results

original dataframe

    2022-02-19 06:00:00 ...
50mb    -61 -61 -61 -62 -63 -63 -64 -63 -62 -63
75mb    -60 -60 -60 -61 -60 -61 -61 -61 -60 -60
100mb   -60 -60 -60 -59 -59 -60 -59 -59 -59 -58
125mb   -57 -57 -56 -55 -55 -55 -55 -55 -55 -55
150mb   -55 -54 -53 -52 -53 -52 -52 -52 -52 -52
175mb   -52 -52 -51 -51 -51 -50 -50 -50 -50 -49
200mb   -50 -50 -49 -49 -49 -49 -48 -48 -48 -47
225mb   -50 -50 -50 -50 -50 -50 -50 -49 -49 -48
250mb   -50 -50 -50 -51 -52 -51 -51 -50 -49 -49
275mb   -51 -51 -52 -53 -53 -53 -53 -52 -50 -49
300mb   -51 -53 -54 -55 -54 -55 -55 -54 -51 -49
325mb   -51 -51 -51 -51 -51 -51 -51 -50 -49 -48
350mb   -50 -50 -48 -48 -47 -47 -47 -47 -48 -47
375mb   -47 -47 -45 -44 -44 -44 -44 -44 -44 -44
400mb   -44 -43 -43 -41 -41 -40 -40 -41 -41 -41
425mb   -40 -40 -40 -39 -38 -38 -37 -37 -38 -38
450mb   -37 -37 -37 -36 -36 -35 -34 -34 -35 -35
475mb   -34 -34 -34 -34 -34 -33 -32 -32 -32 -33
500mb   -31 -31 -31 -31 -31 -31 -30 -29 -29 -31
525mb   -28 -28 -28 -28 -28 -28 -28 -27 -28 -30
550mb   -26 -25 -25 -26 -26 -26 -27 -26 -27 -29
575mb   -23 -23 -23 -23 -23 -23 -24 -24 -27 -28
600mb   -21 -21 -21 -21 -21 -21 -22 -23 -27 -28
625mb   -19 -19 -19 -19 -19 -19 -21 -23 -26 -27
650mb   -17 -17 -17 -17 -17 -17 -19 -23 -25 -27
675mb   -16 -15 -15 -15 -15 -16 -18 -21 -23 -24
700mb   -15 -14 -14 -13 -13 -15 -17 -20 -21 -22
725mb   -14 -13 -13 -12 -13 -15 -17 -18 -19 -20
750mb   -12 -13 -12 -12 -13 -15 -16 -16 -17 -18
775mb   -11 -12 -12 -13 -13 -15 -14 -15 -15 -16
800mb   -10 -10 -12 -13 -13 -14 -13 -13 -13 -15
825mb   -8  -9  -11 -12 -12 -12 -12 -11 -12 -15
850mb   -8  -8  -9  -11 -11 -11 -10 -10 -10 -14
875mb   -9  -8  -7  -9  -10 -9  -9  -8  -8  -12
900mb   -10 -8  -7  -7  -9  -8  -8  -7  -7  -10
925mb   -10 -8  -7  -6  -8  -7  -6  -6  -5  -8
950mb   -10 -9  -8  -6  -7  -6  -5  -4  -4  -6
975mb   -10 -9  -7  -6  -5  -4  -3  -3  -2  -4
1000mb  -9  -8  -6  -5  -4  -3  -2  -1  -1  -3

The 1000mb 2022-02-19 06:00:00 receives 100% of the correction.

the 50mb row and 2022-02-19 15:00:00 column remain unchanged

with broadcast diminished correction


    2022-02-19 06:00:00 ...
50mb    -61.00  -61.00  -61.00  -62.00  -63.00  -63.00  -64.00  -63.00  -62.00  -63.0
75mb    -59.47  -60.00  -60.00  -61.00  -60.00  -61.00  -61.00  -61.00  -60.00  -60.0
100mb   -58.95  -60.00  -60.00  -59.00  -59.00  -60.00  -59.00  -59.00  -59.00  -58.0
125mb   -55.42  -57.00  -56.00  -55.00  -55.00  -55.00  -55.00  -55.00  -55.00  -55.0
150mb   -52.89  -54.00  -53.00  -52.00  -53.00  -52.00  -52.00  -52.00  -52.00  -52.0
175mb   -49.37  -51.59  -51.00  -51.00  -51.00  -50.00  -50.00  -50.00  -50.00  -49.0
200mb   -46.84  -49.06  -49.00  -49.00  -49.00  -49.00  -48.00  -48.00  -48.00  -47.0
225mb   -46.32  -48.54  -50.00  -50.00  -50.00  -50.00  -50.00  -49.00  -49.00  -48.0
250mb   -45.79  -48.01  -50.00  -51.00  -52.00  -51.00  -51.00  -50.00  -49.00  -49.0
275mb   -46.26  -48.49  -51.71  -53.00  -53.00  -53.00  -53.00  -52.00  -50.00  -49.0
300mb   -45.74  -49.96  -53.18  -55.00  -54.00  -55.00  -55.00  -54.00  -51.00  -49.0
325mb   -45.21  -47.43  -49.65  -51.00  -51.00  -51.00  -51.00  -50.00  -49.00  -48.0
350mb   -43.68  -45.91  -46.13  -48.00  -47.00  -47.00  -47.00  -47.00  -48.00  -47.0
375mb   -40.16  -42.38  -42.60  -43.82  -44.00  -44.00  -44.00  -44.00  -44.00  -44.0
400mb   -36.63  -37.85  -40.08  -40.30  -41.00  -40.00  -40.00  -41.00  -41.00  -41.0
425mb   -32.11  -34.33  -36.55  -37.77  -38.00  -38.00  -37.00  -37.00  -38.00  -38.0
450mb   -28.58  -30.80  -33.02  -34.25  -36.00  -35.00  -34.00  -34.00  -35.00  -35.0
475mb   -25.05  -27.27  -29.50  -31.72  -33.94  -33.00  -32.00  -32.00  -32.00  -33.0
500mb   -21.53  -23.75  -25.97  -28.19  -30.42  -31.00  -30.00  -29.00  -29.00  -31.0
525mb   -18.00  -20.22  -22.44  -24.67  -26.89  -28.00  -28.00  -27.00  -28.00  -30.0
550mb   -15.47  -16.70  -18.92  -22.14  -24.36  -26.00  -27.00  -26.00  -27.00  -29.0
575mb   -11.95  -14.17  -16.39  -18.61  -20.84  -23.00  -24.00  -24.00  -27.00  -28.0
600mb   -9.42   -11.64  -13.87  -16.09  -18.31  -20.53  -22.00  -23.00  -27.00  -28.0
625mb   -6.89   -9.12   -11.34  -13.56  -15.78  -18.01  -21.00  -23.00  -26.00  -27.0
650mb   -4.37   -6.59   -8.81   -11.04  -13.26  -15.48  -19.00  -23.00  -25.00  -27.0
675mb   -2.84   -4.06   -6.29   -8.51   -10.73  -13.95  -18.00  -21.00  -23.00  -24.0
700mb   -1.32   -2.54   -4.76   -5.98   -8.20   -12.43  -16.65  -20.00  -21.00  -22.0
725mb   0.21    -1.01   -3.23   -4.46   -7.68   -11.90  -16.12  -18.00  -19.00  -20.0
750mb   2.74    -0.49   -1.71   -3.93   -7.15   -11.37  -14.60  -16.00  -17.00  -18.0
775mb   4.26    1.04    -1.18   -4.40   -6.63   -10.85  -12.07  -15.00  -15.00  -16.0
800mb   5.79    3.57    -0.65   -3.88   -6.10   -9.32   -10.54  -12.77  -13.00  -15.0
825mb   8.32    5.09    0.87    -2.35   -4.57   -6.80   -9.02   -10.24  -12.00  -15.0
850mb   8.84    6.62    3.40    -0.82   -3.05   -5.27   -6.49   -8.71   -10.00  -14.0
875mb   8.37    7.15    5.92    1.70    -1.52   -2.74   -4.96   -6.19   -8.00   -12.0
900mb   7.89    7.67    6.45    4.23    0.01    -1.22   -3.44   -4.66   -6.88   -10.0
925mb   8.42    8.20    6.98    5.75    1.53    0.31    -0.91   -3.13   -4.36   -8.0
950mb   8.95    7.73    6.50    6.28    3.06    1.84    0.61    -0.61   -2.83   -6.0
975mb   9.47    8.25    8.03    6.81    5.58    4.36    3.14    0.92    -0.30   -4.0
1000mb  11.00   9.78    9.56    8.33    7.11    5.89    4.67    3.44    1.22    -3.0

I've looked into the numpy.linalg.lstsq method but I'm not sure how to implement it.

\$\endgroup\$
1
  • \$\begingroup\$ Data and index are as show in the original post data temps (record array) and index is a list of millibars strings \$\endgroup\$ Mar 19 at 16:13

1 Answer 1

2
\$\begingroup\$

Passing df to make_matrix is not adequately loosely coupled. Instead you can just pass its size as two integers.

I do not trust your use of vstack. I would sooner add a new dimension via slice.

Rather than conditional zeroing of the matrix in place, you should probably use np.maximum.

celcius is spelled celsius.

Don't around where you've done it. If you want to round for print, there are better ways.

Suggested

import pandas as pd
import numpy as np


def make_matrix(x: int, y: int, correction: float = 20) -> np.ndarray:
    arr_x = np.linspace(0, correction, x)[:, np.newaxis]
    arr_y = np.linspace(0, -correction, y)
    matrix = np.maximum(arr_x + arr_y, 0)
    return matrix


def main() -> None:
    celsius_temps = pd.DataFrame.from_records(data, index=index)
    celsius_temps.columns = pd.to_datetime(celsius_temps.columns)
    mat = make_matrix(*celsius_temps.shape)
    result = celsius_temps + mat
    print(result)


if __name__ == '__main__':
    main()
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Or maybe just build the correction matrix in one shot? def make_matrix(x, y, correction) \$\endgroup\$
    – tdy
    Mar 19 at 20:00
  • 1
    \$\begingroup\$ @tdy I like that idea; thanks. \$\endgroup\$
    – Reinderien
    Mar 19 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.