Skip to content

Commit

Permalink
Add to varinfo config, re-enable MissingReprojectedDataError, modify …
Browse files Browse the repository at this point in the history
…docstrings
  • Loading branch information
joeyschultz committed Oct 23, 2024
1 parent 78dd9df commit 25cdc10
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
25 changes: 23 additions & 2 deletions swath_projector/earthdata_varinfo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
"VNP10": "VIIRS",
"TEMPO_O3TOT_L2": "TEMPO"
},
"ExcludedScienceVariables": [
{
"Applicability": {
"Mission": "TEMPO",
"ShortNamePath": "TEMPO_O3TOT_L2"
},
"VariablePattern": [
"/support_data/a_priori_layer_o3",
"/support_data/cal_adjustment",
"/support_data/dNdR",
"/support_data/layer_efficiency",
"/support_data/lut_wavelength",
"/support_data/N_value",
"/support_data/N_value_residual",
"/support_data/ozone_sensitivity_ratio",
"/support_data/step_1_N_value_residual",
"/support_data/step_2_N_value_residual",
"/support_data/temp_sensitivity_ratio"
]
}
],
"MetadataOverrides": [
{
"Applicability": {
Expand All @@ -28,15 +49,15 @@
"Applicability": {
"Mission": "TEMPO",
"ShortNamePath": "TEMPO_O3TOT_L2",
"VariablePattern": "/product/.*|/support_data/.*"
"VariablePattern": "^/product/.*|^/support_data/.*"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/geolocation/latitude, /geolocation/longitude"
}
],
"_Description": "TEMPO variables only have simple, single names for coordinates, but need full paths."
"_Description": "TEMPO_O3TOT_L2 variables only contain basenames for coordinates, which are found in sibling hierarchical groups. This rule fully qualifies the paths to these coordinates."
}
]
}
3 changes: 2 additions & 1 deletion swath_projector/nc_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from netCDF4 import Dataset, Variable
from varinfo import VarInfoFromNetCDF4

from swath_projector.exceptions import MissingReprojectedDataError
from swath_projector.utilities import get_variable_file_path, variable_in_dataset

# Values needed for history_json attribute
Expand Down Expand Up @@ -94,7 +95,7 @@ def create_output(

else:
logger.error(f'Cannot find "{dataset_file}".')
# QuickFix (DAS-2216) Ignore missing reprojections
raise MissingReprojectedDataError(variable_name)


def set_output_attributes(
Expand Down
3 changes: 2 additions & 1 deletion swath_projector/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def get_variable_values(
As the variable data are returned as a `numpy.ma.MaskedArray`, the will
return no data in the filled pixels. To ensure that the data are
correctly handled, the fill value is applied to masked pixels using the
`filled` method.
`filled` method. The variable values are transposed if the `along-track`
dimension size is less than the `across-track` dimension size.
"""
# TODO: Remove in favour of apply2D or process_subdimension.
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_nc_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from datetime import datetime
from unittest import TestCase, skip
from unittest import TestCase
from unittest.mock import Mock, patch

from netCDF4 import Dataset
Expand Down Expand Up @@ -186,7 +186,6 @@ def test_same_data_type(self):
output_data_type = out_dataset[test_variable].datatype
self.assertEqual(input_data_type, output_data_type, 'Should be equal')

@skip("Test disabled for DAS-2216 quick fix that ignores missing reprojections")
def test_missing_file_raises_error(self):
"""If a science variable should be included in the output, but there
is no associated output file, an exception should be raised.
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,41 +366,41 @@ def test_make_array_two_dimensional(self):
class TestTransposeIfXdimLessThanYdim(TestCase):

def test_wider_than_tall(self):
# Test case where x dim < y dim and should transpose
"""Test case where x dim < y dim and should transpose."""
input_array = np.ma.array([[1, 2, 3], [4, 5, 6]])
expected_output = np.ma.array([[1, 4], [2, 5], [3, 6]])
result = transpose_if_xdim_less_than_ydim(input_array)
np.testing.assert_array_equal(result, expected_output)
self.assertEqual(result.shape, (3, 2))

def test_taller_than_wide(self):
# Test case where x < y and should not transpose.
"""Test case where x < y and should not transpose."""
input_array = np.ma.array([[1, 2], [3, 4], [5, 6]])
result = transpose_if_xdim_less_than_ydim(input_array)
np.testing.assert_array_equal(result, input_array)
self.assertEqual(result.shape, (3, 2))

def test_square_array(self):
# test where y dim == x dim and should not transpose.
"""Test case where y dim == x dim and should not transpose."""
input_array = np.ma.array([[1, 2], [3, 4]])
result = transpose_if_xdim_less_than_ydim(input_array)
np.testing.assert_array_equal(result, input_array)
self.assertEqual(result.shape, (2, 2))

def test_1d_array(self):
# Test case with a 1D array
"""Test case with a 1D array"""
input_array = np.ma.array([1, 2, 3])
with self.assertRaisesRegex(ValueError, 'variable must be 2 dimensional'):
transpose_if_xdim_less_than_ydim(input_array)

def test_3d_array(self):
# Test case with a 3D array
"""Test case with a 3D array"""
input_array = np.ma.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
with self.assertRaisesRegex(ValueError, 'variable must be 2 dimensional'):
transpose_if_xdim_less_than_ydim(input_array)

def test_masked_array(self):
# Test case with a masked array
"""Test case with a masked array"""
input_array = np.ma.array(
[[1, 2, 3], [4, 5, 6]], mask=[[True, False, False], [False, True, False]]
)
Expand Down

0 comments on commit 25cdc10

Please sign in to comment.