Update AGBD.py
Browse files
AGBD.py
CHANGED
|
@@ -221,7 +221,7 @@ def denormalize_bands(bands_data, norm_values, order, norm_strat='pct'):
|
|
| 221 |
|
| 222 |
return bands_data
|
| 223 |
|
| 224 |
-
|
| 225 |
def decode_lc(encoded_lc, mode='cos'):
|
| 226 |
# Encode the LC classes with sin/cosine values and scale the data to [0,1]
|
| 227 |
if mode == 'cos':
|
|
@@ -231,6 +231,26 @@ def decode_lc(encoded_lc, mode='cos'):
|
|
| 231 |
else:
|
| 232 |
raise ValueError(f'Mode `{mode}` is not valid.')
|
| 233 |
return lc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
class NewDataset(datasets.GeneratorBasedBuilder):
|
| 236 |
def __init__(self, *args, additional_features=[], normalize_data=True, patch_size=15, **kwargs):
|
|
@@ -294,8 +314,10 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 294 |
patch[12:14] = denormalize_bands(patch[12:14], norm_values['ALOS_bands'], ['HH', 'HV'])
|
| 295 |
patch[14] = denormalize_data(patch[14], norm_values['CH']['ch'])
|
| 296 |
patch[15] = denormalize_data(patch[15], norm_values['CH']['std'])
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
| 299 |
patch[18] = patch[18] * 100
|
| 300 |
patch[19] = denormalize_data(patch[19], norm_values['DEM'])
|
| 301 |
|
|
|
|
| 221 |
|
| 222 |
return bands_data
|
| 223 |
|
| 224 |
+
"""
|
| 225 |
def decode_lc(encoded_lc, mode='cos'):
|
| 226 |
# Encode the LC classes with sin/cosine values and scale the data to [0,1]
|
| 227 |
if mode == 'cos':
|
|
|
|
| 231 |
else:
|
| 232 |
raise ValueError(f'Mode `{mode}` is not valid.')
|
| 233 |
return lc
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
def recover_lc_map(lc_cos, lc_sin):
|
| 237 |
+
|
| 238 |
+
# Convert lc_cos and lc_sin back to the range of the original sin and cos values
|
| 239 |
+
lc_cos = 2 * lc_cos - 1
|
| 240 |
+
lc_sin = 2 * lc_sin - 1
|
| 241 |
+
|
| 242 |
+
# Calculate the angles using arccos and arcsin
|
| 243 |
+
theta_cos = np.arccos(lc_cos)
|
| 244 |
+
sin_theta_cos = np.sin(theta_cos)
|
| 245 |
+
check = np.isclose(sin_theta_cos, lc_sin, atol = 1e-8)
|
| 246 |
+
theta = np.where(check, theta_cos, 2 * np.pi - theta_cos)
|
| 247 |
+
|
| 248 |
+
# Convert the angle theta back to lc_map
|
| 249 |
+
lc_map = np.round((theta / (2 * np.pi)) * 100)
|
| 250 |
+
lc_map = np.where(lc_map % 10 != 0, lc_map + 100, lc_map)
|
| 251 |
+
|
| 252 |
+
return lc_map
|
| 253 |
+
|
| 254 |
|
| 255 |
class NewDataset(datasets.GeneratorBasedBuilder):
|
| 256 |
def __init__(self, *args, additional_features=[], normalize_data=True, patch_size=15, **kwargs):
|
|
|
|
| 314 |
patch[12:14] = denormalize_bands(patch[12:14], norm_values['ALOS_bands'], ['HH', 'HV'])
|
| 315 |
patch[14] = denormalize_data(patch[14], norm_values['CH']['ch'])
|
| 316 |
patch[15] = denormalize_data(patch[15], norm_values['CH']['std'])
|
| 317 |
+
lc_cos, lc_sin = patch[16], patch[17]
|
| 318 |
+
lc = recover_lc_map(lc_cos, lc_sin)
|
| 319 |
+
patch[16] = lc
|
| 320 |
+
patch[17] = lc
|
| 321 |
patch[18] = patch[18] * 100
|
| 322 |
patch[19] = denormalize_data(patch[19], norm_values['DEM'])
|
| 323 |
|