Skip to content

Commit

Permalink
Merge pull request #49 from pstradio/SMOS_debug
Browse files Browse the repository at this point in the history
Smos debug
  • Loading branch information
pstradio authored Apr 1, 2022
2 parents 2e5522a + 2ee887c commit b8ac123
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/qa4sm_reader/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def get_metric_units(dataset, raise_error=False):
"ERA5_LAND_TEST": "ERA5-Land test",
"CGLS_CSAR_SSM1km_V1_1": "v1_1",
"CGLS_SCATSAR_SWI1km_V1_0": "v1_0",
"Level3_ASC": "Level3 Ascending",
"Level3_DESC": "Level3 Descending",
"SMOSL3_v339_ASC": "version 339 Ascending",
"SMOSL3_v339_DESC": "version 339 Descending",
}

# fallback for dataset val_dc_variable in case they are not in the metadata
Expand Down Expand Up @@ -374,8 +374,8 @@ def get_metric_units(dataset, raise_error=False):
"ERA5_LAND_TEST": "svwl1",
"CGLS_CSAR_SSM1km_V1_1": "soil moisture",
"CGLS_SCATSAR_SWI1km_V1_0": "SWI",
"Level3_ASC": "soil moisture",
"Level3_DESC": "soil moisture"
"SMOSL3_v339_ASC": "soil moisture",
"SMOSL3_v339_DESC": "soil moisture"
}


Expand Down Expand Up @@ -425,7 +425,7 @@ def get_resolution_info(dataset, raise_error=False):
'SMOS_IC': 'km',
'CGLS_CSAR_SSM1km': 'km',
'CGLS_SCATSAR_SWI1km': 'km',
'SMOS_L3': 'deg',
'SMOS_L3': 'km',
}

try:
Expand Down Expand Up @@ -552,7 +552,7 @@ def get_resolution_info(dataset, raise_error=False):
"instrument_depthfrom": ("upper depth", None, "continuous", "[m]"),
"instrument_depthto": ("lower depth", None, "continuous", "[m]"),
# --- generated during the image initialization:
"soil_type": ("soil texture", None, "discrete", None),
"soil_type": ("soil granulometry", None, "discrete", None),
"instrument_depth": ("instrument depth", None, "continuous", "[m]"),
}

Expand Down
6 changes: 3 additions & 3 deletions src/qa4sm_reader/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def _boxplot_definition(
parts = [globals._metric_name[metric]]
parts.append(
globals._metric_description[metric].format(
globals.get_metric_units(self.ref['short_name'])
))
globals.get_metric_units(self.ref['short_name'])
))
label = "{}{}".format(*parts)
# generate plot
figwidth = globals.boxplot_width * (len(df.columns) + 1)
Expand Down Expand Up @@ -561,7 +561,7 @@ def mapplot_var(
out_name: str = None,
out_types: str = 'png',
save_files: bool = False,
compute_dpi:bool = True,
compute_dpi: bool = True,
**style_kwargs,
) -> Union[list, tuple]:
"""
Expand Down
6 changes: 3 additions & 3 deletions src/qa4sm_reader/plotting_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,11 @@ def combine_soils(
# function to calssify
def sort_soil_type(row):
if row["x"] < sc_x and row["y"] < cc_y:
return "Coarse\ngranulometry"
return "Coarse\ngran."
elif cc_y < row["y"] < cf_y:
return "Medium\ngranulometry"
return "Medium\ngran."
else:
return "Fine\ngranulometry"
return "Fine\ngran."

soil_combined = soil_combined.apply(lambda row: sort_soil_type(row), axis=1).to_frame("soil_type")

Expand Down
42 changes: 38 additions & 4 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qa4sm_reader.plotting_methods import geotraj_to_geo2d, _dict2df, bin_continuous, bin_classes, \
bin_discrete, combine_soils, combine_depths, output_dpi
from qa4sm_reader.handlers import Metadata
from qa4sm_reader.globals import dpi_min, dpi_max
from qa4sm_reader.globals import dpi_min, dpi_max, get_resolution_info


@pytest.fixture
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_combine_soils():
}
combined = combine_soils(soil_fractions)
exp = pd.DataFrame(
data=["Coarse\ngranulometry", "Fine\ngranulometry", "Coarse\ngranulometry"],
data=["Coarse\ngran.", "Fine\ngran.", "Coarse\ngran."],
columns=["soil_type"]
)

Expand Down Expand Up @@ -420,9 +420,43 @@ def test_output_dpi():

# test dpi formula
dpi_fraction = np.sqrt(
((1 - (res1 - 1)/35)**2)**2 + (((extent1[1]-extent1[0]) * (extent1[3]-extent1[2]))/(360 * 110))**2
((1 - (res1 - 1) / 35) ** 2) ** 2 + (((extent1[1] - extent1[0]) * (extent1[3] - extent1[2])) / (360 * 110)) ** 2
) / np.sqrt(2)
dpi1_should = dpi_min + (dpi_max-dpi_min) * dpi_fraction
dpi1_should = dpi_min + (dpi_max - dpi_min) * dpi_fraction

assert dpi1_should == dpi1, "Check correctness of dpi formula and/or constants, " \
"e.g. the maximum resolution in km"


test_data = [
('ISMN', None, 'point'),
('C3S', 0.25, 'deg'),
('C3S_combined', 0.25, 'deg'),
('GLDAS', 0.25, 'deg'),
('ASCAT', 12.5, 'km'),
('SMAP', 36, 'km'), # old name, unused
('SMAP_L3', 36, 'km'),
('ERA5', 0.25, 'deg'),
('ERA5_LAND', 0.1, 'deg'),
('ESA_CCI_SM_active', 0.25, 'deg'),
('ESA_CCI_SM_combined', 0.25, 'deg'),
('ESA_CCI_SM_passive', 0.25, 'deg'),
('SMOS', 25, 'km'), # old name, unused
('SMOS_IC', 25, 'km'),
('CGLS_CSAR_SSM1km', 1, 'km'),
('CGLS_SCATSAR_SWI1km', 1, 'km'),
('SMOS_L3', 25, 'km')
]


@pytest.mark.parametrize(
"dataset,dataset_res_should,dataset_units_should", test_data,
)
def test_globals_resolutions(dataset, dataset_res_should, dataset_units_should):
# important to include this in the tests as changes here
# affect the quality of the images and can also break the
# code, e.g. if by mistake 'degree' is specified as 'km'
dataset_res, dataset_units = get_resolution_info(dataset)

assert dataset_res == dataset_res_should
assert dataset_units == dataset_units_should

0 comments on commit b8ac123

Please sign in to comment.