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)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def mlcc_code2specs(code):
|
||||
specs = {}
|
||||
code = code.lower()
|
||||
|
@ -21,9 +22,30 @@ def mlcc_code2specs(code):
|
|||
specs["tolerance"] = 0
|
||||
else:
|
||||
# type 2
|
||||
specs["temperature_min"] = {"x": -55, "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]]
|
||||
specs["temperature_min"] = {
|
||||
"x": -55,
|
||||
"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 = {
|
||||
"0402": (2, ["0402", "R0402", "C0402"]),
|
||||
|
@ -37,9 +59,13 @@ footprints = {
|
|||
|
||||
|
||||
# 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:
|
||||
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:
|
||||
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
|
||||
|
||||
# resistors
|
||||
resistors = stock[stock["First Category"] == "Resistors"]
|
||||
resistors.loc[:, "Value"] = resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:,0]
|
||||
resistors.loc[:, "Tolerance"] = resistors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
||||
resistors.loc[:, "TempCoef"] = resistors["Description"].str.extract(r"(\d+)ppm/<2F><>").astype(float) / 1e6
|
||||
resistors = stock[stock["First Category"] == "Resistors"].copy()
|
||||
resistors["Value"] = (
|
||||
resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:, 0]
|
||||
)
|
||||
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 = 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.notnull() & power_dec.notnull()] = pd.NA
|
||||
resistors.loc[:, "Power"] = power
|
||||
resistors.loc[:, "Footprint"] = pd.NA
|
||||
for fp, (pins, name) in footprints.items():
|
||||
resistors["Power"] = power
|
||||
resistors["Footprint"] = pd.NA
|
||||
for fp, (pins, names) in footprints.items():
|
||||
matches = False
|
||||
for n in name:
|
||||
matches = matches | (resistors["Package"] == n)
|
||||
for name in names:
|
||||
matches = matches | (resistors["Package"] == name)
|
||||
matches = matches & (resistors["Solder Joint"] == pins)
|
||||
resistors["Footprint"][matches] = fp
|
||||
resistors.loc[matches, "Footprint"] = fp
|
||||
# resistors.drop("Package", inplace=True)
|
||||
resistors.dropna(inplace=True)
|
||||
|
||||
print(len(resistors))
|
||||
|
||||
# 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 = value.iloc[:,0].astype(float) * value.iloc[:,2].replace(["p", "n", "u", "m", ""], [1e-12, 1e-9, 1e-6, 1e-3, 1]).astype(float)
|
||||
capacitors.loc[:, "Value"] = value
|
||||
capacitors.loc[:, "Tolerance"] = capacitors["Description"].str.extract(r"(\d+)%").astype(float) / 100
|
||||
capacitors.loc[:, "Voltage"] = capacitors["Description"].str.extract(r"(\d+(\.\d+)?)V").astype(float).iloc[:,0]
|
||||
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)
|
||||
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"
|
||||
code_np0 = capacitors["Description"].str.contains(r"NP0")
|
||||
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:
|
||||
matches = matches | (capacitors["Package"] == n)
|
||||
matches = matches & (capacitors["Solder Joint"] == pins)
|
||||
capacitors["Footprint"][matches] = fp
|
||||
capacitors.loc[matches, "Footprint"] = fp
|
||||
# capacitors.drop("Package", inplace=True)
|
||||
capacitors.dropna(inplace=True)
|
||||
|
||||
|
||||
print(len(capacitors))
|
||||
pass
|
Loading…
Reference in New Issue
Block a user