Skip to content

Commit

Permalink
[python] Add material excel parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Aug 31, 2024
1 parent b2ac93c commit c97d43d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 8 deletions.
4 changes: 2 additions & 2 deletions data/driver.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Supravox 285 GMF,Woofer,11.0,8,10.55,,0.0197,6.5,0.345,8.86,0.33,,0.04426,,,,3.4
Supravox 400 GMF,Woofer,16.0,8,18.2908,0.00047,0.0621385,6.5,0.1432,7.5492,0.14,,0.0855,,,,,,19.0,4000.0,18.87,120,240,98.5,2.83,490.0,,,,,
Supravox 400-2000 EXC,Woofer,16.0,8,17.53,0.0005,0.066,6.5,0.184,9.1932,0.1805,,0.0855,,,,,,23.0,4000.0,22,120,240,98.16,2.83,681.0,,,,,10.7
TAD TD-2002,Horn,1.0,8,,,,,,,,,,,,,,,450.0,27000.0,,20,40,111.0,2.83,,,,,,6.9
TAD TL-1601b,Woofer,16.0,8,20.5,0.000276,0.117,6.6,0.32,6.8,0.31,0.020,0.0881,,,,,,28.0,2000.0,28.0,200,500,97.5,2.83,304.0,,,,,13.0
TAD TL-1801,Woofer,18.0,8,21.0,0.000237,0.158,6.6,0.39,7.9,0.37,0.022,0.122,,,,,,26.0,2000.0,26.0,200,800,96.5,2.83,500.0,,,,,12.6
TAD TL-1601b,Woofer,16.0,8,20.5,0.000276,0.117,6.6,0.32,6.8,0.31,0.020,0.0881,,,,8.0,18.0,28.0,2000.0,28.0,200,500,97.5,2.83,304.0,,,,,13.0
TAD TL-1801,Woofer,18.0,8,21.0,0.000237,0.158,6.6,0.39,7.9,0.37,0.022,0.122,,,,7.5,20.0,26.0,2000.0,26.0,200,800,96.5,2.83,500.0,,,,,12.6
Volt Loudspeakers VM527,Midrange,2.0,8,,,,5.5,,,,,0.002827,,,40.0,1.0,1.0,500.0,4500.0,502.0,75,150,91.0,2.83,,,,,,
Volt Loudspeakers VM752,Midrange,3.0,8,9.3,0.0004,0.004,6.3,0.81,9.53,0.75,,0.0057,,,89.5,1.0,2.0,500.0,4000.0,400.0,100,200,94.0,2.83,0.16,,,,,
Volt Loudspeakers RV2501,Woofer,10.0,8,13.9,0.0003,0.05522,5.3,0.37,3.19,0.33,,0.0330,,,,5.0,10.0,30.0,800.0,39.0,250,500,91.0,2.83,47.03,,35,,80.0,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = [
"scipy>=1.14.0",
"sympy>=1.13.1",
"tqdm>=4.66.5",
"xlrd",
]

[project.urls]
Expand Down
2 changes: 2 additions & 0 deletions src/python/akustik/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from akustik.absorber.cli import absorber
from akustik.anc.cli import anc
from akustik.diffusor.cli import diffusor
from akustik.material.cli import material
from akustik.room.cli import room
from akustik.speaker.cli import speaker
from akustik.wave.cli import wave
Expand All @@ -19,6 +20,7 @@ def main(ctx, verbose):
main.add_command(absorber)
main.add_command(anc)
main.add_command(diffusor)
main.add_command(material)
main.add_command(room)
main.add_command(speaker)
main.add_command(wave)
Empty file.
13 changes: 13 additions & 0 deletions src/python/akustik/material/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import click


@click.group(help="Materials.")
def material():
pass


@material.command(help="Load excel spreadsheet.")
@click.argument('filename', nargs=1, type=click.Path(exists=True))
def load(filename):
from akustik.material.load import main
main(filename)
77 changes: 77 additions & 0 deletions src/python/akustik/material/load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import numpy as np
import pandas as pd


def load_materials(file) -> pd.DataFrame:
"""Loads the materials from the Excel spreadsheet as a pandas dataframe.
Only the octaves (125, 250, 500, 1000, 2000, 4000) are loaded. Rows that
do not contain coefficients for these frequencies are dropped.
The Room Acoustics Absorption Coefficient Database:
https://www.ptb.de/cms/ptb/fachabteilungen/abt1/fb-16/ag-163/absorption-coefficient-database.html
"""
bands = [63, 125, 250, 500, 1000, 2000, 4000]

character_df = pd.read_excel(
file,
sheet_name=["selection_table"],
skiprows=3,
nrows=5,
usecols=[33, 39],
index_col=1,
)["selection_table"]

def to_character(id): return character_df.iloc[int(id) - 1][
"character of absorption (column AQ + AR)"
]

criteria_df = pd.read_excel(
file,
sheet_name=["selection_table"],
skiprows=2,
nrows=12,
usecols=[41, 48],
index_col=1,
)["selection_table"]

def to_criteria(id): return criteria_df.iloc[int(id) - 1][
"material criteria: (column AS + AT)"
]

df = pd.read_excel(
file,
sheet_name=["selection_table"],
skiprows=19,
nrows=2574,
index_col=0,
dtype={"No.": np.int32},
)["selection_table"]

for freq in bands:
df = df[pd.to_numeric(df[freq], errors="coerce").notnull()]
df[freq] = df[freq].astype(np.float64)

material_col = "material criteria"
df = df.dropna(subset=[material_col])
df["criteria"] = df[material_col].apply(
to_criteria).astype(dtype="category")

character_col = "character of absorption"
df = df[df[character_col] != 12.0]
df = df.dropna(subset=[character_col])
df["character"] = df[character_col].apply(
to_character).astype(dtype="category")

# df["octave_mean"] = df[bands].mean(axis=1)
df["max"] = df[bands].max(axis=1)
df = df[df["max"] <= 1.0]

return df[["description", "criteria", "character"] + bands]


def main(filename):
materials: pd.DataFrame = load_materials(filename)
materials["description"] = materials["description"].str.replace("\n", " ")
# materials = materials[materials["description"].str.contains("floor")]
materials.to_csv("materials.csv")
print(materials.info(verbose=True, memory_usage=True))
12 changes: 6 additions & 6 deletions src/python/akustik/speaker/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main(driver_db, SPL_target):
df = pd.read_csv(driver_db)
drivers = [
# "Alcone AC 15",
"Alcone AC 8 HE",
# "Alcone AC 8 HE",
# "AMT U60W1.1-C",
# "AMT U160W1.1-R",
# "Dayton Audio AMTHR-4",
Expand All @@ -98,9 +98,9 @@ def main(driver_db, SPL_target):
# "Dayton Audio RSS315HFA-8",
# "Dayton Audio RSS315HF-4",
# "Dayton Audio RSS315HO-4",
# "Dayton Audio RSS390HF-4",
# "Dayton Audio RSS390HO-4",
# "Dayton Audio RSS460HO-4",
"Dayton Audio RSS390HF-4",
"Dayton Audio RSS390HO-4",
"Dayton Audio RSS460HO-4",
# "Radian 950NeoPB-8",
# "ScanSpeak Discovery 15M/4624G00",
# "ScanSpeak Discovery 30W/4558T00",
Expand All @@ -110,8 +110,8 @@ def main(driver_db, SPL_target):
# "Supravox 400 GMF",
# "Supravox 400-2000 EXC",
# "TAD TD-2002",
# "TAD TL-1601b",
# "TAD TL-1801",
"TAD TL-1601b",
"TAD TL-1801",
# "Volt Loudspeakers VM527",
# "Volt Loudspeakers VM752",
# "Volt Loudspeakers RV2501",
Expand Down

0 comments on commit c97d43d

Please sign in to comment.