Code Duplication    Length = 23-33 lines in 2 locations

examples/gridding/Point_Interpolation.py 1 location

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

examples/gridding/Wind_SLP_Interpolation.py 1 location

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