Grid class#
- class laygo2.object.grid.Grid(name, vgrid, hgrid)[source]#
Bases:
object
A base class having conversion operators and the mapping information (element) between two-dimensional physical coordinates and abstract coordinates.
Examplar grid conversions between abstract and physical coordinates are summarized in the following figure.
Public Data Attributes:
name
the name of the grid.
vgrid
hgrid
elements
return elements of subgrids ([_xy[0].elements, _xy[1].elements]).
phy2abs
PhyToAbsGridConverter(master=self)
abs2phy
AbsToPhyGridConverter(master=self)
xy
Two-dimensional _AbsToPhyConverter of a coordinate system.
x
One-dimensional _AbsToPhyGridConverter
y
One-dimensional _AbsToPhyGridConverter of the y-coordinate system.
v
OneDimGrid of the x-coordinate system (=self.x).
h
OneDimGrid of the y-coordinate system (=self.y).
mn
Two-dimensional _PhyToAbsConverter of a coordinate system.
m
One-dimensional _PhyToAbsConverter of the x-coordinate system.
n
One-dimensional _PhyToAbsConverter of
shape
Two-dimensional element length in a coordinate system.
range
width
Width of the region in which the coordinate system is defined.
height
Height of the region in which the coordinate system is defined.
height_vec
Return the height vector [0, h].
width_vec
Return width as a list.
Public Methods:
get_range
()set_range
(value)__init__
(name, vgrid, hgrid)Constructor function of Grid class.
__call__
(other)Call self as a function.
__getitem__
(pos)__eq__
(other)Return the physical grid coordinate that matches to other.
__lt__
(other)Return the index of the grid coordinate that is the largest but less than other.
__le__
(other)Return the index of the grid coordinate that is the largest but less than or equal to other.
__gt__
(other)Return the index of the grid coordinate that is the smallest but greater than other.
__ge__
(other)Return the index of the grid coordinate that is the smallest but greater than or equal to other.
bbox
(obj)Return the abstract grid coordinates corresponding to the 'internal' bounding box of obj.
bottom_left
(obj)Return the abstract grid coordinates corresponding to the bottom-left corner of obj.
bottom_right
(obj)Return the abstract grid coordinates corresponding to the bottom-right corner of obj.
top_left
(obj)Return the abstract grid coordinates corresponding to the top-left corner of obj.
top_right
(obj)Return the abstract grid coordinates corresponding to the top-right corner of obj.
crossing
(*args)Return the abstract grid coordinates corresponding to the crossing point of args.
overlap
(*args[, type])Return the abstract grid coordinates corresponding to the overlap of args.
union
(*args)Return the abstract grid coordinates corresponding to union of args.
center
(obj)Return the abstract grid coordinates corresponding to the center point of obj.
left
(obj)Return the abstract grid coordinates corresponding to the left point of obj.
right
(obj)Return the abstract grid coordinates corresponding to the right point of obj.
top
(obj)Return the abstract grid coordinates corresponding to the top point of obj.
bottom
(obj)Return the abstract grid coordinates corresponding to the bottom point of obj.
copy
()Make a copy of the current Grid object
vflip
([copy])Flip the grid in vertical direction.
hflip
([copy])Flip the grid in horizontal direction.
vstack
(obj[, copy])Stack grid(s) on top of the current grid in vertical direction.
hstack
(obj[, copy])Stack grid(s) on top of the current grid in horizontal direction.
__iter__
()__next__
()__str__
()Return the string representation of the object.
summarize
()Output the information of the respective grid.
- __init__(name, vgrid, hgrid)[source]#
Constructor function of Grid class.
- Parameters:
name (str)
vgrid (laygo2.object.grid.OndDimGrid) – OneDimGrid object of the x-coordinate system
hgrid (laygo2.object.grid.OndDimGrid) – OneDimGrid object of the y-coordinate system
- Return type:
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> print(g2) <laygo2.object.grid.Grid object> name: test, class: Grid, scope: [[0, 0], [100, 100]], elements: [array([ 0, 10, 20, 40, 50]), array([10, 20, 40, 50, 60])
- bbox(obj)[source]#
Return the abstract grid coordinates corresponding to the ‘internal’ bounding box of obj.
See also
_PhyToAbsGridConverter.bbox
- bottom_left(obj)[source]#
Return the abstract grid coordinates corresponding to the bottom-left corner of obj.
See also
_PhyToAbsGridConverter.bottom_left
- bottom_right(obj)[source]#
Return the abstract grid coordinates corresponding to the bottom-right corner of obj.
See also
_PhyToAbsGridConverter.bottom_right
- center(obj)[source]#
Return the abstract grid coordinates corresponding to the center point of obj.
- Parameters:
obj (laygo2.object.physical.PhysicalObject) – The object of which center coordinate is computed.
See also
laygo2.object.grid._PhyToAbsGridConverter.center
- copy()[source]#
Make a copy of the current Grid object
- Returns:
laygo2.object.grid.Grid
- Return type:
the copied Grid object.
See also
- crossing(*args)[source]#
Return the abstract grid coordinates corresponding to the crossing point of args.
See also
laygo2.object.grid._PhyToAbsGridConverter.crossing
- hflip(copy=True)[source]#
Flip the grid in horizontal direction.
- Parameters:
copy (optional, boolean) – If True, make a copy and flip the copied grid (default). If False, flip the current grid object.
- Returns:
laygo2.object.grid.Grid
- Return type:
the flipped Grid object.
See also
- overlap(*args, type='bbox')[source]#
Return the abstract grid coordinates corresponding to the overlap of args.
See also
laygo2.object.grid._PhyToAbsGridConverter.overlap
- summarize()[source]#
Output the information of the respective grid.
- Parameters:
None
- Return type:
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.summarize() <laygo2.object.grid.Grid object> name: test, class: Grid, scope: [[0, 0], [100, 100]], elements: [array([ 0, 10, 20, 40, 50]), array([10, 20, 40, 50, 60])
- top_left(obj)[source]#
Return the abstract grid coordinates corresponding to the top-left corner of obj.
See also
_PhyToAbsGridConverter.top_left
- top_right(obj)[source]#
Return the abstract grid coordinates corresponding to the top-right corner of obj.
See also
_PhyToAbsGridConverter.top_right
- union(*args)[source]#
Return the abstract grid coordinates corresponding to union of args.
See also
laygo2.object.grid._PhyToAbsGridConverter.union
- vflip(copy=True)[source]#
Flip the grid in vertical direction.
- Parameters:
copy (optional, boolean) – If True, make a copy and flip the copied grid (default). If False, flip the current grid object.
- Returns:
laygo2.object.grid.Grid
- Return type:
the flipped Grid object.
See also
- _xy = None#
the list contains the 1d-grid objects for x and y axes.
- Type:
List[OneDimGrid]
- abs2phy = None#
AbsToPhyGridConverter(master=self)
- property h#
OneDimGrid of the y-coordinate system (=self.y).
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.h g1_y
- Type:
- property height#
Height of the region in which the coordinate system is defined.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.height 100
- Type:
numpy.int32
- property height_vec#
Return the height vector [0, h].
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.height_vec [0, 100]
- Type:
- property hgrid#
- property m#
One-dimensional _PhyToAbsConverter of the x-coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.n[40] 2 >>> g2.n(40) 2 >>> g2.n < 40 760 >>> g2.n <= 40 810 >>> g2.n > 40 820 >>> g2.n >= 40 810
- Type:
_PhyToAbsGridConverter
- property mn#
Two-dimensional _PhyToAbsConverter of a coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.mn[40,40] [3, 2] >>> g2.mn([40, 40]) [3, 2] >>> g2.mn < [40,40] [750, 760] >>> g2.mn <= [40,40] [800, 810] >>> g2.mn > [40,40] [810, 820] >>> g2.mn >= [40,40] [800, 810]
- Type:
laygo2._PhyToAbsGridConverter
- property n#
- One-dimensional _PhyToAbsConverter of
the y-coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.n[40] 2 >>> g2.n(40) 2 >>> g2.n < 40 760 >>> g2.n <= 40 810 >>> g2.n > 40 820 >>> g2.n >= 40 810
- Type:
_PhyToAbsGridConverter
- phy2abs = None#
PhyToAbsGridConverter(master=self)
- property range#
- Region in which the coordinate system is defined.
bbox of the respective Grid
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.range [ [0, 0], [100, 100 ]]
- Type:
- property shape#
- Two-dimensional element length in a coordinate system.
length of x-axis elements, length of y-axis elements
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.shape [5, 5]
- Type:
- property v#
OneDimGrid of the x-coordinate system (=self.x).
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.v g1_x
- Type:
- property vgrid#
- property width#
- Width of the region in which the coordinate system is defined.
x scope
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.width 100
- Type:
numpy.int32
- property width_vec#
- Return width as a list.
length of the respective axis and zero
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.width_vec [100, 0]
- Type:
- property x#
- One-dimensional _AbsToPhyGridConverter
of the x-coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.x[10] 200 >>> g2.x < 10 [0] >>> g2.x <= 10 [1] >>> g2.x > 10 [2] >>> g2.x >= 10 [1]
- Type:
_AbsToPhyGridConverter
- property xy#
Two-dimensional _AbsToPhyConverter of a coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.xy[10,10] [200 210] >>> g2.xy([10, 10]) [200 210] >>> g2.xy < [10,10] [0,-1] >>> g2.xy <= [10,10] [1,0] >>> g2.xy > [10,10] [2,1] >>> g2.xy >= [10,10] [1,0]
- Type:
_AbsToPhyGridConverter
- property y#
One-dimensional _AbsToPhyGridConverter of the y-coordinate system.
Example
>>> from laygo2.object.grid import OneDimGrid, Grid >>> g1_x = OneDimGrid(name='xgrid', scope=[0, 100], elements=[0, 10, 20, 40, 50 ]) >>> g1_y = OneDimGrid(name='ygrid', scope=[0, 100], elements=[10, 20, 40, 50, 60 ]) >>> g2 = Grid(name="test", vgrid = g1_x, hgrid = g1_y ) >>> g2.y[10] 210 >>> g2.y < 10 [-1] >>> g2.y <= 10 [0] >>> g2.y > 10 [1] >>> g2.y >= 10 [0]
- Type:
_AbsToPhyGridConverter