diff --git a/CHANGELOG.md b/CHANGELOG.md index 37602f1..c85e6c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Changed - [[DAS-2216](https://bugs.earthdata.nasa.gov/browse/DAS-2216)] - The Swath Projector has been updated with quick fixes to add support for TEMPO level 2 data. These changes include optional transposing of arrays based on dimension sizes and updates to the configuration file for TEMPO_O3TOT_L2 to correctly locate coordinate variables and exclude science variables with dimensions that do no match those of the coordinate variables. + The Swath Projector has been updated with quick fixes to add support for TEMPO level 2 data. These changes include optional transposing of arrays based on dimension sizes, addition of rows_per_scan parameter for ewa interpolation, and updates to the configuration file for TEMPO_O3TOT_L2 to correctly locate coordinate variables and exclude science variables with dimensions that do no match those of the coordinate variables. ## [v1.1.1] - 2024-09-16 diff --git a/swath_projector/interpolation.py b/swath_projector/interpolation.py index cfa5a63..9fc92e3 100644 --- a/swath_projector/interpolation.py +++ b/swath_projector/interpolation.py @@ -25,6 +25,7 @@ from swath_projector.utilities import ( create_coordinates_key, get_coordinate_variable, + get_rows_per_scan, get_scale_and_offset, get_variable_file_path, get_variable_numeric_fill_value, @@ -268,7 +269,7 @@ def get_ewa_results( ewa_information['target_area'], variable['values'], maximum_weight_mode=maximum_weight_mode, - rows_per_scan=2, # Added in QuickFix DAS-2216 to be fixed in DAS-2220 + rows_per_scan=get_rows_per_scan(variable['values'].shape[0]), ) if variable['fill_value'] is not None: diff --git a/swath_projector/utilities.py b/swath_projector/utilities.py index 888bf55..468a14c 100644 --- a/swath_projector/utilities.py +++ b/swath_projector/utilities.py @@ -246,3 +246,16 @@ def transpose_if_xdim_less_than_ydim( return np.ma.transpose(variable_values).copy() return variable_values + + +def get_rows_per_scan(total_rows: int) -> int: + """ + Finds the smallest divisor of the total number of rows. If no divisor is + found, return the total number of rows. + """ + if total_rows < 2: + return 1 + for row_number in range(2, int(total_rows**0.5) + 1): + if total_rows % row_number == 0: + return row_number + return total_rows diff --git a/tests/unit/test_utilities.py b/tests/unit/test_utilities.py index 0b78611..fe3eae3 100644 --- a/tests/unit/test_utilities.py +++ b/tests/unit/test_utilities.py @@ -10,6 +10,7 @@ construct_absolute_path, create_coordinates_key, get_coordinate_variable, + get_rows_per_scan, get_scale_and_offset, get_variable_file_path, get_variable_numeric_fill_value, @@ -411,3 +412,17 @@ def test_masked_array(self): result = transpose_if_xdim_less_than_ydim(input_array) np.testing.assert_array_equal(result, expected_output) np.testing.assert_array_equal(result.mask, expected_output.mask) + + +class TestGetRowsPerScan(TestCase): + def test_number_less_than_2(self): + self.assertEqual(get_rows_per_scan(1), 1) + + def test_even_composite_number(self): + self.assertEqual(get_rows_per_scan(4), 2) + + def test_odd_composite_number(self): + self.assertEqual(get_rows_per_scan(9), 3) + + def test_prime_number(self): + self.assertEqual(get_rows_per_scan(3), 3)