NCAR / watershed_tools

Methods for creating watershed discretizations for use in hydrological modeling or analysis. Examples use the SUMMA modeling Framework.
GNU General Public License v3.0
11 stars 5 forks source link

hru_mask overwritten in geospatial_analysis.py #12

Open DaveCasson opened 1 year ago

DaveCasson commented 1 year ago

To be resolved with later pull request

In geospatial_analysis.py, the starting with line 601.

Suggest replacing hru_mask with hru_mask_temp Otherwise the code: hru_int_ma = np.ma.masked_array(hru_int,hru_mask==0) will use a hru_mask that only considers the mask from the last loop.

    # concatenate element-wise two arrays to generate HRU
    if iraster == 0:
        hru_str_fmt = raster_str_fmt
        hru_mask    = (raster_mask!=0)
    else:
        hru_str_fmt = np.char.add(hru_str_fmt, raster_str_fmt)
        hru_mask = (hru_mask & raster_mask)

# assign the unique integer to unique HRU (HRU_str_fmt)
# note: the defined numpy array dtype needs to be consistent with the available rasterio dytpes (e.g., int32,float32,float64).
# note: rasterio dytpes doesn't have int64.
hru_int = np.zeros(np.shape(hru_str_fmt), dtype=np.int32)
unique_hrus_str = np.unique(hru_str_fmt[hru_mask!=0])
for ihru, hru in enumerate(unique_hrus_str):
    hru_mask_temp = hru_str_fmt == hru
    hru_int[hru_mask_temp] = int(ihru)+1
hru_int_ma = np.ma.masked_array(hru_int,hru_mask==0)