sqil-core 0.0.1__py3-none-any.whl → 0.1.0__py3-none-any.whl

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.
@@ -1,134 +0,0 @@
1
- from decimal import ROUND_DOWN, Decimal
2
-
3
- import numpy as np
4
-
5
- from .const import EXP_UNIT_MAP, PARAM_METADATA
6
- from .read import read_json
7
-
8
-
9
- def _cut_to_significant_digits(number, n):
10
- """Cut a number to n significant digits."""
11
- if number == 0:
12
- return 0 # Zero has no significant digits
13
- d = Decimal(str(number))
14
- shift = d.adjusted() # Get the exponent of the number
15
- rounded = d.scaleb(-shift).quantize(
16
- Decimal("1e-{0}".format(n - 1)), rounding=ROUND_DOWN
17
- )
18
- return float(rounded.scaleb(shift))
19
-
20
-
21
- def format_number(
22
- num: float | np.ndarray, precision: int = 3, unit: str = "", latex: bool = True
23
- ) -> str:
24
- """Format a number (or an array of numbers) in a nice way for printing.
25
-
26
- Parameters
27
- ----------
28
- num : float | np.ndarray
29
- Input number (or array). Should not be rescaled,
30
- e.g. input values in Hz, NOT GHz
31
- precision : int
32
- The number of digits of the output number. Must be >= 3.
33
- unit : str, optional
34
- Unit of measurement, by default ''
35
- latex : bool, optional
36
- Include Latex syntax, by default True
37
-
38
- Returns
39
- -------
40
- str
41
- Formatted number
42
- """
43
- # Handle arrays
44
- if isinstance(num, (list, np.ndarray)):
45
- return [format_number(n, unit, latex) for n in num]
46
-
47
- # Return if not a number
48
- if not isinstance(num, (int, float, complex)):
49
- return num
50
-
51
- # Format number
52
- exp_form = f"{num:.12e}"
53
- base, exponent = exp_form.split("e")
54
- # Make exponent a multiple of 3
55
- base = float(base) * 10 ** (int(exponent) % 3)
56
- exponent = (int(exponent) // 3) * 3
57
- # Apply precision to the base
58
- if precision < 3:
59
- precision = 3
60
- base_precise = _cut_to_significant_digits(
61
- base, precision + 1
62
- ) # np.round(base, precision - (int(exponent) % 3))
63
- base_precise = np.round(
64
- base_precise, precision - len(str(base_precise).split(".")[0])
65
- )
66
- if int(base_precise) == float(base_precise):
67
- base_precise = int(base_precise)
68
-
69
- # Build string
70
- if unit:
71
- res = f"{base_precise}{'~' if latex else ' '}{EXP_UNIT_MAP[exponent]}{unit}"
72
- else:
73
- res = f"{base_precise}" + (f" x 10^{{{exponent}}}" if exponent != 0 else "")
74
- return f"${res}$" if latex else res
75
-
76
-
77
- def get_name_and_unit(param_id: str) -> str:
78
- """Get the name and unit of measurement of a prameter, e.g. Frequency [GHz].
79
-
80
- Parameters
81
- ----------
82
- param : str
83
- Parameter ID, as defined in the param_dict.json file.
84
-
85
- Returns
86
- -------
87
- str
88
- Name and [unit]
89
- """
90
- meta = PARAM_METADATA[param_id]
91
- scale = meta["scale"] if "scale" in meta else 1
92
- exponent = -(int(f"{scale:.0e}".split("e")[1]) // 3) * 3
93
- return f"{meta['name']} [{EXP_UNIT_MAP[exponent]}{meta['unit']}]"
94
-
95
-
96
- def get_x_id_by_plot_dim(exp_id: str, plot_dim: str, sweep_param: str | None) -> str:
97
- if exp_id == "CW_onetone":
98
- if plot_dim == "1":
99
- return sweep_param or "ro_freq"
100
- return "ro_freq"
101
-
102
-
103
- def build_title(title: str, path: str, params: list[str]) -> str:
104
- """Build a plot title that includes the values of given parameters found in
105
- the params_dict.json file, e.g. One tone with I = 0.5 mA.
106
-
107
- Parameters
108
- ----------
109
- title : str
110
- Title of the plot to which the parameters will be appended.
111
-
112
- path: str
113
- Path to the param_dict.json file.
114
-
115
- params : List[str]
116
- List of keys of parameters in the param_dict.json file.
117
-
118
- Returns
119
- -------
120
- str
121
- The original title followed by parameter values.
122
- """
123
- dic = read_json(f"{path}/param_dict.json")
124
- title += " with "
125
- for idx, param in enumerate(params):
126
- if not (param in PARAM_METADATA.keys()) or not (param in dic):
127
- title += f"{param} = ? & "
128
- continue
129
- meta = PARAM_METADATA[param]
130
- value = format_number(dic[param], meta["unit"])
131
- title += f"${meta['symbol']} =${value} & "
132
- if idx % 2 == 0 and idx != 0:
133
- title += "\n"
134
- return title[0:-3]
@@ -1,10 +0,0 @@
1
- sqil_core/__init__.py,sha256=JzMIz-0dEtF2rpf7ZBoIG4Ypd-0R4Xt87E8UKk6Was4,105
2
- sqil_core/utils/__init__.py,sha256=KzCQaJ11jGja82QXC7lHI1MYKi4Gxz_qwxCr8oTxK3k,156
3
- sqil_core/utils/analysis.py,sha256=CrtZ06KlNq-CcROoJiKgQWtUV9xnN3Ppv7QsUGFAY08,2106
4
- sqil_core/utils/const.py,sha256=gfZL9MOzAxJ0BeKMxIelVN3yY0dG-Px9W5fwGiZRYfw,953
5
- sqil_core/utils/formatter.py,sha256=VyYY2qGhWnt6TU3dOcwGpPUsNqMt-0TIZdzw3CnyCh4,4190
6
- sqil_core/utils/read.py,sha256=BSbv-audrnILJceCMOTr8KWsjza-4OypGBiV1FVY4yM,4963
7
- sqil_core-0.0.1.dist-info/entry_points.txt,sha256=2IYIJomhGZYKEZRBeCuH07ng82_2RzvrZOfhmBdhYxY,99
8
- sqil_core-0.0.1.dist-info/METADATA,sha256=-8WGOUEFls4M2Aticfslnex1wA_XjgXv9V57S2rucr4,2434
9
- sqil_core-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
- sqil_core-0.0.1.dist-info/RECORD,,