stringcalc 0.1.0.dev13__tar.gz → 0.1.0.dev15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/.pre-commit-config.yaml +7 -7
  2. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/PKG-INFO +3 -3
  3. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/README.md +1 -1
  4. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/__init__.py +1 -1
  5. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/cli.py +79 -8
  6. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/ghs.csv +22 -22
  7. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/frets.py +4 -3
  8. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/tension.py +112 -39
  9. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/tests/test_string.py +28 -14
  10. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/LICENSE +0 -0
  11. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/docs/prior-art.md +0 -0
  12. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/pyproject.toml +0 -0
  13. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/__init__.py +0 -0
  14. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/aquila-nng.csv +0 -0
  15. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/daddario-tension.csv +0 -0
  16. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/stringjoy.csv +0 -0
  17. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/data/worth.csv +0 -0
  18. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/stringcalc/py.typed +0 -0
  19. {stringcalc-0.1.0.dev13 → stringcalc-0.1.0.dev15}/tests/test_frets.py +0 -0
@@ -1,6 +1,6 @@
1
1
  repos:
2
2
  - repo: https://github.com/pre-commit/pre-commit-hooks
3
- rev: "v4.4.0"
3
+ rev: "v5.0.0"
4
4
  hooks:
5
5
  - id: trailing-whitespace
6
6
  - id: end-of-file-fixer
@@ -8,27 +8,27 @@ repos:
8
8
  - id: check-yaml
9
9
 
10
10
  - repo: https://github.com/asottile/pyupgrade
11
- rev: "v3.4.0"
11
+ rev: "v3.19.1"
12
12
  hooks:
13
13
  - id: pyupgrade
14
14
  args: [--py39-plus]
15
15
 
16
16
  - repo: https://github.com/PyCQA/isort
17
- rev: "5.12.0"
17
+ rev: "6.0.1"
18
18
  hooks:
19
19
  - id: isort
20
20
 
21
21
  - repo: https://github.com/psf/black
22
- rev: "23.3.0"
22
+ rev: "25.1.0"
23
23
  hooks:
24
24
  - id: black
25
25
 
26
26
  - repo: https://github.com/csachs/pyproject-flake8
27
- rev: "v6.0.0.post1"
27
+ rev: "v7.0.0"
28
28
  hooks:
29
29
  - id: pyproject-flake8 # pflake8
30
30
 
31
- - repo: https://github.com/pre-commit/mirrors-prettier
32
- rev: "v2.7.1"
31
+ - repo: https://github.com/rbubley/mirrors-prettier
32
+ rev: "v3.5.3"
33
33
  hooks:
34
34
  - id: prettier
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: stringcalc
3
- Version: 0.1.0.dev13
3
+ Version: 0.1.0.dev15
4
4
  Summary: Calculations for instrument strings
5
5
  Author-email: zmoon <zmoon92@gmail.com>
6
6
  Requires-Python: ~=3.9
@@ -26,7 +26,7 @@ Provides-Extra: test
26
26
 
27
27
  # stringcalc
28
28
 
29
- *Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings*
29
+ _Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings_
30
30
 
31
31
  [![CI workflow status](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
32
32
  [![Version on PyPI](https://img.shields.io/pypi/v/stringcalc.svg)](https://pypi.org/project/stringcalc/)
@@ -1,6 +1,6 @@
1
1
  # stringcalc
2
2
 
3
- *Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings*
3
+ _Calculations for [string instrument](https://en.wikipedia.org/wiki/String_instrument)s' strings_
4
4
 
5
5
  [![CI workflow status](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml/badge.svg)](https://github.com/zmoon/stringcalc/actions/workflows/ci.yml)
6
6
  [![Version on PyPI](https://img.shields.io/pypi/v/stringcalc.svg)](https://pypi.org/project/stringcalc/)
@@ -2,4 +2,4 @@
2
2
  Calculations for instrument strings
3
3
  """
4
4
 
5
- __version__ = "0.1.0.dev13"
5
+ __version__ = "0.1.0.dev15"
@@ -1,6 +1,7 @@
1
1
  """
2
2
  CLI
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  import functools
@@ -85,7 +86,7 @@ def _version_callback(show: bool):
85
86
 
86
87
 
87
88
  @app.callback()
88
- def main(
89
+ def main( # noqa: E704
89
90
  version: bool = typer.Option(
90
91
  False,
91
92
  "--version/",
@@ -93,8 +94,7 @@ def main(
93
94
  callback=_version_callback,
94
95
  is_eager=True,
95
96
  )
96
- ):
97
- ...
97
+ ): ...
98
98
 
99
99
 
100
100
  def _with_float_nonext_dtypes(df):
@@ -287,11 +287,45 @@ def gauge_(
287
287
  help=("If true, suggest D'Addario gauges. If false, compute exact gauge."),
288
288
  ),
289
289
  types: list[str] = typer.Option(
290
- None, "--type", help="String type. Can specify multiple times if using --suggest."
290
+ None,
291
+ "--type",
292
+ help=(
293
+ "String type. Can specify multiple times if using --suggest. "
294
+ "For --suggest, defaults to D'Addario phosphor bronze and plain steel ('DA:PB', 'DA:PL'). "
295
+ "If not using --suggest, must specify exactly one type (no default). "
296
+ ),
291
297
  ),
292
298
  nsuggest: int = typer.Option(
293
299
  3, "-N", "--nsuggest", help="Number of suggestions. Only relevant if using --suggest."
294
300
  ),
301
+ is_fan: bool = typer.Option(
302
+ None,
303
+ "--fanned",
304
+ help=(
305
+ "Fanned calculations. Must provide two scale lengths. "
306
+ "Assumed if two scale lengths are provided."
307
+ ),
308
+ ),
309
+ nut_width: float = typer.Option(
310
+ None,
311
+ "-w",
312
+ "--nut-width",
313
+ help=(
314
+ "Neck width at (center of?) nut (for fanned calculations). "
315
+ "Required if using --fanned."
316
+ ),
317
+ ),
318
+ edge_space: list[float] = typer.Option(
319
+ None,
320
+ "-e",
321
+ "--edge-space",
322
+ help=(
323
+ "Edge space, between the edge of the neck and the center of the first string. "
324
+ "You can specify one (used for both left and right) or two (left, right). "
325
+ 'The default is 5/32" on the left and 1/8" on the right. '
326
+ "Only used for fanned calculations."
327
+ ),
328
+ ),
295
329
  float_format: str = typer.Option(
296
330
  r"%.3f", help="Format for float-to-string conversion. Only relevant if using --suggest."
297
331
  ),
@@ -316,11 +350,45 @@ def gauge_(
316
350
  types_set: set[str]
317
351
  if not types:
318
352
  if verbose:
319
- info("No string types specified, defaulting to PB + PL.")
320
- types_set = {"PB", "PL"}
353
+ info("No string types specified, defaulting to D'Addario PB + PL.")
354
+ types_set = {"DA:PB", "DA:PL"}
321
355
  else:
322
356
  types_set = set(types)
323
357
 
358
+ if is_fan is None:
359
+ is_fan = len(L) == 2
360
+ if is_fan:
361
+ if len(L) != 2:
362
+ error(
363
+ "Must supply two scale lengths (bass and treble sides) for fanned calculation. "
364
+ f"Got {len(L)}.",
365
+ rc=2,
366
+ )
367
+ n_str = max(len(T), len(P))
368
+ if n_str < 2:
369
+ error("Need at least two strings for fanned calculation.", rc=2)
370
+ if not nut_width:
371
+ error("Must supply nut width for fanned calculation.", rc=2)
372
+ if edge_space is None:
373
+ edge_space = [5 / 32, 1 / 8]
374
+ else:
375
+ if len(edge_space) == 1:
376
+ edge_space *= 2
377
+ elif len(edge_space) > 2:
378
+ error(f"Specify one or two edge space values. Got {len(edge_space)}.", rc=2)
379
+ e_b, e_t = edge_space
380
+ L_b, L_t = L
381
+ dLdx = (L_t - L_b) / nut_width
382
+ d = (nut_width - e_b - e_t) / (n_str - 1) # string spacing
383
+ xs = [e_b + i * d for i in range(n_str)]
384
+ L = [round(L_b + dLdx * x, 4) for x in xs]
385
+ if verbose:
386
+ info(f"Nut width: {nut_width}")
387
+ info(f"Left/bass edge space: {e_b}")
388
+ info(f"Right/treble edge space: {e_t}")
389
+ info(f"Computed string spacing: {round(d, 4)}")
390
+ info(f"Computed string nut positions: {[round(x, 4) for x in xs]}")
391
+
324
392
  if verbose:
325
393
  info(f"Searching string types: {types_set}")
326
394
 
@@ -345,7 +413,7 @@ def gauge_(
345
413
  g_df.attrs["col_desc"]["dT"] += f" ({T_} lbf)"
346
414
  table = _rich_table(
347
415
  g_df,
348
- title=f"Closest D'Addario gauges\nfor {L_}\" @ {P_}",
416
+ title=f'Closest gauges\nfor {L_}" @ {P_}',
349
417
  float_format=float_format,
350
418
  panel=n_cases > 1,
351
419
  column_info=column_info,
@@ -357,7 +425,10 @@ def gauge_(
357
425
 
358
426
  else:
359
427
  if not types:
360
- error("Must supply type to use exact gauge calculation.", rc=2)
428
+ error(
429
+ "Must supply type to use exact gauge calculation, e.g. 'plain nylon', 'plain steel'.",
430
+ rc=2,
431
+ )
361
432
 
362
433
  if len(types) > 1:
363
434
  error(f"Only specify one type for exact gauge calculation. Got {types}.", rc=2)
@@ -178,28 +178,28 @@ DY58,0.0006736,0.058,Electric - Boomers,DY
178
178
  DY60,0.0008791,0.06,Electric - Boomers,DY
179
179
  DY70,0.0008867,0.07,Electric - Boomers,DY
180
180
  DY80,0.001211,0.08,Electric - Boomers,DY
181
- N18B,7.424e-05,0.018,Electric - Nickel Rockers,NB
182
- N20B,9.326e-05,0.02,Electric - Nickel Rockers,NB
183
- N22B,0.0001024,0.022,Electric - Nickel Rockers,NB
184
- N24B,0.0001202,0.024,Electric - Nickel Rockers,NB
185
- N26B,0.0001528,0.026,Electric - Nickel Rockers,NB
186
- N28B,0.0001695,0.028,Electric - Nickel Rockers,NB
187
- N30B,0.0001829,0.03,Electric - Nickel Rockers,NB
188
- N32B,0.0002186,0.032,Electric - Nickel Rockers,NB
189
- N34B,0.0002485,0.034,Electric - Nickel Rockers,NB
190
- N36B,0.0002786,0.036,Electric - Nickel Rockers,NB
191
- N38B,0.0003128,0.038,Electric - Nickel Rockers,NB
192
- N40B,0.0003234,0.04,Electric - Nickel Rockers,NB
193
- N42B,0.0003701,0.042,Electric - Nickel Rockers,NB
194
- N44B,0.0004174,0.044,Electric - Nickel Rockers,NB
195
- N46B,0.0004404,0.046,Electric - Nickel Rockers,NB
196
- N48B,0.0004999,0.048,Electric - Nickel Rockers,NB
197
- N50B,0.0005332,0.05,Electric - Nickel Rockers,NB
198
- N52B,0.000564,0.052,Electric - Nickel Rockers,NB
199
- N54B,0.0006025,0.054,Electric - Nickel Rockers,NB
200
- N56B,0.0006762,0.056,Electric - Nickel Rockers,NB
201
- N58B,0.000759,0.058,Electric - Nickel Rockers,NB
202
- N60B,0.0007527,0.06,Electric - Nickel Rockers,NB
181
+ N18,7.424e-05,0.018,Electric - Nickel Rockers,N
182
+ N20,9.326e-05,0.02,Electric - Nickel Rockers,N
183
+ N22,0.0001024,0.022,Electric - Nickel Rockers,N
184
+ N24,0.0001202,0.024,Electric - Nickel Rockers,N
185
+ N26,0.0001528,0.026,Electric - Nickel Rockers,N
186
+ N28,0.0001695,0.028,Electric - Nickel Rockers,N
187
+ N30,0.0001829,0.03,Electric - Nickel Rockers,N
188
+ N32,0.0002186,0.032,Electric - Nickel Rockers,N
189
+ N34,0.0002485,0.034,Electric - Nickel Rockers,N
190
+ N36,0.0002786,0.036,Electric - Nickel Rockers,N
191
+ N38,0.0003128,0.038,Electric - Nickel Rockers,N
192
+ N40,0.0003234,0.04,Electric - Nickel Rockers,N
193
+ N42,0.0003701,0.042,Electric - Nickel Rockers,N
194
+ N44,0.0004174,0.044,Electric - Nickel Rockers,N
195
+ N46,0.0004404,0.046,Electric - Nickel Rockers,N
196
+ N48,0.0004999,0.048,Electric - Nickel Rockers,N
197
+ N50,0.0005332,0.05,Electric - Nickel Rockers,N
198
+ N52,0.000564,0.052,Electric - Nickel Rockers,N
199
+ N54,0.0006025,0.054,Electric - Nickel Rockers,N
200
+ N56,0.0006762,0.056,Electric - Nickel Rockers,N
201
+ N58,0.000759,0.058,Electric - Nickel Rockers,N
202
+ N60,0.0007527,0.06,Electric - Nickel Rockers,N
203
203
  ST18,0.0001028,0.018,Electric - Super Steels,ST
204
204
  ST20,0.0001081,0.02,Electric - Super Steels,ST
205
205
  ST22,0.0001018,0.022,Electric - Super Steels,ST
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Fret distances
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  from typing import Union
@@ -18,7 +19,7 @@ QLike = Union[Quantity, str]
18
19
  # Note also `pint._typing.UnitLike`
19
20
 
20
21
 
21
- def distance_et(n: int | npt.ArrayLike, *, L: float) -> np.float_ | npt.NDArray[np.float_]:
22
+ def distance_et(n: int | npt.ArrayLike, *, L: float) -> np.float64 | npt.NDArray[np.float64]:
22
23
  """Exact equal-temperament distance from nut for fret(s) `n` for scale length `L`.
23
24
 
24
25
  Using the 12th-root-of-2 method.
@@ -33,12 +34,12 @@ def distance_et(n: int | npt.ArrayLike, *, L: float) -> np.float_ | npt.NDArray[
33
34
  s
34
35
  Scale length.
35
36
  """
36
- n = np.floor(n, dtype=float)
37
+ n = np.floor(n, dtype=np.float64)
37
38
 
38
39
  if not np.all(n > 0):
39
40
  raise ValueError("input fret numbers should be positive")
40
41
 
41
- return L * (1 - 1 / (2 ** (n / 12)))
42
+ return (L * (1 - 1 / (2 ** (n / 12)))).astype(np.float64)
42
43
 
43
44
 
44
45
  def distances(N: int, *, L: float, method: str = "et") -> pd.DataFrame:
@@ -5,13 +5,14 @@ e.g.
5
5
  - For specified strings, calculate tensions
6
6
  - For specified total or per-string tension, suggest strings
7
7
  """
8
+
8
9
  from __future__ import annotations
9
10
 
10
11
  import math
11
12
  import re
12
13
  import warnings
13
14
  from functools import lru_cache
14
- from typing import Callable, NamedTuple
15
+ from typing import NamedTuple, Protocol
15
16
 
16
17
  import pandas as pd
17
18
 
@@ -31,10 +32,10 @@ DATA = _get_data()
31
32
  def load_data() -> pd.DataFrame:
32
33
  """Load all string data.
33
34
 
34
- Use the individual `load_*_data` functions for more control.
35
+ Combines results from the individual ``load_*_data`` functions with ``for_combined=True``.
35
36
  """
36
37
  df = pd.concat(
37
- [fn() for fn in _DATA_LOADERS],
38
+ [fn(for_combined=True) for fn in _DATA_LOADERS],
38
39
  ignore_index=True,
39
40
  )
40
41
 
@@ -45,23 +46,42 @@ def load_data() -> pd.DataFrame:
45
46
 
46
47
 
47
48
  @lru_cache(2)
48
- def load_daddario_data(*, drop_sample_tensions: bool = True) -> pd.DataFrame:
49
- """Load the data (currently only D'Addario) needed for the calculations."""
49
+ def load_daddario_data(*, for_combined: bool = False) -> pd.DataFrame:
50
+ """Load the data (currently only D'Addario) needed for the calculations.
51
+
52
+ Parameters
53
+ ----------
54
+ for_combined
55
+ Return the frame intended for use in the combined dataset (:func:`load_data`),
56
+ adding appropriate prefixes and dropping extraneous columns.
57
+ """
50
58
 
51
59
  df = pd.read_csv(DATA.joinpath("daddario-tension.csv"), header=0).convert_dtypes()
52
60
 
53
- if drop_sample_tensions:
61
+ if for_combined:
54
62
  df = df.drop(columns=["notes", "tens"])
55
63
 
64
+ df["group"] = "D'Addario - " + df["category"] + " - " + df["group"]
65
+ df["group_id"] = "DA:" + df["group_id"]
66
+ df["id"] = "DA:" + df["id"]
67
+
68
+ df = df.drop(columns=["category", "id_pref", "id_suff"])
69
+
56
70
  # Set categorical columns
57
71
  for name in ["category", "group", "id_pref", "id_suff", "group_id"]:
58
- df[name] = df[name].astype("category")
72
+ if name in df.columns:
73
+ df[name] = df[name].astype("category")
59
74
 
60
75
  return df
61
76
 
62
77
 
78
+ @lru_cache(1)
79
+ def _get_daddario_group_ids() -> set[str]:
80
+ return set(load_daddario_data(for_combined=False).group_id.cat.categories)
81
+
82
+
63
83
  @lru_cache
64
- def load_aquila_data(*, nng_density: float = 1300, drop_gauge_eqvs: bool = True) -> pd.DataFrame:
84
+ def load_aquila_data(*, nng_density: float = 1300, for_combined: bool = False) -> pd.DataFrame:
65
85
  """Load Aquila NNG (New Nylgut) data.
66
86
 
67
87
  Parameters
@@ -71,6 +91,9 @@ def load_aquila_data(*, nng_density: float = 1300, drop_gauge_eqvs: bool = True)
71
91
  They are supposed to be the same density as gut.
72
92
  https://www.cs.helsinki.fi/u/wikla/mus/Calcs/wwwscalc.html says gut is 1276 kg/m3;
73
93
  I have seen 1300 elsewhere.
94
+ for_combined
95
+ Return the frame intended for use in the combined dataset (:func:`load_data`),
96
+ adding appropriate prefixes and dropping extraneous columns.
74
97
  """
75
98
  import numpy as np
76
99
 
@@ -81,84 +104,121 @@ def load_aquila_data(*, nng_density: float = 1300, drop_gauge_eqvs: bool = True)
81
104
  df["uw"] = nng_density * 2.205 / 1e6 * (2.54**3) * (np.pi * df.gauge**2 / 4)
82
105
 
83
106
  # Set group ID (used to select string type)
84
- df["group"] = "Aquila New Nylgut"
107
+ df["group"] = "New Nylgut"
85
108
  df["group_id"] = "NNG"
86
- for name in ["group", "group_id"]:
87
- df[name] = df[name].astype("category")
88
109
 
89
- # Include gauge equivalents?
90
110
  gauge_eqv_cols = [col for col in df.columns if col.startswith("gauge_")]
91
- if drop_gauge_eqvs:
111
+ if for_combined:
112
+ df["group"] = "Aquila " + df["group"]
113
+ df["group_id"] = "A:" + df["group_id"]
114
+ df["id"] = "A:" + df["id"]
115
+
92
116
  df = df.drop(columns=gauge_eqv_cols)
93
117
  else:
94
118
  df = df.rename(columns={col: col.replace("gauge_", "gauge_eqv_") for col in gauge_eqv_cols})
95
119
 
120
+ for name in ["group", "group_id"]:
121
+ df[name] = df[name].astype("category")
122
+
96
123
  return df
97
124
 
98
125
 
99
- @lru_cache(1)
100
- def load_worth_data() -> pd.DataFrame:
101
- """Load Worth fluorocarbon data."""
126
+ @lru_cache(2)
127
+ def load_worth_data(*, for_combined: bool = False) -> pd.DataFrame:
128
+ """Load Worth fluorocarbon data.
129
+
130
+ Parameters
131
+ ----------
132
+ for_combined
133
+ Return the frame intended for use in the combined dataset (:func:`load_data`),
134
+ adding appropriate prefixes and dropping extraneous columns.
135
+ """
102
136
 
103
137
  df = pd.read_csv(DATA.joinpath("worth.csv"), header=0).convert_dtypes()
104
138
 
105
139
  # Set group ID (used to select string type)
106
- df["group"] = "Worth Fluorocarbon"
107
- df["group_id"] = "WFC"
140
+ df["group"] = "Fluorocarbon"
141
+ df["group_id"] = "FC"
142
+
143
+ if for_combined:
144
+ df["group"] = "Worth " + df["group"]
145
+ df["group_id"] = "W" + df["group_id"]
146
+ df["id"] = "WFC:" + df["id"]
147
+
148
+ df = df.drop(columns="rho")
149
+
108
150
  for name in ["group", "group_id"]:
109
151
  df[name] = df[name].astype("category")
110
152
 
111
153
  return df
112
154
 
113
155
 
114
- @lru_cache(1)
115
- def load_stringjoy_data() -> pd.DataFrame:
156
+ @lru_cache(2)
157
+ def load_stringjoy_data(*, for_combined: bool = False) -> pd.DataFrame:
116
158
  """Load Stringjoy data.
117
159
 
118
160
  https://tension.stringjoy.com/
161
+
162
+ Parameters
163
+ ----------
164
+ for_combined
165
+ Return the frame intended for use in the combined dataset (:func:`load_data`),
166
+ adding appropriate prefixes and dropping extraneous columns.
119
167
  """
120
168
 
121
169
  df = pd.read_csv(DATA.joinpath("stringjoy.csv"), header=0).convert_dtypes()
122
170
 
123
- # Differentiate from D'Addario
124
- df["id"] = "SJ" + df["id"]
125
- df["group"] = "Stringjoy " + df["group"]
126
- df["group_id"] = "SJ" + df["group_id"]
171
+ if for_combined:
172
+ df["id"] = "SJ:" + df["id"]
173
+ df["group"] = "Stringjoy " + df["group"]
174
+ df["group_id"] = "SJ:" + df["group_id"]
175
+
127
176
  for name in ["group", "group_id"]:
128
177
  df[name] = df[name].astype("category")
129
178
 
130
179
  return df
131
180
 
132
181
 
133
- @lru_cache(1)
134
- def load_ghs_data() -> pd.DataFrame:
182
+ @lru_cache(2)
183
+ def load_ghs_data(*, for_combined: bool = False) -> pd.DataFrame:
135
184
  """Load GHS data.
136
185
 
137
186
  https://www.ghsstrings.com/pages/tension-calc
187
+
188
+ Parameters
189
+ ----------
190
+ for_combined
191
+ Return the frame intended for use in the combined dataset (:func:`load_data`),
192
+ adding appropriate prefixes and dropping extraneous columns.
138
193
  """
139
194
 
140
195
  df = pd.read_csv(DATA.joinpath("ghs.csv"), header=0).convert_dtypes()
141
196
 
142
197
  # Drop ID dupes (e.g. PL which is included for both acoustic and electric)
143
- df = df.drop_duplicates(subset=["id"])
198
+ df = df.drop_duplicates(subset=["id"], keep="first")
144
199
 
145
200
  # Drop where we don't have gauge (bass strings for different scale lengths)
146
201
  df = df.dropna(subset=["gauge"])
147
202
 
148
- # Differentiate from D'Addario
149
- df["id"] = "GHS" + df["id"]
150
- df["group"] = "GHS - " + df["group"]
151
- df["group_id"] = "GHS" + df["group_id"]
203
+ if for_combined:
204
+ df["id"] = "GHS:" + df["id"]
205
+ df["group"] = "GHS - " + df["group"]
206
+ df["group_id"] = "GHS:" + df["group_id"]
207
+
152
208
  for name in ["group", "group_id"]:
153
209
  df[name] = df[name].astype("category")
154
210
 
155
211
  return df.reset_index(drop=True)
156
212
 
157
213
 
158
- _DATA_LOADERS: list[Callable[[], pd.DataFrame]] = [
214
+ class _DataLoader(Protocol):
215
+ def __call__(self, *, for_combined: bool = False) -> pd.DataFrame: ... # noqa: E704
216
+
217
+
218
+ _DATA_LOADERS: list[_DataLoader] = [
159
219
  load_daddario_data,
160
220
  load_aquila_data,
161
- lambda: load_worth_data().drop(columns="rho"),
221
+ load_worth_data,
162
222
  load_stringjoy_data,
163
223
  load_ghs_data,
164
224
  ]
@@ -258,13 +318,13 @@ def tension(s: String, pitch: str = "A4") -> float:
258
318
  L = s.L
259
319
 
260
320
  if t in {"PL", "S", "PS"}: # plain steel
261
- tda = "PL"
321
+ tda = "DA:PL"
262
322
  elif t in {"PB"}: # phosphor bronze
263
- tda = "PB"
323
+ tda = "DA:PB"
264
324
  elif t in {"NYL", "N"}: # plain "rectified" nylon
265
- tda = "NYL"
325
+ tda = "DA:NYL"
266
326
  elif t in {"NYLW", "NW"}: # standard silver-wrapped nylon
267
- tda = "NYLW"
327
+ tda = "DA:NYLW"
268
328
  else:
269
329
  raise ValueError(f"string type {t!r} invalid or not supported")
270
330
 
@@ -362,7 +422,19 @@ def suggest_gauge(
362
422
  from pyabc2 import Pitch
363
423
 
364
424
  if types is None:
365
- types = {"PB", "PL"}
425
+ types = {"DA:PB", "DA:PL"}
426
+
427
+ # Assume D'Addario if match to an original D'Addario group ID (with no `DA:` prefix)
428
+ daddario_group_ids = _get_daddario_group_ids()
429
+ types_in = types
430
+ types = {t if t not in daddario_group_ids else f"DA:{t}" for t in types}
431
+ types_changed = types_in - types
432
+ if types_changed:
433
+ warnings.warn(
434
+ f"string type groups {sorted(types_changed)} assumed to be D'Addario. "
435
+ f"Use group ID prefix 'DA:' to be explicit and avoid this warning.",
436
+ stacklevel=2,
437
+ )
366
438
 
367
439
  data_all = load_data()
368
440
  data = data_all.query("group_id in @types")
@@ -388,7 +460,8 @@ def suggest_gauge(
388
460
  b = 1.7 # TODO: allow to set this?
389
461
  if (data_sort["dT"] > b).all() or (data_sort["dT"] < -b).all():
390
462
  warnings.warn(
391
- f"You are outside the range of what string type group(s) {types} can provide. "
463
+ f"(T={T}, L={L}, P={pitch}) "
464
+ f"is outside the range of what string type group(s) {types} can provide. "
392
465
  "Maybe a different string type can give the tension/pitch/length you desire.",
393
466
  stacklevel=2,
394
467
  )
@@ -7,6 +7,7 @@ from stringcalc.tension import (
7
7
  _STRING_TYPE_ALIASES,
8
8
  String,
9
9
  gauge,
10
+ load_daddario_data,
10
11
  load_data,
11
12
  load_stringjoy_data,
12
13
  suggest_gauge,
@@ -57,10 +58,10 @@ def test_suggest_gauge():
57
58
  pitch = "E4" # top string in standard guitar tuning
58
59
 
59
60
  ret = suggest_gauge(T, L, pitch)
60
- assert ret.id.tolist() == ["PL011", "PL0115", "PL012"]
61
+ assert ret.id.tolist() == ["DA:PL011", "DA:PL0115", "DA:PL012"]
61
62
 
62
- ret = suggest_gauge(T, L, pitch, types={"NYL"})
63
- assert ret.id.tolist() == ["NYL031", "NYL032", "NYL033"]
63
+ ret = suggest_gauge(T, L, pitch, types={"DA:NYL"})
64
+ assert ret.id.tolist() == ["DA:NYL031", "DA:NYL032", "DA:NYL033"]
64
65
 
65
66
 
66
67
  def test_suggest_gauge_pb056():
@@ -69,8 +70,8 @@ def test_suggest_gauge_pb056():
69
70
  L = 25.5
70
71
  pitch = "D2" # dropped D
71
72
 
72
- ret = suggest_gauge(T, L, pitch, types={"PB"})
73
- assert ret.id.tolist() == ["PB053", "PB056D", "PB059"]
73
+ ret = suggest_gauge(T, L, pitch, types={"DA:PB"})
74
+ assert ret.id.tolist() == ["DA:PB053", "DA:PB056D", "DA:PB059"]
74
75
 
75
76
 
76
77
  @pytest.mark.parametrize(
@@ -80,11 +81,14 @@ def test_suggest_gauge_pb056():
80
81
  def test_suggest_gauge_bounds_warning(pitch):
81
82
  T = 15
82
83
  L = 21
83
- types = {"PB"}
84
+ types = {"DA:PB"}
84
85
 
85
86
  with pytest.warns(
86
87
  UserWarning,
87
- match=r"You are outside the range of what string type group\(s\) \{'PB'\} can provide\.",
88
+ match=(
89
+ rf"\(T=15, L=21, P={pitch}\) "
90
+ r"is outside the range of what string type group\(s\) \{'DA:PB'\} can provide\."
91
+ ),
88
92
  ):
89
93
  suggest_gauge(T=T, L=L, pitch=pitch, types=types)
90
94
 
@@ -93,7 +97,7 @@ def test_suggest_gauge_bounds_warning(pitch):
93
97
  "types",
94
98
  [
95
99
  {"asdf"},
96
- {"PB", "asdf"},
100
+ {"DA:PB", "asdf"},
97
101
  ],
98
102
  ids=[
99
103
  "all invalid",
@@ -141,7 +145,7 @@ def test_aliases_unique():
141
145
 
142
146
 
143
147
  def test_load_data_group_ids_unique():
144
- dfs = [fn() for fn in _DATA_LOADERS]
148
+ dfs = [fn(for_combined=True) for fn in _DATA_LOADERS]
145
149
  for a, b in itertools.product(
146
150
  [set(df.group_id.cat.categories) for df in dfs],
147
151
  repeat=2,
@@ -153,11 +157,14 @@ def test_load_data_group_ids_unique():
153
157
 
154
158
 
155
159
  def test_load_data_cat_dtypes():
156
- df = load_data()
157
-
160
+ df = load_daddario_data(for_combined=False)
158
161
  for name in ["category", "group", "id_pref", "id_suff", "group_id"]:
159
162
  assert df[name].dtype == "category"
160
163
 
164
+ df = load_data()
165
+ for name in ["group", "group_id"]:
166
+ assert df[name].dtype == "category"
167
+
161
168
 
162
169
  def test_load_data_ids_unique():
163
170
  df = load_data()
@@ -167,8 +174,8 @@ def test_load_data_ids_unique():
167
174
 
168
175
 
169
176
  def test_stringjoy_data_ids():
170
- df = load_stringjoy_data()
171
- assert df.group_id.str.len().isin((3, 4)).all()
177
+ df = load_stringjoy_data(for_combined=True)
178
+ assert df.group_id.str.len().isin((4, 5)).all()
172
179
  assert df.group_id.str.startswith("SJ").all()
173
180
  assert df.id.str.startswith("SJ").all()
174
181
  assert (
@@ -180,6 +187,13 @@ def test_string_suggest_t_consistency():
180
187
  s = String.from_spec('25.5" PB .042')
181
188
  P = "A2"
182
189
  T = tension(s, pitch=P)
183
- df = suggest_gauge(T, s.L, P, types={"PB"}, n=1)
190
+ df = suggest_gauge(T, s.L, P, types={"DA:PB"}, n=1)
184
191
  assert df["T"].tolist() == [T]
185
192
  assert df.dT.tolist() == [0]
193
+
194
+
195
+ def test_string_suggest_da_conv_warning():
196
+ with pytest.warns(
197
+ UserWarning, match=r"string type groups \['PB', 'PL'\] assumed to be D'Addario"
198
+ ):
199
+ suggest_gauge(20, 25.5, "G3", types={"PB", "PL"})