Skip to content

Commit

Permalink
make w2w compatible with numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jkittner committed Jul 1, 2024
1 parent 84f7d80 commit 4809cc6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions w2w/w2w.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def _get_lcz_arr(src_data: xr.DataArray, info: Info) -> NDArray[np.int_]:

# Get mask of selected built LCZs
lcz_urb_mask = xr.DataArray(
np.in1d(src_data, info.BUILT_LCZ).reshape(src_data.shape),
np.isin(src_data, info.BUILT_LCZ).reshape(src_data.shape),
dims=src_data.dims,
coords=src_data.coords,
)
Expand Down Expand Up @@ -846,7 +846,7 @@ def _hgt_resampler(

def _get_truncated_normal_sample(
lcz_i: int, ucp_table: pd.DataFrame, SAMPLE_SIZE: int = 100000
) -> NDArray[np.float_]:
) -> NDArray[np.floating[Any]]:
'''Helper function to return bounded normal distribution sample'''

# Create instance of a truncated normal distribution
Expand All @@ -867,7 +867,7 @@ def _get_truncated_normal_sample(

def _check_hi_values(
lcz_i: int,
hi_sample: NDArray[np.float_],
hi_sample: NDArray[np.floating[Any]],
ucp_table: pd.DataFrame,
ERROR_MARGIN: float,
) -> None:
Expand Down Expand Up @@ -977,7 +977,7 @@ def _hi_resampler(
RESAMPLE_TYPE: str,
ucp_table: pd.DataFrame,
HI_THRES_MIN: int = 5,
) -> Tuple[NDArray[np.float_], float]:
) -> Tuple[NDArray[np.floating[Any]], float]:
'''Helper function to resample ucp HI_URB2D_URB2D data to WRF grid'''

# Read gridded LCZ data
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def _lcz_resampler(
info: Info,
frc_urb2d: xr.DataArray,
LCZ_NAT_MASK: bool,
) -> Tuple[NDArray[np.bool_], NDArray[np.float_]]:
) -> Tuple[NDArray[np.bool_], NDArray[np.floating[Any]]]:
'''Helper function to resample lcz classes to WRF grid using majority'''

# Read gridded LCZ data
Expand Down Expand Up @@ -1098,7 +1098,7 @@ def _adjust_greenfrac_landusef(
# GREENFRAC is set as average / month from GREENFRAC
# of original urban pixels
wrf_urb = xr.DataArray(
np.in1d(dst_data_orig['LU_INDEX'][0, :, :].values, [urban_cat]).reshape(
np.isin(dst_data_orig['LU_INDEX'][0, :, :].values, [urban_cat]).reshape(
dst_data_orig['LU_INDEX'][0, :, :].shape
),
dims=dst_data_orig['LU_INDEX'][0, :, :].dims,
Expand Down Expand Up @@ -1579,7 +1579,7 @@ def checks_and_cleaning(info: Info, ucp_table: pd.DataFrame, nbui_max: float) ->
'LF_URB2D': {'index': 96, 'range': [0, 5]},
}

def _check_range(darr: NDArray[np.float_], exp_range: List[int]) -> int:
def _check_range(darr: NDArray[np.floating[Any]], exp_range: List[int]) -> int:
total_len = len(darr)
sel_len = ((darr >= exp_range[0]) & (darr <= exp_range[1])).sum(axis=0)

Expand Down

0 comments on commit 4809cc6

Please sign in to comment.