clean up and avoid setting a copy warnings
This commit is contained in:
parent
ae000e449c
commit
624cf5fce2
|
@ -11,6 +11,7 @@ parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("input", nargs="?", default=None)
|
parser.add_argument("input", nargs="?", default=None)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def mlcc_code2specs(code):
|
def mlcc_code2specs(code):
|
||||||
specs = {}
|
specs = {}
|
||||||
code = code.lower()
|
code = code.lower()
|
||||||
|
@ -21,9 +22,30 @@ def mlcc_code2specs(code):
|
||||||
specs["tolerance"] = 0
|
specs["tolerance"] = 0
|
||||||
else:
|
else:
|
||||||
# type 2
|
# type 2
|
||||||
specs["temperature_min"] = {"x": -55, "y": -30, "z": +10}[code[0]]
|
specs["temperature_min"] = {
|
||||||
specs["temperature_max"] = {2: +45, 4: +65, 5: +85, 6: +105, 7: +125}[int(code[1])]
|
"x": -55,
|
||||||
specs["tolerance"] = {"d":0.033, "e":0.047, "f":0.075, "p":0.10, "r":0.15, "s":0.22, "t":0.33, "u":0.56, "v":0.82}[code[2]]
|
"y": -30,
|
||||||
|
"z": +10,
|
||||||
|
}[code[0]]
|
||||||
|
specs["temperature_max"] = {
|
||||||
|
2: +45,
|
||||||
|
4: +65,
|
||||||
|
5: +85,
|
||||||
|
6: +105,
|
||||||
|
7: +125,
|
||||||
|
}[int(code[1])]
|
||||||
|
specs["tolerance"] = {
|
||||||
|
"d": 0.033,
|
||||||
|
"e": 0.047,
|
||||||
|
"f": 0.075,
|
||||||
|
"p": 0.10,
|
||||||
|
"r": 0.15,
|
||||||
|
"s": 0.22,
|
||||||
|
"t": 0.33,
|
||||||
|
"u": 0.56,
|
||||||
|
"v": 0.82,
|
||||||
|
}[code[2]]
|
||||||
|
|
||||||
|
|
||||||
footprints = {
|
footprints = {
|
||||||
"0402": (2, ["0402", "R0402", "C0402"]),
|
"0402": (2, ["0402", "R0402", "C0402"]),
|
||||||
|
@ -37,9 +59,13 @@ footprints = {
|
||||||
|
|
||||||
|
|
||||||
# TODO: remove hardcoded csv
|
# TODO: remove hardcoded csv
|
||||||
args.input = "/home/brendan/Documents/tempsync/projects/0034_UniversalController/jlcparts.csv"
|
args.input = (
|
||||||
|
"/home/brendan/Documents/tempsync/projects/0034_UniversalController/jlcparts.csv"
|
||||||
|
)
|
||||||
if args.input:
|
if args.input:
|
||||||
parts_csv = pd.read_csv(args.input, encoding_errors="replace", delimiter=",", index_col=False)
|
parts_csv = pd.read_csv(
|
||||||
|
args.input, encoding_errors="replace", delimiter=",", index_col=False
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -51,33 +77,49 @@ stock = parts_csv[parts_csv["Stock"]>0]
|
||||||
# - if something has tolerance specified as absolute, "Value" may be wrong but "Tolerance" will be NA so it will be dropped
|
# - if something has tolerance specified as absolute, "Value" may be wrong but "Tolerance" will be NA so it will be dropped
|
||||||
|
|
||||||
# resistors
|
# resistors
|
||||||
resistors = stock[stock["First Category"] == "Resistors"]
|
resistors = stock[stock["First Category"] == "Resistors"].copy()
|
||||||
resistors.loc[:, "Value"] = resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:,0]
|
resistors["Value"] = (
|
||||||
resistors.loc[:, "Tolerance"] = resistors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:, 0]
|
||||||
resistors.loc[:, "TempCoef"] = resistors["Description"].str.extract(r"(\d+)ppm/<2F><>").astype(float) / 1e6
|
)
|
||||||
|
resistors["Tolerance"] = (
|
||||||
|
resistors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
||||||
|
)
|
||||||
|
resistors["TempCoef"] = (
|
||||||
|
resistors["Description"].str.extract(r"(\d+)ppm/<2F><>").astype(float) / 1e6
|
||||||
|
)
|
||||||
power_frac = resistors["Description"].str.extract(r"(\d+)/(\d+)W").astype(float)
|
power_frac = resistors["Description"].str.extract(r"(\d+)/(\d+)W").astype(float)
|
||||||
power_frac = power_frac.iloc[:, 0] / power_frac.iloc[:, 1]
|
power_frac = power_frac.iloc[:, 0] / power_frac.iloc[:, 1]
|
||||||
power_dec = resistors["Description"].str.extract(r"(\d+(\.\d+))W").astype(float).iloc[:,0]
|
power_dec = (
|
||||||
|
resistors["Description"].str.extract(r"(\d+(\.\d+))W").astype(float).iloc[:, 0]
|
||||||
|
)
|
||||||
power = power_frac.add(power_dec, fill_value=0)
|
power = power_frac.add(power_dec, fill_value=0)
|
||||||
power[power_frac.notnull() & power_dec.notnull()] = pd.NA
|
power[power_frac.notnull() & power_dec.notnull()] = pd.NA
|
||||||
resistors.loc[:, "Power"] = power
|
resistors["Power"] = power
|
||||||
resistors.loc[:, "Footprint"] = pd.NA
|
resistors["Footprint"] = pd.NA
|
||||||
for fp, (pins, name) in footprints.items():
|
for fp, (pins, names) in footprints.items():
|
||||||
matches = False
|
matches = False
|
||||||
for n in name:
|
for name in names:
|
||||||
matches = matches | (resistors["Package"] == n)
|
matches = matches | (resistors["Package"] == name)
|
||||||
matches = matches & (resistors["Solder Joint"] == pins)
|
matches = matches & (resistors["Solder Joint"] == pins)
|
||||||
resistors["Footprint"][matches] = fp
|
resistors.loc[matches, "Footprint"] = fp
|
||||||
# resistors.drop("Package", inplace=True)
|
# resistors.drop("Package", inplace=True)
|
||||||
resistors.dropna(inplace=True)
|
resistors.dropna(inplace=True)
|
||||||
|
|
||||||
|
print(len(resistors))
|
||||||
|
|
||||||
# capacitors
|
# capacitors
|
||||||
capacitors = stock[stock["First Category"] == "Capacitors"]
|
capacitors = stock[stock["First Category"] == "Capacitors"].copy()
|
||||||
value = capacitors["Description"].str.extract(r"(\d+(\.\d+)?)([pnum]?)F")
|
value = capacitors["Description"].str.extract(r"(\d+(\.\d+)?)([pnum]?)F")
|
||||||
value = value.iloc[:,0].astype(float) * value.iloc[:,2].replace(["p", "n", "u", "m", ""], [1e-12, 1e-9, 1e-6, 1e-3, 1]).astype(float)
|
value = value.iloc[:, 0].astype(float) * value.iloc[:, 2].replace(
|
||||||
capacitors.loc[:, "Value"] = value
|
["p", "n", "u", "m", ""], [1e-12, 1e-9, 1e-6, 1e-3, 1]
|
||||||
capacitors.loc[:, "Tolerance"] = capacitors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
).astype(float)
|
||||||
capacitors.loc[:, "Voltage"] = capacitors["Description"].str.extract(r"(\d+(\.\d+)?)V").astype(float).iloc[:,0]
|
capacitors["Value"] = value
|
||||||
|
capacitors["Tolerance"] = (
|
||||||
|
capacitors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
||||||
|
)
|
||||||
|
capacitors["Voltage"] = (
|
||||||
|
capacitors["Description"].str.extract(r"(\d+(\.\d+)?)V").astype(float).iloc[:, 0]
|
||||||
|
)
|
||||||
# TODO: "MLCC"/"Tantalum"
|
# TODO: "MLCC"/"Tantalum"
|
||||||
code_np0 = capacitors["Description"].str.contains(r"NP0")
|
code_np0 = capacitors["Description"].str.contains(r"NP0")
|
||||||
code_t1 = capacitors["Description"].str.extract(r"([CBLAMPRSTVU][01234678][GHJKLMN])")
|
code_t1 = capacitors["Description"].str.extract(r"([CBLAMPRSTVU][01234678][GHJKLMN])")
|
||||||
|
@ -92,9 +134,9 @@ for fp, (pins, name) in footprints.items():
|
||||||
for n in name:
|
for n in name:
|
||||||
matches = matches | (capacitors["Package"] == n)
|
matches = matches | (capacitors["Package"] == n)
|
||||||
matches = matches & (capacitors["Solder Joint"] == pins)
|
matches = matches & (capacitors["Solder Joint"] == pins)
|
||||||
capacitors["Footprint"][matches] = fp
|
capacitors.loc[matches, "Footprint"] = fp
|
||||||
# capacitors.drop("Package", inplace=True)
|
# capacitors.drop("Package", inplace=True)
|
||||||
capacitors.dropna(inplace=True)
|
capacitors.dropna(inplace=True)
|
||||||
|
|
||||||
|
print(len(capacitors))
|
||||||
pass
|
pass
|
Loading…
Reference in New Issue
Block a user