-
Notifications
You must be signed in to change notification settings - Fork 4
chore(ty): replace pyright with ty in RBMDS #56
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
|
|
||
| from datetime import datetime | ||
| from pathlib import Path | ||
| from typing import Iterable, overload | ||
| from typing import Iterable, Literal, overload | ||
|
|
||
| from swvo.io.RBMDataSet.custom_enums import ( | ||
| FolderTypeEnum, | ||
|
|
@@ -94,7 +94,7 @@ def load( | |
| folder_type: FolderTypeEnum = FolderTypeEnum.DataServer, | ||
| *, | ||
| verbose: bool = True, | ||
| preferred_extension: str = "pickle", | ||
| preferred_extension: Literal["mat", "pickle"] = "pickle", | ||
| ) -> RBMDataSet | list[RBMDataSet]: | ||
|
Comment on lines
96
to
98
|
||
| """Loads an RBMDataSet or a list of RBMDataSets based on the provided parameters. | ||
|
|
||
|
|
@@ -152,7 +152,7 @@ def load( | |
| return_list.append(cls._instance.data_set_dict[key_tuple]) | ||
| else: | ||
| cls._instance.data_set_dict[key_tuple] = RBMDataSet( | ||
| satellite=sat, | ||
| satellite=sat, # ty:ignore[invalid-argument-type] | ||
| instrument=instrument, | ||
| mfm=mfm, | ||
| start_time=start_time, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,7 +76,7 @@ def bin_and_interpolate_to_model_grid( | |||||||||
| raise (ValueError(msg)) | ||||||||||
|
|
||||||||||
| # 3. Bin in time | ||||||||||
| psd_binned_in_time = _bin_in_time(self.datetime, sim_time, psd_binned_in_space) | ||||||||||
| psd_binned_in_time = _bin_in_time(self.datetime, sim_time, psd_binned_in_space) # ty:ignore[invalid-argument-type] | ||||||||||
| # sanity check | ||||||||||
| if np.min(target_var_init) > np.min(psd_binned_in_time) or np.max(target_var_init) < np.max(psd_binned_in_time): | ||||||||||
| msg = "Found inconsitency in time binning. Aborting..." | ||||||||||
|
|
@@ -87,7 +87,7 @@ def bin_and_interpolate_to_model_grid( | |||||||||
| plot_debug_figures( | ||||||||||
| self, | ||||||||||
| psd_binned_in_time, | ||||||||||
| sim_time, | ||||||||||
| sim_time, # ty:ignore[invalid-argument-type] | ||||||||||
| grid_P, | ||||||||||
| grid_R, | ||||||||||
| grid_mu_V, | ||||||||||
|
|
@@ -99,7 +99,7 @@ def bin_and_interpolate_to_model_grid( | |||||||||
| plot_debug_figures_plasmasphere( | ||||||||||
| self, | ||||||||||
| psd_binned_in_time, | ||||||||||
| sim_time, | ||||||||||
| sim_time, # ty:ignore[invalid-argument-type] | ||||||||||
| grid_P, | ||||||||||
| grid_R, | ||||||||||
| debug_plot_settings, | ||||||||||
|
|
@@ -257,12 +257,12 @@ def _interpolate_in_V_K( | |||||||||
| rs = p.map_async(func, range(psd_in.shape[0])) | ||||||||||
|
|
||||||||||
| # display progress bar if verbose | ||||||||||
| total_elements = rs._number_left | ||||||||||
| total_elements = rs._number_left # ty:ignore[unresolved-attribute] | ||||||||||
| with tqdm(total=total_elements) as t: | ||||||||||
| while True: | ||||||||||
| if rs.ready(): | ||||||||||
| break | ||||||||||
| t.n = total_elements - rs._number_left | ||||||||||
| t.n = total_elements - rs._number_left # ty:ignore[unresolved-attribute] | ||||||||||
| t.refresh() | ||||||||||
| time.sleep(1) | ||||||||||
|
|
||||||||||
|
|
@@ -417,11 +417,11 @@ def plot_debug_figures_plasmasphere( | |||||||||
| ) | ||||||||||
| ax0.set_ylim(1, 6.6) | ||||||||||
| ax0.set_title("Orbit") | ||||||||||
| ax0.set_rlim([0, 6.6]) | ||||||||||
| ax0.set_theta_offset(np.pi) | ||||||||||
| ax0.set_rlim([0, 6.6]) # ty:ignore[unresolved-attribute] | ||||||||||
| ax0.set_theta_offset(np.pi) # ty:ignore[unresolved-attribute] | ||||||||||
|
|
||||||||||
sahiljhawar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| grid_X = grid_R[:, :, 0, 0] * np.cos(grid_P[:, :, 0, 0]) | ||||||||||
| grid_Y = grid_R[:, :, 0, 0] * np.sin(grid_P[:, :, 0, 0]) | ||||||||||
| grid_X = grid_R[:, :, 0, 0] * np.cos(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] # ty:ignore[ignore-comment-unknown-rule, not-subscriptable] | ||||||||||
| grid_Y = grid_R[:, :, 0, 0] * np.sin(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] # ty:ignore[ignore-comment-unknown-rule, not-subscriptable] | ||||||||||
|
Comment on lines
+423
to
+424
|
||||||||||
| grid_X = grid_R[:, :, 0, 0] * np.cos(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] # ty:ignore[ignore-comment-unknown-rule, not-subscriptable] | |
| grid_Y = grid_R[:, :, 0, 0] * np.sin(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] # ty:ignore[ignore-comment-unknown-rule, not-subscriptable] | |
| grid_X = grid_R[:, :, 0, 0] * np.cos(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] | |
| grid_Y = grid_R[:, :, 0, 0] * np.sin(grid_P[:, :, 0, 0]) # ty:ignore[non-subscriptable] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ def create_RBSP_line_data( | |
| target_type = TargetType[target_type] | ||
|
|
||
| if target_type == TargetType.TargetPairs: | ||
| assert len(target_en) == len(target_al), "For TargetType.Pairs, the target vectors must have the same size!" | ||
| assert len(target_en) == len(target_al), "For TargetType.Pairs, the target vectors must have the same size!" # ty:ignore[invalid-argument-type] | ||
|
||
|
|
||
| result_arr = [] | ||
| list_instruments_used = [] | ||
|
|
@@ -115,18 +115,18 @@ def create_RBSP_line_data( | |
| instrument, | ||
| mfm, | ||
| verbose=verbose, | ||
| ) | ||
| ) # ty:ignore[no-matching-overload] | ||
| ) | ||
|
|
||
| # strip of time dimention | ||
| if rbm_data[i].energy_channels.shape[0] == len(rbm_data[i].time): | ||
| rbm_data[i].energy_channels_no_time = np.nanmean(rbm_data[i].energy_channels, axis=0) | ||
| rbm_data[i].energy_channels_no_time = np.nanmean(rbm_data[i].energy_channels, axis=0) # ty:ignore[unresolved-attribute] | ||
| else: | ||
| rbm_data[i].energy_channels_no_time = rbm_data[i].energy_channels | ||
| rbm_data[i].energy_channels_no_time = rbm_data[i].energy_channels # ty:ignore[unresolved-attribute] | ||
| if rbm_data[i].alpha_local.shape[0] == len(rbm_data[i].time): | ||
| rbm_data[i].alpha_local_no_time = np.nanmean(rbm_data[i].alpha_local, axis=0) | ||
| rbm_data[i].alpha_local_no_time = np.nanmean(rbm_data[i].alpha_local, axis=0) # ty:ignore[unresolved-attribute] | ||
| else: | ||
| rbm_data[i].alpha_local_no_time = rbm_data[i].alpha_local | ||
| rbm_data[i].alpha_local_no_time = rbm_data[i].alpha_local # ty:ignore[unresolved-attribute] | ||
sahiljhawar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| for e, target_en_single in enumerate(target_en): | ||
| if verbose: | ||
|
|
@@ -150,19 +150,19 @@ def create_RBSP_line_data( | |
| rbm_data_set_result = deepcopy(rbm_data[i]) | ||
|
|
||
| if target_type == TargetType.TargetPairs: | ||
| rbm_data_set_result.line_data_flux = np.empty((len(rbm_data_set_result.time), len(target_en))) | ||
| rbm_data_set_result.line_data_energy = np.empty((len(target_en),)) | ||
| rbm_data_set_result.line_data_alpha_local = np.empty((len(target_al),)) | ||
| rbm_data_set_result.line_data_flux = np.empty((len(rbm_data_set_result.time), len(target_en))) # ty:ignore[invalid-argument-type, unresolved-attribute] | ||
| rbm_data_set_result.line_data_energy = np.empty((len(target_en),)) # ty:ignore[invalid-argument-type, unresolved-attribute] | ||
| rbm_data_set_result.line_data_alpha_local = np.empty((len(target_al),)) # ty:ignore[invalid-argument-type, unresolved-attribute] | ||
| elif target_type == TargetType.TargetMeshGrid: | ||
| rbm_data_set_result.line_data_flux = np.empty( | ||
| rbm_data_set_result.line_data_flux = np.empty( # ty:ignore[unresolved-attribute] | ||
| ( | ||
| len(rbm_data_set_result.time), | ||
| len(target_en), | ||
| len(target_al), | ||
| len(target_en), # ty:ignore[invalid-argument-type] | ||
| len(target_al), # ty:ignore[invalid-argument-type] | ||
| ) | ||
| ) | ||
| rbm_data_set_result.line_data_energy = np.empty((len(target_en),)) | ||
| rbm_data_set_result.line_data_alpha_local = np.empty((len(target_al),)) | ||
| rbm_data_set_result.line_data_energy = np.empty((len(target_en),)) # ty:ignore[invalid-argument-type, unresolved-attribute] | ||
| rbm_data_set_result.line_data_alpha_local = np.empty((len(target_al),)) # ty:ignore[invalid-argument-type, unresolved-attribute] | ||
|
|
||
| energy_offsets_relative = energy_offsets / target_en_single | ||
| if np.all(np.abs(energy_offsets_relative) > energy_offset_threshold): | ||
|
|
@@ -187,7 +187,7 @@ def create_RBSP_line_data( | |
|
|
||
| if target_type == TargetType.TargetPairs: | ||
| closest_al_idx = np.nanargmin( | ||
| np.abs(rbm_data[min_offset_instrument].alpha_local_no_time - target_al[e]) | ||
| np.abs(rbm_data[min_offset_instrument].alpha_local_no_time - target_al[e]) # ty:ignore[not-subscriptable] | ||
| ) | ||
| rbm_data_set_result.line_data_alpha_local[e] = rbm_data[min_offset_instrument].alpha_local_no_time[ | ||
| closest_al_idx | ||
|
|
@@ -200,7 +200,9 @@ def create_RBSP_line_data( | |
| else: | ||
| rbm_data_set_result.line_data_flux[:, e] = np.squeeze( | ||
| rbm_data[min_offset_instrument].interp_flux( | ||
| target_en_single, target_al[e], TargetType.TargetPairs | ||
| target_en_single, | ||
| target_al[e], | ||
| TargetType.TargetPairs, # ty:ignore[not-subscriptable] | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
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.
loaded_var_arrsis annotated asdict[str, NDArray[np.number]], butjoined_valuemay not always match that type, leading toty:ignore[invalid-assignment]. Rather than suppressing, adjust the dict’s value type (e.g., includeNDArray[np.object_]/NDArray[np.generic]) or refactor to keep numeric vs non-numeric entries separate.