Skip to content

Commit

Permalink
Merge pull request #165 from GEUS-Glaciology-and-Climate/164-bufr-fil…
Browse files Browse the repository at this point in the history
…es-and-position-update-stopping-at-lyn_t

164 bufr files and position update stopping at lyn t
  • Loading branch information
RasmusBahbah authored Aug 10, 2023
2 parents 3424f2c + 17eaa07 commit 86b4362
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
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

0 comments on commit 86b4362

Please sign in to comment.