@@ -113,9 +113,7 @@ class Session:
113
113
... with GMTTempFile() as fout:
114
114
... # Call the grdinfo module with the virtual file as input
115
115
... # and the temp file as output.
116
- ... ses.call_module(
117
- ... "grdinfo", "{} -C ->{}".format(fin, fout.name)
118
- ... )
116
+ ... ses.call_module("grdinfo", f"{fin} -C ->{fout.name}")
119
117
... # Read the contents of the temp file before it's deleted.
120
118
... print(fout.read().strip())
121
119
...
@@ -189,9 +187,8 @@ def __enter__(self):
189
187
if Version (version ) < Version (self .required_version ):
190
188
self .destroy ()
191
189
raise GMTVersionError (
192
- "Using an incompatible GMT version {}. Must be equal or newer than {}." .format (
193
- version , self .required_version
194
- )
190
+ f"Using an incompatible GMT version { version } . "
191
+ f"Must be equal or newer than { self .required_version } ."
195
192
)
196
193
return self
197
194
@@ -366,7 +363,7 @@ def print_func(file_pointer, message): # pylint: disable=unused-argument
366
363
367
364
if session is None :
368
365
raise GMTCLibError (
369
- "Failed to create a GMT API session:\n {}" . format ( self ._error_message )
366
+ f "Failed to create a GMT API session:\n { self ._error_message } "
370
367
)
371
368
372
369
self .session_pointer = session
@@ -412,7 +409,7 @@ def destroy(self):
412
409
status = c_destroy_session (self .session_pointer )
413
410
if status :
414
411
raise GMTCLibError (
415
- "Failed to destroy GMT API session:\n {}" . format ( self ._error_message )
412
+ f "Failed to destroy GMT API session:\n { self ._error_message } "
416
413
)
417
414
418
415
self .session_pointer = None
@@ -462,9 +459,7 @@ def get_default(self, name):
462
459
463
460
if status != 0 :
464
461
raise GMTCLibError (
465
- "Error getting default value for '{}' (error code {})." .format (
466
- name , status
467
- )
462
+ f"Error getting default value for '{ name } ' (error code { status } )."
468
463
)
469
464
470
465
return value .value .decode ()
@@ -503,9 +498,7 @@ def call_module(self, module, args):
503
498
)
504
499
if status != 0 :
505
500
raise GMTCLibError (
506
- "Module '{}' failed with status code {}:\n {}" .format (
507
- module , status , self ._error_message
508
- )
501
+ f"Module '{ module } ' failed with status code { status } :\n { self ._error_message } "
509
502
)
510
503
511
504
def create_data (self , family , geometry , mode , ** kwargs ):
@@ -650,30 +643,24 @@ def _parse_constant(self, constant, valid, valid_modifiers=None):
650
643
nmodifiers = len (parts ) - 1
651
644
if nmodifiers > 1 :
652
645
raise GMTInvalidInput (
653
- "Only one modifier is allowed in constants, {} given: '{}'" .format (
654
- nmodifiers , constant
655
- )
646
+ f"Only one modifier is allowed in constants, { nmodifiers } given: '{ constant } '"
656
647
)
657
648
if nmodifiers > 0 and valid_modifiers is None :
658
649
raise GMTInvalidInput (
659
650
"Constant modifiers not allowed since valid values were not "
660
- + "given: '{}'" . format ( constant )
651
+ + f "given: '{ constant } '"
661
652
)
662
653
if name not in valid :
663
654
raise GMTInvalidInput (
664
- "Invalid constant argument '{}'. Must be one of {}." .format (
665
- name , str (valid )
666
- )
655
+ f"Invalid constant argument '{ name } '. Must be one of { str (valid )} ."
667
656
)
668
657
if (
669
658
nmodifiers > 0
670
659
and valid_modifiers is not None
671
660
and parts [1 ] not in valid_modifiers
672
661
):
673
662
raise GMTInvalidInput (
674
- "Invalid constant modifier '{}'. Must be one of {}." .format (
675
- parts [1 ], str (valid_modifiers )
676
- )
663
+ f"Invalid constant modifier '{ parts [1 ]} '. Must be one of { str (valid_modifiers )} ."
677
664
)
678
665
integer_value = sum (self [part ] for part in parts )
679
666
return integer_value
@@ -905,7 +892,7 @@ def put_matrix(self, dataset, matrix, pad=0):
905
892
self .session_pointer , dataset , gmt_type , pad , matrix_pointer
906
893
)
907
894
if status != 0 :
908
- raise GMTCLibError ("Failed to put matrix of type {}." . format ( matrix .dtype ) )
895
+ raise GMTCLibError (f "Failed to put matrix of type { matrix .dtype } ." )
909
896
910
897
def write_data (self , family , geometry , mode , wesn , output , data ):
911
898
"""
@@ -974,7 +961,7 @@ def write_data(self, family, geometry, mode, wesn, output, data):
974
961
data ,
975
962
)
976
963
if status != 0 :
977
- raise GMTCLibError ("Failed to write dataset to '{}'" . format ( output ) )
964
+ raise GMTCLibError (f "Failed to write dataset to '{ output } '" )
978
965
979
966
@contextmanager
980
967
def open_virtual_file (self , family , geometry , direction , data ):
@@ -1036,7 +1023,7 @@ def open_virtual_file(self, family, geometry, direction, data):
1036
1023
... with lib.open_virtual_file(*vfargs) as vfile:
1037
1024
... # Send the output to a temp file so that we can read it
1038
1025
... with GMTTempFile() as ofile:
1039
- ... args = "{ } ->{}".format(vfile, ofile.name)
1026
+ ... args = f"{vfile } ->{ofile.name}"
1040
1027
... lib.call_module("info", args)
1041
1028
... print(ofile.read().strip())
1042
1029
...
@@ -1083,7 +1070,7 @@ def open_virtual_file(self, family, geometry, direction, data):
1083
1070
finally :
1084
1071
status = c_close_virtualfile (self .session_pointer , vfname .encode ())
1085
1072
if status != 0 :
1086
- raise GMTCLibError ("Failed to close virtual file '{}'." . format ( vfname ) )
1073
+ raise GMTCLibError (f "Failed to close virtual file '{ vfname } '." )
1087
1074
1088
1075
@contextmanager
1089
1076
def virtualfile_from_vectors (self , * vectors ):
@@ -1131,9 +1118,7 @@ def virtualfile_from_vectors(self, *vectors):
1131
1118
... with ses.virtualfile_from_vectors(x, y, z) as fin:
1132
1119
... # Send the output to a file so that we can read it
1133
1120
... with GMTTempFile() as fout:
1134
- ... ses.call_module(
1135
- ... "info", "{} ->{}".format(fin, fout.name)
1136
- ... )
1121
+ ... ses.call_module("info", f"{fin} ->{fout.name}")
1137
1122
... print(fout.read().strip())
1138
1123
...
1139
1124
<vector memory>: N = 3 <1/3> <4/6> <7/9>
@@ -1244,9 +1229,7 @@ def virtualfile_from_matrix(self, matrix):
1244
1229
... with ses.virtualfile_from_matrix(data) as fin:
1245
1230
... # Send the output to a file so that we can read it
1246
1231
... with GMTTempFile() as fout:
1247
- ... ses.call_module(
1248
- ... "info", "{} ->{}".format(fin, fout.name)
1249
- ... )
1232
+ ... ses.call_module("info", f"{fin} ->{fout.name}")
1250
1233
... print(fout.read().strip())
1251
1234
...
1252
1235
<matrix memory>: N = 4 <0/9> <1/10> <2/11>
@@ -1327,7 +1310,7 @@ def virtualfile_from_grid(self, grid):
1327
1310
... with ses.virtualfile_from_grid(data) as fin:
1328
1311
... # Send the output to a file so that we can read it
1329
1312
... with GMTTempFile() as fout:
1330
- ... args = "{ } -L0 -Cn ->{}".format(fin, fout.name)
1313
+ ... args = f"{fin } -L0 -Cn ->{fout.name}"
1331
1314
... ses.call_module("grdinfo", args)
1332
1315
... print(fout.read().strip())
1333
1316
...
@@ -1508,7 +1491,7 @@ def extract_region(self):
1508
1491
>>> with Session() as lib:
1509
1492
... wesn = lib.extract_region()
1510
1493
...
1511
- >>> print(", ".join(["{ :.2f}".format(x) for x in wesn]))
1494
+ >>> print(", ".join([f"{x :.2f}" for x in wesn]))
1512
1495
0.00, 10.00, -20.00, -10.00
1513
1496
1514
1497
Using ISO country codes for the regions (for example ``'US.HI'`` for
@@ -1521,7 +1504,7 @@ def extract_region(self):
1521
1504
>>> with Session() as lib:
1522
1505
... wesn = lib.extract_region()
1523
1506
...
1524
- >>> print(", ".join(["{ :.2f}".format(x) for x in wesn]))
1507
+ >>> print(", ".join([f"{x :.2f}" for x in wesn]))
1525
1508
-164.71, -154.81, 18.91, 23.58
1526
1509
1527
1510
The country codes can have an extra argument that rounds the region a
@@ -1535,7 +1518,7 @@ def extract_region(self):
1535
1518
>>> with Session() as lib:
1536
1519
... wesn = lib.extract_region()
1537
1520
...
1538
- >>> print(", ".join(["{ :.2f}".format(x) for x in wesn]))
1521
+ >>> print(", ".join([f"{x :.2f}" for x in wesn]))
1539
1522
-165.00, -150.00, 15.00, 25.00
1540
1523
"""
1541
1524
c_extract_region = self .get_libgmt_func (
0 commit comments