def as_region_filter(shape_list, origin=<NUM_LIT:1>):
filter_list = []<EOL>for shape in shape_list:<EOL><INDENT>if shape.name == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>if shape.name == "<STR_LIT>":<EOL><INDENT>xy = np.array(shape.coord_list) - origin<EOL>f = region_filter.Polygon(xy[::<NUM_LIT:2>], xy[<NUM_LIT:1>::<NUM_LIT:2>])<EOL><DEDENT>elif shape.name == "<STR_LIT>" or shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, w, h, rot = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f = region_filter.Rotated(region_filter.Box(xc, yc, w, h),<EOL>rot, xc, yc)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>angle = shape.coord_list[-<NUM_LIT:1>]<EOL>maj_list, min_list = shape.coord_list[<NUM_LIT:2>:-<NUM_LIT:1>:<NUM_LIT:2>], shape.coord_list[<NUM_LIT:3>:-<NUM_LIT:1>:<NUM_LIT:2>]<EOL>if len(maj_list) > <NUM_LIT:1>:<EOL><INDENT>w1, h1 = max(maj_list), max(min_list)<EOL>w2, h2 = min(maj_list), min(min_list)<EOL>f1 = region_filter.Ellipse(xc, yc, w1, h1)& ~region_filter.Ellipse(xc, yc, w2, h2)<EOL>f = region_filter.Rotated(f1, angle, xc, yc)<EOL><DEDENT>else:<EOL><INDENT>w, h = maj_list[<NUM_LIT:0>], min_list[<NUM_LIT:0>]<EOL>f = region_filter.Rotated(region_filter.Ellipse(xc, yc, w, h),<EOL>angle, xc, yc)<EOL><DEDENT><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc = shape.coord_list[:<NUM_LIT:2>]<EOL>xc, yc = xc - origin, yc - origin<EOL>r_list = shape.coord_list[<NUM_LIT:2>:]<EOL>r1 = max(r_list)<EOL>r2 = min(r_list)<EOL>f = region_filter.Circle(xc, yc, r1) & ~region_filter.Circle(xc, yc, r2)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, r = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f = region_filter.Circle(xc, yc, r)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, a1, a2, an, r1, r2, rn = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f1 = region_filter.Circle(xc, yc, r2) & ~region_filter.Circle(xc, yc, r1)<EOL>f = f1 & region_filter.AngleRange(xc, yc, a1, a2)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, r1, r2, a1, a2 = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f1 = region_filter.Circle(xc, yc, r2) & ~region_filter.Circle(xc, yc, r1)<EOL>f = f1 & region_filter.AngleRange(xc, yc, a1, a2)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f1 = region_filter.Ellipse(xc, yc, r21, r22) & ~region_filter.Ellipse(xc, yc, r11, r12)<EOL>f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2)<EOL>f = region_filter.Rotated(f2, angle, xc, yc)<EOL><DEDENT>elif shape.name == "<STR_LIT>":<EOL><INDENT>xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list<EOL>xc, yc = xc - origin, yc - origin<EOL>f1 = region_filter.Box(xc, yc, r21, r22) & ~region_filter.Box(xc, yc, r11, r12)<EOL>f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2)<EOL>f = region_filter.Rotated(f2, angle, xc, yc)<EOL><DEDENT>else:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>".format(shape.name))<EOL>continue<EOL><DEDENT>if shape.exclude:<EOL><INDENT>filter_list = [region_filter.RegionOrList(*filter_list) & ~f]<EOL><DEDENT>else:<EOL><INDENT>filter_list.append(f)<EOL><DEDENT><DEDENT>return region_filter.RegionOrList(*filter_list)<EOL>
Often, the regions files implicitly assume the lower-left corner
of the image as a coordinate (1,1). However, the python convetion
is that the array index starts from 0. By default (origin = 1),
coordinates of the returned mpl artists have coordinate shifted by
(1, 1). If you do not want this shift, use origin=0.