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
Prev Previous commit
Next Next commit
add flag for surface interpolation bias correction
  • Loading branch information
grantbuster committed Jan 16, 2023
commit ec45cc787e4a3aea3516608ae0cfa33c4a25fd93
19 changes: 15 additions & 4 deletions sup3r/models/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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):
pres_div=None, pres_exp=None, fix_bias=True):
"""
Parameters
----------
Expand Down Expand Up @@ -85,6 +85,10 @@ def __init__(self, features, s_enhance, noise_adders=None,
pres_div : None | float
Exponential factor in the pressure scale height equation. Defaults
to the cls.PRES_EXP attribute.
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
low-resolution deviation from the input data
"""

self._features = features
Expand All @@ -95,6 +99,7 @@ def __init__(self, features, s_enhance, noise_adders=None,
self._w_delta_topo = w_delta_topo or self.W_DELTA_TOPO
self._pres_div = pres_div or self.PRES_DIV
self._pres_exp = pres_exp or self.PRES_EXP
self._fix_bias = fix_bias

if isinstance(self._noise_adders, (int, float)):
self._noise_adders = [self._noise_adders] * len(self._features)
Expand Down Expand Up @@ -317,7 +322,10 @@ def downscale_temp(self, single_lr_temp, topo_lr, topo_hr):
lower_data = single_lr_temp.copy() + topo_lr * self._temp_lapse
hi_res_temp = self.downscale_arr(lower_data, self._s_enhance)
hi_res_temp -= topo_hr * self._temp_lapse
hi_res_temp = self._fix_downscaled_bias(single_lr_temp, hi_res_temp)

if self._fix_bias:
hi_res_temp = self._fix_downscaled_bias(single_lr_temp,
hi_res_temp)

return hi_res_temp

Expand Down Expand Up @@ -379,7 +387,8 @@ def downscale_rh(self, single_lr_rh, single_lr_temp, single_hr_temp,
+ self._w_delta_temp * delta_temp
+ self._w_delta_topo * delta_topo)

hi_res_rh = self._fix_downscaled_bias(single_lr_rh, hi_res_rh)
if self._fix_bias:
hi_res_rh = self._fix_downscaled_bias(single_lr_rh, hi_res_rh)

return hi_res_rh

Expand Down Expand Up @@ -437,7 +446,9 @@ def downscale_pres(self, single_lr_pres, topo_lr, topo_hr):
const = 101325 * (1 - (1 - topo_hr / self._pres_div)**self._pres_exp)
hi_res_pres -= const

hi_res_pres = self._fix_downscaled_bias(single_lr_pres, hi_res_pres)
if self._fix_bias:
hi_res_pres = self._fix_downscaled_bias(single_lr_pres,
hi_res_pres)

if np.min(hi_res_pres) < 0.0:
msg = ('Spatial interpolation of surface pressure '
Expand Down