Skip to content

Commit e153ebf

Browse files
committed
Rename type to cstype
1 parent a3185e8 commit e153ebf

2 files changed

Lines changed: 53 additions & 51 deletions

File tree

pygmt/params/position.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,44 @@ class Position(BaseParam):
4040
4141
**Reference Point**
4242
43-
The *reference point* can be specified in five different ways using the ``type`` and
44-
``refpoint`` attributes:
43+
The *reference point* can be specified in five different ways using the ``cstype``
44+
and ``refpoint`` attributes:
4545
46-
``type="mapcoords"`` Map Coordinates
46+
``cstype="mapcoords"`` Map Coordinates
4747
Use data/geographic coordinates. Specify ``refpoint`` as
4848
(*longitude*, *latitude*). Useful when tying the embellishment to a specific
4949
geographic location.
5050
51-
**Example:** ``refpoint=(135, 20), type="mapcoords"``
51+
**Example:** ``refpoint=(135, 20), cstype="mapcoords"``
5252
53-
``type="plotcoords"`` Plot Coordinates
53+
``cstype="plotcoords"`` Plot Coordinates
5454
Use plot coordinates as distances from the lower-left plot origin. Specify
5555
``refpoint`` as (*x*, *y*) with units (e.g., inches, centimeters, points).
5656
Useful for precise layout control.
5757
58-
**Example:** ``refpoint=("2c", "2.5c"), type="plotcoords"``
58+
**Example:** ``refpoint=("2c", "2.5c"), cstype="plotcoords"``
5959
60-
``type="boxcoords"`` Normalized Coordinates
60+
``cstype="boxcoords"`` Normalized Coordinates
6161
Use normalized coordinates where (0, 0) is the lower-left corner and (1, 1) is
6262
the upper-right corner of the bounding box of the current plot. Specify
6363
``refpoint`` as (*nx*, *ny*). Useful for positioning relative to plot dimensions
6464
without units.
6565
66-
**Example:** ``refpoint=(0.2, 0.1), type="boxcoords"``
66+
**Example:** ``refpoint=(0.2, 0.1), cstype="boxcoords"``
6767
68-
``type="inside"`` Inside Plot
68+
``cstype="inside"`` Inside Plot
6969
Select one of the nine :doc:`justification codes </techref/justification_codes>`
7070
as the *reference point*. The *anchor point* defaults to be the same as the
7171
*reference point*, so the embellishment is placed inside the plot.
7272
73-
**Example:** ``refpoint="TL", type="inside"``
73+
**Example:** ``refpoint="TL", cstype="inside"``
7474
75-
``type="outside"`` Outside Plot
76-
Similar to ``type="inside"``, but the *anchor point* defaults to the mirror
75+
``cstype="outside"`` Outside Plot
76+
Similar to ``cstype="inside"``, but the *anchor point* defaults to the mirror
7777
opposite of the *reference point*. Useful for placing embellishments outside
7878
the plot boundaries (e.g., color bars).
7979
80-
**Example:** ``refpoint="TL", type="outside"``
80+
**Example:** ``refpoint="TL", cstype="outside"``
8181
8282
**Anchor Point**
8383
@@ -88,9 +88,9 @@ class Position(BaseParam):
8888
Set ``anchor`` explicitly to override these defaults. If not set, the default
8989
*anchor* behaviors are:
9090
91-
- ``type="inside"``: Same as the *reference point* justification code
92-
- ``type="outside"``: Mirror opposite of the *reference point* justification code
93-
- Other types: ``"MC"`` (middle center) for map rose and scale, ``"BL"``
91+
- ``cstype="inside"``: Same as the *reference point* justification code
92+
- ``cstype="outside"``: Mirror opposite of the *reference point* justification code
93+
- Other cstypes: ``"MC"`` (middle center) for map rose and scale, ``"BL"``
9494
(bottom-left) for other embellishments
9595
9696
**Offset**
@@ -110,7 +110,9 @@ class Position(BaseParam):
110110
>>> fig = pygmt.Figure()
111111
>>> fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
112112
>>> fig.logo(
113-
... position=Position((3, 3), type="mapcoords", anchor="ML", offset=(0.2, 0.2)),
113+
... position=Position(
114+
... (3, 3), cstype="mapcoords", anchor="ML", offset=(0.2, 0.2)
115+
... ),
114116
... box=True,
115117
... )
116118
>>> fig.show()
@@ -119,20 +121,20 @@ class Position(BaseParam):
119121
120122
>>> fig = pygmt.Figure()
121123
>>> fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
122-
>>> fig.logo(position=Position("TL", type="inside", offset="0.2c"), box=True)
124+
>>> fig.logo(position=Position("TL", cstype="inside", offset="0.2c"), box=True)
123125
>>> fig.show()
124126
"""
125127

126-
#: Location of the reference point on the plot. The format depends on ``type``:
128+
#: Location of the reference point on the plot. The format depends on ``cstype``:
127129
#:
128-
#: - ``type="mapcoords"``: (*longitude*, *latitude*)
129-
#: - ``type="plotcoords"``: (*x*, *y*) with plot units
130-
#: - ``type="boxcoords"``: (*nx*, *ny*)
131-
#: - ``type="inside"`` or ``"outside"``:
130+
#: - ``cstype="mapcoords"``: (*longitude*, *latitude*)
131+
#: - ``cstype="plotcoords"``: (*x*, *y*) with plot units
132+
#: - ``cstype="boxcoords"``: (*nx*, *ny*)
133+
#: - ``cstype="inside"`` or ``"outside"``:
132134
#: :doc:`2-character justification codes </techref/justification_codes>`
133135
refpoint: Sequence[float | str] | AnchorCode
134136

135-
#: Type of the reference point. Valid values are:
137+
#: cstype of the reference point. Valid values are:
136138
#:
137139
#: - ``"mapcoords"``: Map/Data coordinates
138140
#: - ``"plotcoords"``: Plot coordinates
@@ -141,13 +143,13 @@ class Position(BaseParam):
141143
#:
142144
#: If not specified, defaults to ``"inside"`` if ``refpoint`` is a justification
143145
#: code; otherwise defaults to ``"plotcoords"``.
144-
type: (
146+
cstype: (
145147
Literal["mapcoords", "inside", "outside", "boxcoords", "plotcoords"] | None
146148
) = None
147149

148150
#: Anchor point on the embellishment using a
149151
#: :doc:`2-character justification code </techref/justification_codes>`.
150-
#: If ``None``, defaults are applied based on ``type`` (see above).
152+
#: If ``None``, defaults are applied based on ``cstype`` (see above).
151153
anchor: AnchorCode | None = None
152154

153155
#: Offset for the anchor point as a single value or (*offset_x*, *offset_y*).
@@ -162,12 +164,12 @@ def _validate(self):
162164
f"{v}{h}" for v in "TMB" for h in "LCR"
163165
}
164166

165-
# Default to "inside" if type is not specified and location is an anchor code.
166-
if self.type is None:
167-
self.type = "inside" if isinstance(self.refpoint, str) else "plotcoords"
167+
# Default to "inside" if cstype is not specified and location is an anchor code.
168+
if self.cstype is None:
169+
self.cstype = "inside" if isinstance(self.refpoint, str) else "plotcoords"
168170

169-
# Validate the location based on type.
170-
match self.type:
171+
# Validate the location based on cstype.
172+
match self.cstype:
171173
case "mapcoords" | "plotcoords" | "boxcoords":
172174
if not is_nonstr_iter(self.refpoint) or len(self.refpoint) != 2:
173175
raise GMTValueError(
@@ -194,8 +196,8 @@ def _validate(self):
194196
def _aliases(self):
195197
return [
196198
Alias(
197-
self.type,
198-
name="type",
199+
self.cstype,
200+
name="cstype",
199201
mapping={
200202
"mapcoords": "g",
201203
"boxcoords": "n",

pygmt/tests/test_params_position.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
from pygmt.params import Position
88

99

10-
def test_params_position_types():
10+
def test_params_position_cstypes():
1111
"""
12-
Test the Position class with different types of coordinate systems.
12+
Test the Position class with different cstypes of coordinate systems.
1313
"""
14-
# Default type is "plotcoords" for (x,y) and "inside" for anchor codes.
14+
# Default cstype is "plotcoords" for (x,y) and "inside" for anchor codes.
1515
assert str(Position((1, 2))) == "x1/2"
1616
assert str(Position("TL")) == "jTL"
1717

18-
assert str(Position((10, 20), type="mapcoords")) == "g10/20"
19-
assert str(Position((0.1, 0.2), type="boxcoords")) == "n0.1/0.2"
20-
assert str(Position(("5c", "3c"), type="plotcoords")) == "x5c/3c"
21-
assert str(Position("MR", type="inside")) == "jMR"
22-
assert str(Position("BR", type="outside")) == "JBR"
18+
assert str(Position((10, 20), cstype="mapcoords")) == "g10/20"
19+
assert str(Position((0.1, 0.2), cstype="boxcoords")) == "n0.1/0.2"
20+
assert str(Position(("5c", "3c"), cstype="plotcoords")) == "x5c/3c"
21+
assert str(Position("MR", cstype="inside")) == "jMR"
22+
assert str(Position("BR", cstype="outside")) == "JBR"
2323

2424

2525
def test_params_position_anchor_offset():
2626
"""
2727
Test the Position class with anchor and offset parameters.
2828
"""
29-
assert str(Position((10, 20), type="mapcoords", anchor="TL")) == "g10/20+jTL"
30-
assert str(Position((10, 20), type="mapcoords", offset=(1, 2))) == "g10/20+o1/2"
31-
pos = Position("TL", type="inside", anchor="MC", offset=("1c", "2c"))
29+
assert str(Position((10, 20), cstype="mapcoords", anchor="TL")) == "g10/20+jTL"
30+
assert str(Position((10, 20), cstype="mapcoords", offset=(1, 2))) == "g10/20+o1/2"
31+
pos = Position("TL", cstype="inside", anchor="MC", offset=("1c", "2c"))
3232
assert str(pos) == "jTL+jMC+o1c/2c"
3333
assert str(Position("TL", anchor="BR", offset=0.5)) == "jTL+jBR+o0.5"
3434

@@ -38,22 +38,22 @@ def test_params_position_invalid_location():
3838
Test that invalid location inputs raise GMTValueError.
3939
"""
4040
with pytest.raises(GMTValueError):
41-
Position("invalid", type="mapcoords")
41+
Position("invalid", cstype="mapcoords")
4242
with pytest.raises(GMTValueError):
43-
Position((1, 2, 3), type="mapcoords")
43+
Position((1, 2, 3), cstype="mapcoords")
4444
with pytest.raises(GMTValueError):
45-
Position(5, type="plotcoords")
45+
Position(5, cstype="plotcoords")
4646
with pytest.raises(GMTValueError):
47-
Position((0.5,), type="boxcoords")
47+
Position((0.5,), cstype="boxcoords")
4848
with pytest.raises(GMTValueError):
49-
Position((10, 20), type="inside")
49+
Position((10, 20), cstype="inside")
5050
with pytest.raises(GMTValueError):
51-
Position("TT", type="outside")
51+
Position("TT", cstype="outside")
5252

5353

5454
def test_params_position_invalid_anchor():
5555
"""
5656
Test that invalid anchor inputs raise GMTValueError.
5757
"""
5858
with pytest.raises(GMTValueError):
59-
Position((10, 20), type="mapcoords", anchor="XX")
59+
Position((10, 20), cstype="mapcoords", anchor="XX")

0 commit comments

Comments
 (0)