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

tropo_pyaps3.get_snwe(): return native int instead of numpy.int64 #1324

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/mintpy/tropo_pyaps3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'MERRA' : [0, 6, 12, 18],
}

INT_DATA_TYPES = (int, np.int16, np.int32, np.int64)
# INT_DATA_TYPES = (int, np.int16, np.int32, np.int64)


###############################################################
Expand Down Expand Up @@ -292,25 +292,25 @@ def get_snwe(meta, geom_file=None, min_buffer=2, step=10):
# utils sub-functions
def ceil2multiple(x, step=10):
"""Given a number x, find the smallest number in multiple of step >= x."""
assert isinstance(x, INT_DATA_TYPES), f'input number is not int: {type(x)}'
# assert isinstance(x, INT_DATA_TYPES), f'input number is not int: {type(x)}'
if x % step == 0:
return x
else:
return x + (step - x % step)

def floor2multiple(x, step=10):
"""Given a number x, find the largest number in multiple of step <= x."""
assert isinstance(x, INT_DATA_TYPES), f'input number is not int: {type(x)}'
# assert isinstance(x, INT_DATA_TYPES), f'input number is not int: {type(x)}'
return x - x % step

# get bounding box
lat0, lat1, lon0, lon1 = get_bounding_box(meta, geom_file=geom_file)

# lat/lon0/1 --> SNWE
S = np.floor(min(lat0, lat1) - min_buffer).astype(int)
N = np.ceil( max(lat0, lat1) + min_buffer).astype(int)
W = np.floor(min(lon0, lon1) - min_buffer).astype(int)
E = np.ceil( max(lon0, lon1) + min_buffer).astype(int)
S = np.floor(min(lat0, lat1) - min_buffer)
N = np.ceil( max(lat0, lat1) + min_buffer)
W = np.floor(min(lon0, lon1) - min_buffer)
E = np.ceil( max(lon0, lon1) + min_buffer)

# SNWE in multiple of 10
if step > 1:
Expand All @@ -319,7 +319,8 @@ def floor2multiple(x, step=10):
N = ceil2multiple(N, step=step)
E = ceil2multiple(E, step=step)

return (S, N, W, E)
# return native int format, as cdsapi-0.7.3 does not support numpy.int64
return (int(S), int(N), int(W), int(E))


def get_bounding_box(meta, geom_file=None):
Expand Down