metno / titanlib

Automatic data quality control software library
GNU Lesser General Public License v3.0
30 stars 8 forks source link

Running "First guess test" using Python #26

Open meteorolog90 opened 1 year ago

meteorolog90 commented 1 year ago

Greetings. My goal is to set up a first guess test using Python. The Wiki only has R-code examples, so I converted them to Python syntax. My setup looks like this:

N = len(lats)

obs_to_check = np.array([1])
obs_to_check = np.repeat(obs_to_check, N, axis = 0)

background_values = np.array([0])
background_values = np.repeat(background_values, N, axis = 0)

background_uncertainties = np.array([1])
background_uncertainties = np.repeat(background_uncertainties, N, axis = 0)

background_elab_type = "MedianOuterCircle"
T = 'True'

num_min_outer = 3
num_max_outer = 10
inner_radius = 20000
outer_radius = 50000
num_iterations = 10
num_min_prof = 0
min_elev_diff = 100
min_horizontal_scale = 250 
max_horizontal_scale = 100000
kth_closest_obs_horizontal_scale = 2
tpos = np.repeat(obs_to_check, N, axis = 0) * 5
tneg = np.repeat(obs_to_check, N, axis = 0) * 5
values_mina = [num-20 for num in temp]
values_maxa = [num+20 for num in temp]
values_minv = [num-1 for num in temp]
values_maxv = [num+1 for num in temp]
debug = T
basic = T

res = titanlib.fgt( points, temp, obs_to_check,

    background_values, 
    background_uncertainties, 
    background_elab_type, 
    num_min_outer, 
    num_max_outer, 
    inner_radius, 
    outer_radius, 
    num_iterations, 
    num_min_prof, 
    min_elev_diff, 
    values_mina, 
    values_maxa, 
    values_minv, 
    values_maxv, 
    tpos, 
    tneg, 
    debug, 
    basic

)

Here is the error message I get:

File "first_quess_test.py", line 152, in <module> basic File "/users/nwp999/bin/pynwp/lib64/python3.6/site-packages/titanlib.py", line 892, in fgt return _titanlib.fgt(points, values, obs_to_check, background_values, background_uncertainties, background_elab_type, num_min_outer , num_max_outer, inner_radius, outer_radius, num_iterations, num_min_prof, min_elev_diff, value_mina, value_maxa, value_minv, value_max v, tpos, tneg, debug, basic) TypeError: in method 'fgt', argument 6 of type 'titanlib::BackgroundType'

Is it possible to run this test using Python ?

trygveasp commented 1 year ago

The background (background_elab_type) must be a background object and not a string.

I have not implemented exactly this test in pysurfex, but there is another first guess using the range_check test from titan where I have interpolated observations and background using gridpp:

https://github.com/metno/pysurfex/blob/master/pysurfex/titan.py#L277