Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

164 bufr files and position update stopping at lyn t #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/getBUFR
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ if __name__ == '__main__':
print(' latest:', latest_timestamp)
no_recent_data.append(stid)
if args.positions is True:
current_timestamp = None
df1_limited, positions = find_positions(df1, stid, args.time_limit, current_timestamp, positions)
else:
print('{} not found in latest_timestamps'.format(stid))
Expand Down
18 changes: 6 additions & 12 deletions src/pypromice/postprocess/csv2bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def setBUFRvalue(ibufr, b_name, value):
print('----> {} {}'.format(b_name, value))


def linear_fit(df, column, decimals, stid, extrapolate=False):
def linear_fit(df, column, decimals, stid):
'''Apply a linear regression to the input column

Linear regression is following:
Expand Down Expand Up @@ -286,14 +286,8 @@ def linear_fit(df, column, decimals, stid, extrapolate=False):
model = LinearRegression().fit(x, y)

# Adding prediction back to original df
if extrapolate is True:
# if extrapolating, then giving all indexes of df to the linear model
x_all = df.index.values.astype(np.int64) // 10 ** 9
df['{}_fit'.format(column)] = model.predict(x_all.reshape(-1,1)).round(decimals=decimals)
else:
# if not extrapolating, then only giving to the linear model the
# indexes for which observations were available
df.loc[df_dropna.index, '{}_fit'.format(column)] = model.predict(x).round(decimals=decimals)
x_all = df.index.values.astype(np.int64) // 10 ** 9
df['{}_fit'.format(column)] = model.predict(x_all.reshape(-1,1)).round(decimals=decimals)

# Plot data if desired
# if stid == 'LYN_T':
Expand Down Expand Up @@ -414,7 +408,7 @@ def find_positions(df, stid, time_limit, current_timestamp=None, positions=None)
# Extrapolate recommended for altitude, optional for lat and lon.
df_limited, lat_valid = linear_fit(df_limited, 'gps_lat', 6, stid)
df_limited, lon_valid = linear_fit(df_limited, 'gps_lon', 6, stid)
df_limited, alt_valid = linear_fit(df_limited, 'gps_alt', 1, stid, extrapolate=True)
df_limited, alt_valid = linear_fit(df_limited, 'gps_alt', 1, stid)

# If we have no valid lat, lon or alt data in the df_limited window, then interpolate
# using full tx dataset.
Expand All @@ -425,9 +419,9 @@ def find_positions(df, stid, time_limit, current_timestamp=None, positions=None)
print(f'----> Using full history for linear extrapolation: {k}')
print(f'first transmission: {df.index.min()}')
if k == 'gps_alt':
df, valid = linear_fit(df, k, 1, stid, extrapolate=True)
df, valid = linear_fit(df, k, 1, stid)
else:
df, valid = linear_fit(df, k, 6, stid, extrapolate=True)
df, valid = linear_fit(df, k, 6, stid)
check_valid_again[k] = valid
if check_valid_again[k] is True:
df_limited[f'{k}_fit'] = df.last(time_limit)[f'{k}_fit']
Expand Down