Skip to content

Commit

Permalink
Add get_rows_per_scan utility and associated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyschultz committed Oct 28, 2024
1 parent e5d4be1 commit bde29b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion swath_projector/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions swath_projector/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/unit/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit bde29b6

Please sign in to comment.