Skip to content
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

Gb/trh loss #142

Merged
merged 12 commits into from
Jan 20, 2023
Merged
Prev Previous commit
Next Next commit
updated default surface spatial model to use lanczos downscaling. mor…
…e random error but less systematic error
  • Loading branch information
grantbuster committed Jan 19, 2023
commit ed9603838e8888c50754f7b7689a949115318dc7
14 changes: 8 additions & 6 deletions sup3r/models/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SurfaceSpatialMetModel(AbstractInterface):

def __init__(self, features, s_enhance, noise_adders=None,
temp_lapse=None, w_delta_temp=None, w_delta_topo=None,
pres_div=None, pres_exp=None, interp_method='BILINEAR',
pres_div=None, pres_exp=None, interp_method='LANCZOS',
fix_bias=True):
"""
Parameters
Expand Down Expand Up @@ -92,6 +92,8 @@ def __init__(self, features, s_enhance, noise_adders=None,
interp_method : str
Name of the interpolation method to use from PIL.Image.Resampling
(NEAREST, BILINEAR, BICUBIC, LANCZOS)
LANCZOS is default and has been tested to work best for
SurfaceSpatialMetModel.
fix_bias : bool
Some local bias can be introduced by the bilinear interp + lapse
rate, this flag will attempt to correct that bias by using the
Expand Down Expand Up @@ -241,7 +243,7 @@ def _get_temp_rh_ind(self, idf_rh):
return idf_temp

def _fix_downscaled_bias(self, single_lr, single_hr,
method=Image.Resampling.BILINEAR):
method=Image.Resampling.LANCZOS):
"""Fix any bias introduced by the spatial downscaling with lapse rate.

Parameters
Expand All @@ -252,7 +254,7 @@ def _fix_downscaled_bias(self, single_lr, single_hr,
single_hr : np.ndarray
Single timestep downscaled raster data with shape
(lat, lon) matching the high-resolution input data.
method : Image.Resampling.BILINEAR
method : Image.Resampling.LANCZOS
An Image.Resampling method (NEAREST, BILINEAR, BICUBIC, LANCZOS).
NEAREST enforces zero bias but makes slightly more spatial seams.

Expand All @@ -272,7 +274,7 @@ def _fix_downscaled_bias(self, single_lr, single_hr,
return single_hr

@staticmethod
def downscale_arr(arr, s_enhance, method=Image.Resampling.BILINEAR):
def downscale_arr(arr, s_enhance, method=Image.Resampling.LANCZOS):
"""Downscale a 2D array of data Image.resize() method

Parameters
Expand All @@ -282,9 +284,9 @@ def downscale_arr(arr, s_enhance, method=Image.Resampling.BILINEAR):
(lat, lon)
s_enhance : int
Integer factor by which the spatial axes are to be enhanced.
method : Image.Resampling.BILINEAR
method : Image.Resampling.LANCZOS
An Image.Resampling method (NEAREST, BILINEAR, BICUBIC, LANCZOS).
BILINEAR is default and has been tested to work best for
LANCZOS is default and has been tested to work best for
SurfaceSpatialMetModel.
"""
im = Image.fromarray(arr)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_surface_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_surface_model(s_enhance=5):
diff = true_hi_res - hi_res

# high res temperature should have very low bias and MAE < 1C
assert np.abs(diff[..., 0].mean()) < 1e-6
assert np.abs(diff[..., 0].mean()) < 1e-4
assert np.abs(diff[..., 0]).mean() < 5

# high res relative humidity should have very low bias and MAE < 3%
assert np.abs(diff[..., 1].mean()) < 1e-6
assert np.abs(diff[..., 1].mean()) < 1e-4
assert np.abs(diff[..., 1]).mean() < 2

# high res pressure should have very low bias and MAE < 200 Pa
Expand Down