Skip to content
Snippets Groups Projects
Commit f29c1570 authored by William Roberts's avatar William Roberts
Browse files

Replace "inplace=" with chained function calls

parent 46f06731
No related branches found
No related tags found
No related merge requests found
......@@ -92,9 +92,8 @@ class Updater(object):
return self._calculate_averages()
def _calculate_averages(self):
index = self.data.pop('timestamp')
frame = pd.DataFrame(self.data, index=index)
frame.mask(frame == -99999., inplace=True)
frame = pd.DataFrame(self.data)
frame = frame.set_index('timestamp').mask(frame == -99999.)
# Add wind direction components so we can average wind direction properly.
frame['wind_east'], frame['wind_north'], _ = calc.wind_vector_components(frame['wind_speed'],
frame['wind_dir'])
......@@ -112,8 +111,8 @@ class Updater(object):
frame['wind_dir_2m'] = calc.wind_vector_degrees(winds_frame_2m['wind_east'], winds_frame_2m['wind_north'])
# Makes 2 minute averages nans if given less than 2 minutes of data.
if len(frame[frame.index > frame.index[-1] - timedelta(minutes=2)]) < 120 / self.data_interval:
frame['wind_speed_2m'].mask(frame['wind_speed_2m'] > -1., inplace=True)
frame['wind_dir_2m'].mask(frame['wind_dir_2m'] > -1., inplace=True)
frame['wind_speed_2m'] = frame['wind_speed_2m'].mask(frame['wind_speed_2m'] > -1.)
frame['wind_dir_2m'] = frame['wind_dir_2m'].mask(frame['wind_dir_2m'] > -1.)
# 1 minute rolling peaks
wind_peak_1m = frame['wind_speed'].rolling(window='1T', closed='right').max()
# criteria for a fast wind to be considered a wind gust
......@@ -123,7 +122,7 @@ class Updater(object):
frame['gust_10m'] = calculate_wind_gust(frame['wind_speed'], winds_frame_2m['wind_speed'])
# Makes 10 minute gusts before 12 minutes nans because data is insufficient.
if len(frame) < 720 / self.data_interval:
frame['gust_10m'].mask(frame['gust_10m'] > -1., inplace=True)
frame['gust_10m'] = frame['gust_10m'].mask(frame['gust_10m'] > -1.)
return frame.fillna(value=np.nan)
......
......@@ -37,9 +37,7 @@ def _get_data(input_files):
def get_data(input_files):
frame = pd.DataFrame(_get_data(input_files))
frame.set_index('stamp', inplace=True)
frame.mask(frame == -99999., inplace=True)
frame.fillna(value=np.nan, inplace=True)
frame = frame.set_index('stamp').mask(frame == -99999.).fillna(value=np.nan)
return frame
......@@ -103,12 +101,11 @@ def create_giant_netcdf(input_files, output_fn, zlib, chunk_size,
# average the values
if summary:
frame = summary_over_interval(new_frame, interval_width)
frame = summary_over_interval(new_frame, interval_width).fillna(np.nan)
else:
frame = new_frame.resample(interval_width, closed='right', loffset=interval_width).mean()
frame = new_frame.resample(interval_width, closed='right', loffset=interval_width).mean().fillna(np.nan)
frame['wind_dir'] = calc.wind_vector_degrees(frame['wind_east'], frame['wind_north'])
frame['gust'] = new_frame['gust'].resample(interval_width, closed='right', loffset=interval_width).max()
frame.fillna(np.nan, inplace=True)
if start and end:
frame = frame[start.strftime('%Y-%m-%d %H:%M:%S'): end.strftime('%Y-%m-%d %H:%M:%S')]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment