Skip to content

Commit

Permalink
put down-sampled axis finding in try block. Up to 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunius committed Jun 20, 2022
1 parent 0e59fd6 commit fb5f99e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ python -m unittest discover -s tests

## Changelog

### v3.5.0

Minor fix:

* When data resolution is higher than 1.0 degree, put axis-finding using down-sampled AR mask in a `try` block. If it failed, revert back to axis-finding using original resolution.

### v3.4.0

Minor fixes:
Expand Down
63 changes: 36 additions & 27 deletions ipart/AR_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,12 +1340,9 @@ def findARAxis(quslab, qvslab, armask_list, costhetas, sinthetas, reso, param_di
sinii=sinthetas
cosii=costhetas

if ds == 1:
#----------Convert mask to directed graph----------
gii=maskToGraph(maskii,quii,qvii,cosii,sinii,edge_eps)
#--------------Get AR axis from graph--------------
axisarrii,axismaskii=getARAxis(gii,quii,qvii,maskii,None)
else:
ds_path_success = None
if ds > 1:
# try quicker graph path search first
#-------------------down sample-------------------
maskii_ds = maskii[::ds, ::ds]
quii_ds = quii[::ds, ::ds]
Expand All @@ -1354,31 +1351,43 @@ def findARAxis(quslab, qvslab, armask_list, costhetas, sinthetas, reso, param_di
sinii_ds = sinii[::ds, ::ds]

#------------------Find axis from down sampled--------------
gii_ds=maskToGraph(maskii_ds,quii_ds,qvii_ds,cosii_ds,sinii_ds,edge_eps)
axisarrii_ds,axismaskii_ds=getARAxis(gii_ds,quii_ds,qvii_ds,maskii_ds,None)

#------------------Get end points------------------
p1=axisarrii_ds[0]*ds
p2=axisarrii_ds[-1]*ds

#-----------------Edge points to search from-----------------
edge_mask = np.zeros_like(maskii)
# enlarge the search region a bit: ds*3
edge_mask[max(0, p1[0]-ds*3):min(edge_mask.shape[0], p1[0]+ds*3),
max(0, p1[1]-ds*3):min(edge_mask.shape[1], p1[1]+ds*3)] = 1
edge_mask[max(0, p2[0]-ds*3):min(edge_mask.shape[0], p2[0]+ds*3),
max(0, p2[1]-ds*3):min(edge_mask.shape[1], p2[1]+ds*3)] = 1

if HAS_CV:
edge=maskii-cv.erode(maskii, cv.getStructuringElement(cv.MORPH_CROSS, (3,3)))
edge_mask = edge_mask * edge
try:
gii_ds=maskToGraph(maskii_ds,quii_ds,qvii_ds,cosii_ds,sinii_ds,edge_eps)
axisarrii_ds,axismaskii_ds=getARAxis(gii_ds,quii_ds,qvii_ds,maskii_ds,None)
except:
ds_path_success = False
else:
edge_mask = edge_mask * (maskii-morphology.binary_erosion(maskii))
ds_path_success = True

#------------------Get end points------------------
p1=axisarrii_ds[0]*ds
p2=axisarrii_ds[-1]*ds

#-----------------Edge points to search from-----------------
edge_mask = np.zeros_like(maskii)
# enlarge the search region a bit: ds*3
edge_mask[max(0, p1[0]-ds*3):min(edge_mask.shape[0], p1[0]+ds*3),
max(0, p1[1]-ds*3):min(edge_mask.shape[1], p1[1]+ds*3)] = 1
edge_mask[max(0, p2[0]-ds*3):min(edge_mask.shape[0], p2[0]+ds*3),
max(0, p2[1]-ds*3):min(edge_mask.shape[1], p2[1]+ds*3)] = 1

if HAS_CV:
edge=maskii-cv.erode(maskii, cv.getStructuringElement(cv.MORPH_CROSS, (3,3)))
edge_mask = edge_mask * edge
else:
edge_mask = edge_mask * (maskii-morphology.binary_erosion(maskii))

gii=maskToGraph(maskii,quii,qvii,cosii,sinii,edge_eps)
gii=maskToGraph(maskii,quii,qvii,cosii,sinii,edge_eps)

#--------------Get AR axis from graph--------------
axisarrii,axismaskii=getARAxis(gii,quii,qvii,maskii,edge_mask)

# if quicker graph search failed, or do not do downsample:
if ds == 1 or ds_path_success == False:
#----------Convert mask to directed graph----------
gii=maskToGraph(maskii,quii,qvii,cosii,sinii,edge_eps)
#--------------Get AR axis from graph--------------
axisarrii,axismaskii=getARAxis(gii,quii,qvii,maskii,edge_mask)
axisarrii,axismaskii=getARAxis(gii,quii,qvii,maskii,None)

if rollii:
# shift back
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#from distutils.core import setup

setup(name='ipart',
version='3.4.0',
version='3.5.0',
description='IPART is a Python package for the detection and tracking of atmospheric rivers from gridded IVT data using image-processing techniques.',
author='Guangzhi XU',
author_email='xugzhi1987@gmail.com',
Expand Down

0 comments on commit fb5f99e

Please sign in to comment.