Skip to content
Snippets Groups Projects
Commit 9a7a98e8 authored by Paolo Veglio's avatar Paolo Veglio
Browse files

added SPI_Cloud_Mask to output

parent a354f5fe
No related branches found
No related tags found
No related merge requests found
......@@ -431,6 +431,7 @@ def main(
integer_cloud_mask[(csc <= 0.95) & (csc > 0.66)] = 1
integer_cloud_mask[csc <= 0.66] = 0
integer_cloud_mask = integer_cloud_mask.astype(np.int8)
spi = utils.cloud_mask_spi(viirs_data)
# logger.debug(f"Memory: {tracemalloc.get_traced_memory()}")
cloud_mask = np.zeros((6, csc.shape[0], csc.shape[1]), dtype=np.byte)
......@@ -448,6 +449,7 @@ def main(
"cloud_mask": {"dims": ("bits", "x", "y"), "data": cloud_mask},
"quality_assurance": {"dims": ("x", "y", "qa"), "data": quality_assurance},
"integer_cloud_mask": {"dims": ("x", "y"), "data": integer_cloud_mask},
"spi": {"dims": ("x1", "y1"), "data": spi.values},
}
old_debug_data = {
......
......@@ -776,16 +776,18 @@ class CloudTests:
sunglint = scene_for_sunglint.find_sunglint(
self.thresholds["Sun_Glint"]["bounds"][3], day_flag
).values
# sunglint = scn.find_scene(self.data, self.thresholds["Sun_Glint"]["bounds"][3])[
# "sunglint"
# ]
idx = np.nonzero((solar_zenith <= 85) & (sunglint == 1))
# idx = np.nonzero((solar_zenith <= 85) & (sunglint == 1))
thr_no_sunglint = np.array([threshold["thr"][i] for i in range(8)])
thr_sunglint = np.array([self.thresholds["Sun_Glint"]["snglnt"][i] for i in range(8)])
temp_conf[sunglint == 0] = conf.conf_test_dble(rad[sunglint == 0], thr_no_sunglint)
temp_conf[idx] = conf.conf_test_dble(rad[idx], thr_sunglint)
temp_conf[sunglint == 1] = conf.conf_test_dble(rad[sunglint == 1], thr_sunglint)
kwargs["confidence"][self.scene_idx] = temp_conf[self.scene_idx]
idx = np.nonzero(
......
......@@ -3,9 +3,19 @@
from typing import Dict
import numpy as np
import xarray as xr
from numpy.lib.stride_tricks import sliding_window_view
def cloud_mask_spi(data: xr.Dataset):
temp_da = xr.DataArray(data.M05.values, dims=("number_of_lines", "number_of_pixels"))
spi = 100 * (
temp_da.coarsen(number_of_lines=2, number_of_pixels=2).std()
/ temp_da.coarsen(number_of_lines=2, number_of_pixels=2).mean()
)
return spi
def local_nxn_mean(arr: np.ndarray, x: int = 3, y: int = 3) -> np.ndarray:
"""Return the mean value of each NxM (default 3) pixel region for a given array."""
local_mean = (
......
......@@ -181,6 +181,17 @@ def save_output(
"valid_max": 3,
},
},
"SPI": {
"dims": ("number_of_lines", "number_of_pixels"),
"data": data.spi.values,
"attrs": {
"units": "none",
"long_name": "VIIRS SPI",
"_FillValue": -999.9,
"valid_min": 0.0,
"valid_max": 100.0,
},
},
}
if debug is True:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment