Code Duplication    Length = 23-33 lines in 2 locations

examples/gridding/Point_Interpolation.py 1 location

@@ 37-69 (lines=33) @@
34
    return view
35
36
37
def station_test_data(variable_names, proj_from=None, proj_to=None):
38
39
    f = get_test_data('station_data.txt')
40
41
    all_data = np.loadtxt(f, skiprows=1, delimiter=',',
42
                          usecols=(1, 2, 3, 4, 5, 6, 7, 17, 18, 19),
43
                          dtype=np.dtype([('stid', '3S'), ('lat', 'f'), ('lon', 'f'),
44
                                          ('slp', 'f'), ('air_temperature', 'f'),
45
                                          ('cloud_fraction', 'f'), ('dewpoint', 'f'),
46
                                          ('weather', '16S'),
47
                                          ('wind_dir', 'f'), ('wind_speed', 'f')]))
48
49
    all_stids = [s.decode('ascii') for s in all_data['stid']]
50
51
    data = np.concatenate([all_data[all_stids.index(site)].reshape(1, ) for site in all_stids])
52
53
    value = data[variable_names]
54
    lon = data['lon']
55
    lat = data['lat']
56
57
    if proj_from is not None and proj_to is not None:
58
59
        try:
60
61
            proj_points = proj_to.transform_points(proj_from, lon, lat)
62
            return proj_points[:, 0], proj_points[:, 1], value
63
64
        except Exception as e:
65
66
            print(e)
67
            return None
68
69
    return lon, lat, value
70
71
72
from_proj = ccrs.Geodetic()

examples/gridding/Wind_SLP_Interpolation.py 1 location

@@ 27-49 (lines=23) @@
24
to_proj = ccrs.AlbersEqualArea(central_longitude=-97., central_latitude=38.)
25
26
27
def station_test_data(variable_names, proj_from=None, proj_to=None):
28
    f = get_test_data('station_data.txt')
29
30
    all_data = np.loadtxt(f, skiprows=1, delimiter=',',
31
                          usecols=(1, 2, 3, 4, 5, 6, 7, 17, 18, 19),
32
                          dtype=np.dtype([('stid', '3S'), ('lat', 'f'), ('lon', 'f'),
33
                                          ('slp', 'f'), ('air_temperature', 'f'),
34
                                          ('cloud_fraction', 'f'), ('dewpoint', 'f'),
35
                                          ('weather', '16S'),
36
                                          ('wind_dir', 'f'), ('wind_speed', 'f')]))
37
38
    all_stids = [s.decode('ascii') for s in all_data['stid']]
39
    data = np.concatenate([all_data[all_stids.index(site)].reshape(1, ) for site in all_stids])
40
41
    value = data[variable_names]
42
    lon = data['lon']
43
    lat = data['lat']
44
45
    if proj_from is not None and proj_to is not None:
46
            proj_points = proj_to.transform_points(proj_from, lon, lat)
47
            return proj_points[:, 0], proj_points[:, 1], value
48
49
    return lon, lat, value
50
51
52
###########################################