-
Notifications
You must be signed in to change notification settings - Fork 38
Zonal Mean Time Coarsener Bug #864
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
base: main
Are you sure you want to change the base?
Changes from all commits
d68f963
e92ec18
411993a
c0e2fcf
0f0136f
7b2b93a
4690d58
f88a395
f7e56e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,21 +173,17 @@ def record_batch( | |
| # if we have a buffer that means we didnt record the last batch | ||
| if self._buffer_gen: | ||
| start_idx = self.last_step | ||
| buffer_size = ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't confidently review this file, the code is hard for me to understand. The for-if statements are nested up to 4 levels, and there's communication I don't understand happening between the first outer loop (for target_data) and the second outer loop (for gen_data). I also don't really know what "buffer" means in this context. We chatted on Slack about potentially refactoring this to a helper function and cleaning it up before merging this, since this isn't a bug that usually affects us.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the buffer is some residual that gets patched on to the start of the next coarsen? If so, a model like for some suitable types T1 and T2 would be a good pattern to use |
||
| i_time_start + window_steps | ||
| ) - self.last_step * self.time_coarsening_factor | ||
| else: | ||
| start_idx = i_time_start // self.time_coarsening_factor | ||
|
|
||
| time_slice = slice( | ||
| start_idx, | ||
| (i_time_start + window_steps) // self.time_coarsening_factor, | ||
| ) | ||
|
|
||
| self.last_step = (i_time_start + window_steps) // self.time_coarsening_factor | ||
|
|
||
| buffer_size = ( | ||
| i_time_start + window_steps | ||
| ) - self.last_step * self.time_coarsening_factor | ||
| buffer_size = (i_time_start + window_steps) - ( | ||
| (i_time_start + window_steps) // self.time_coarsening_factor | ||
| ) * (self.time_coarsening_factor) | ||
|
|
||
| buffer = {} | ||
| time_slice = None | ||
| for name, tensor in target_data.items(): | ||
| if name in self._target_data: | ||
| if self._buffer_target: | ||
|
|
@@ -198,11 +194,19 @@ def record_batch( | |
| ], | ||
| dim=self._time_dim, | ||
| ) | ||
| self._target_data[name][:, time_slice, :] += self._coarsen_tensor( | ||
| self._zonal_mean(tensor) | ||
| ) | ||
| if buffer_size > 0: | ||
| buffer[name] = tensor[:, -buffer_size:, :] | ||
| coarsened = self._coarsen_tensor(self._zonal_mean(tensor)) | ||
| if time_slice is None: | ||
| # Use actual coarsened size so slice matches when i_time_start is | ||
| # misaligned with coarsening factor | ||
| n_coarsened = coarsened.shape[self._time_dim] | ||
| time_slice = slice(start_idx, start_idx + n_coarsened) | ||
| self.last_step = start_idx + n_coarsened | ||
| new_buffer_size = ( | ||
| i_time_start + window_steps | ||
| ) - self.last_step * self.time_coarsening_factor | ||
| self._target_data[name][:, time_slice, :] += coarsened | ||
| if new_buffer_size > 0: | ||
| buffer[name] = tensor[:, -new_buffer_size:, :] | ||
| self._buffer_target = buffer | ||
|
|
||
| buffer = {} | ||
|
|
@@ -216,11 +220,10 @@ def record_batch( | |
| ], | ||
| dim=self._time_dim, | ||
| ) | ||
| self._gen_data[name][:, time_slice, :] += self._coarsen_tensor( | ||
| self._zonal_mean(tensor) | ||
| ) | ||
| if buffer_size > 0: | ||
| buffer[name] = tensor[:, -buffer_size:, :] | ||
| coarsened = self._coarsen_tensor(self._zonal_mean(tensor)) | ||
| self._gen_data[name][:, time_slice, :] += coarsened | ||
| if new_buffer_size > 0: | ||
| buffer[name] = tensor[:, -new_buffer_size:, :] | ||
| self._buffer_gen = buffer | ||
|
|
||
| self._n_batches[:, time_slice, :] += 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.