Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jakep72 committed Jan 11, 2024
1 parent d8a0cee commit 8cafcd3
Show file tree
Hide file tree
Showing 22 changed files with 485 additions and 48 deletions.
62 changes: 18 additions & 44 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,24 @@ name: Publish to PyPI
on: push

jobs:
build:
name: Build distribution 📦
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/<acoustipy> # Replace <package-name> with your PyPI project name
permissions:
username: __token__
password: ${{ secrets.PYPI_TOKEN }}

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ instance/
# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/
Expand Down Expand Up @@ -127,5 +125,3 @@ dmypy.json

# Pyre type checker
.pyre/

docs/
2 changes: 2 additions & 0 deletions docs/AcoustiBase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# AcoustiBase
::: src.acoustipy.Database
2 changes: 2 additions & 0 deletions docs/AcousticID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# AcousticID
::: src.acoustipy.Params
3 changes: 3 additions & 0 deletions docs/AcousticTMM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AcousticTMM
::: src.acoustipy.TMM
handler: python
48 changes: 48 additions & 0 deletions docs/Examples/Hybrid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Hybrid Characterization
Use a hybrid characterization method to identify parameters of the Johnson-Champoux-Allard model given data obtained from an impedance tube.

```python
from acoustipy import AcousticTMM, AcousticID

# Create an AcousticTMM object to generate toy impedance tube data
structure = AcousticTMM(incidence='Normal',air_temperature = 20)

# Define the JCA and air gap material parameters for the toy data
layer1 = structure.Add_JCA_Layer(30, 46182,.917,2.1,83,128)
air = structure.Add_Air_Layer(thickness = 100)

# Generate rigid backed reflection data and save to a csv file
s1 = structure.assemble_structure(layer1)
A1 = structure.reflection(s1)
structure.to_csv('no_gap',A1)

# Generate air backed reflection data and save to a csv file
s2 = structure.assemble_structure(layer1,air)
A2 = structure.reflection(s2)
structure.to_csv('gap',A2)

# Create an AcousticID object, specifying to mount types, data files, and data types
inv = AcousticID(mount_type='Dual',no_gap_file="no_gap.csv",gap_file = "gap.csv",input_type='reflection',air_temperature=20)

# Call the Hybrid method to find the tortuosity, viscous, and thermal characteristic lengths of the material
res = inv.Hybrid(30,.917,air_gap=95,uncertainty = .15)

# print the identified parameters
print(res)

# Plot the absorption curves using the actual parameters vs those identified from the Indirect method
inv.plot_comparison(res)

res >>> {'thickness': 29.982,
'flow resistivity': 46209.81,
'porosity': 0.918,
'tortuosity': 2.103,
'viscous characteristic length': 83.0,
'thermal characteristic length': 128.0,
'air gap': 100.0,
'error': 1.3018228618069009e-17}
```

<br></br>

![](../assets/ex_material_identification_hybrid.png)
48 changes: 48 additions & 0 deletions docs/Examples/Indirect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Indirect Characterization
Use an indirect characterization method to identify parameters of the Johnson-Champaux-Allard model given data obtained from an impedance tube.

```python
from acoustipy import AcousticTMM, AcousticID

# Create an AcousticTMM object to generate toy impedance tube data
structure = AcousticTMM(incidence='Normal',air_temperature = 20)

# Define the JCA and air gap material parameters for the toy data
layer1 = structure.Add_JCA_Layer(30, 46182,.917,2.1,83,128)
air = structure.Add_Air_Layer(thickness = 100)

# Generate rigid backed reflection data and save to a csv file
s1 = structure.assemble_structure(layer1)
A1 = structure.reflection(s1)
structure.to_csv('no_gap',A1)

# Generate air backed reflection data and save to a csv file
s2 = structure.assemble_structure(layer1,air)
A2 = structure.reflection(s2)
structure.to_csv('gap',A2)

# Create an AcousticID object, specifying to mount types, data files, and data types
inv = AcousticID(mount_type='Dual',no_gap_file="no_gap.csv",gap_file = "gap.csv",air_temperature=20,input_type='reflection')

# Call the Indirect method to find the flow resistivity, tortuosity, and viscous, and thermal characteristic lengths of the material
res = inv.Indirect(30,.917,air_gap=100)

# Plot the absorption curves using the actual parameters vs those identified from the Indirect method
inv.plot_comparison(res)

# print the identified parameters
print(res)

res >> {'thickness': 30,
'flow resistivity': 46182.79193470273,
'porosity': 0.9326784023844896,
'tortuosity': 2.1373594528548225,
'viscous characteristic length': 83.16500367154856,
'thermal characteristic length': 115.12539138619321,
'air gap': 100}

```

<br></br>

![](../assets/ex_material_identification_indirect.png)
45 changes: 45 additions & 0 deletions docs/Examples/Inverse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Inverse JCA Characterization
Use an inverse characterization method to identify parameters of the Johnson-Champaux-Allard model given data obtained from an impedance tube.

```python
from acoustipy import acousticTMM, AcousticID

# Create an AcousticTMM object to generate toy impedance tube data
structure = acousticTMM(incidence='Normal',air_temperature = 20)

# Define the JCA and air gap material parameters for the toy data
layer1 = structure.Add_JCA_Layer(thickness = 30, flow_resistivity = 46879, porosity = .93, tortuosity = 1.7, viscous_characteristic_length = 80, thermal_characteristic_length = 105)
air = structure.Add_Air_Layer(thickness = 375)

# Generate rigid backed absorption data and save to a csv file
s1 = structure.assemble_structure(layer1)
A1 = structure.absorption(s1)
structure.to_csv('no_gap',A1)

# Generate air backed absorption data and save to a csv file
s2 = structure.assemble_structure(layer1,air)
A2 = structure.absorption(s2)
structure.to_csv('gap',A2)

# Create an AcousticID object, specifying to mount types, data files, and data types
inv = AcousticID(mount_type='Dual',no_gap_file="no_gap.csv", gap_file = 'gap.csv',air_temperature=20,input_type='absorption')

# Call the Inverse method to find the tortuosity, viscous, and thermal characteristic lengths of the material
res = inv.Inverse(30, 47000,.926,air_gap=375,uncertainty=.2,verbose=True)

# Display summary statistics about the optimization
stats = inv.stats(res)
print(stats)

# Plot the results of the found parameters compared to the toy input data
inv.plot_comparison(res)

# Save the optimization results to a csv
inv.to_csv("params.csv",res)

stats = {'slope': 1.000037058594857, 'intercept': 9.276088883464206e-05, 'r_value': 0.9999999674493408, 'p_value': 0.0, 'std_err': 8.732362148426126e-06}
```

<br></br>

![](../assets/ex_material_identification_inverse.png)
69 changes: 69 additions & 0 deletions docs/Examples/impedance_tube.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Using impedance tube data
Estimate the diffuse sound field absorption coefficients of a structure
using the normal incidence reflection coefficients obtained via impedance
tube.

```python
from acoustipy import AcousticTMM

# Generate synthetic "impedance tube" data
structure = AcousticTMM(incidence='Normal', air_temperature = 20)

# Define the JCA and air gap material parameters for the synthetic data
layer1 = structure.Add_JCA_Layer(25.4, 60000, .91, 1.3, 85, 110)
air = structure.Add_Air_Layer(thickness = 100)

# Generate rigid backed reflection data and save to a csv file
s1 = structure.assemble_structure(layer1)
r1 = structure.reflection(s1)
structure.to_csv('no_gap_tube',r1)

# Generate air backed absorption data and save to a csv file
s2 = structure.assemble_structure(layer1,air)
r2 = structure.reflection(s2)
structure.to_csv('gap_tube',r2)

# Create a new structure to estimate the diffuse field absorption coefficients
estimated_structure = AcousticTMM(incidence='Diffuse', air_temperature = 20)

# Load the synthetic impedance tube data and define a new air layer
estimated_layer = estimated_structure.Add_Layer_From_Tube(no_gap_file = 'no_gap_tube.csv', gap_file='gap_tube.csv', sample_thickness=25.4, air_gap_thickness=100)
air2 = estimated_structure.Add_Air_Layer(thickness = 400)

# Generate narrow band absorption data for the new structure
s3 = estimated_structure.assemble_structure(estimated_layer,air2)
absorption = structure.absorption(s3)

# Calculate the 3rd octave bands absorption coefficients
bands = structure.octave_bands(absorption)

# Calculate the four frequency average absorption
ffa_estimate = structure.FFA(bands)
print(ffa_estimate)

>>> 0.717

# Compare the estimated FFA to that calculated from the original layer data
air3 = structure.Add_Air_Layer(thickness = 400)
s4 = structure.assemble_structure(layer1,air3)
abs1 = structure.absorption(s4)
bands1 = structure.octave_bands(abs1)
ffa_original = structure.FFA(bands1)
print(ffa_original)

>>> 0.717
```














26 changes: 26 additions & 0 deletions docs/Examples/layer_to_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Saving layers to a database
Save the parameters of individual layers to a built-in SQLite database.

```python
from acoustipy import AcousticTMM, AcoustiBase


structure = AcousticTMM(incidence='Normal',air_temperature = 20)

# For each Add_XXX_Layer method, enable the save_layer parameter and give it a unique layer name
db = structure.Add_DB_Layer(25.4, 50000,save_layer=True,layer_name='test_DB')
dbm = structure.Add_DBM_Layer(25.4, 50000,save_layer=True,layer_name='test_DBM')
jca = structure.Add_JCA_Layer(25.4, 50000,.90,1.2,80,110,save_layer=True,layer_name='test_JCA')
jcal = structure.Add_JCAL_Layer(25.4, 50000,.90,1.2,80,110,50,save_layer=True,layer_name='test_JCAL')
jcapl = structure.Add_JCAPL_Layer(25.4, 50000, .90, 1.2, 80, 110, 50, 70, 65,save_layer=True,layer_name='test_JCAPL')
horoshenkov = structure.Add_Horoshenkov_Layer(40, .90, 147, .325, save_layer=True, layer_name='test_horoshenkov')
biot_limp = structure.Add_Biot_Limp_Layer('JCA',25.4, 50000,200, .90, 1.2, 80, 110,save_layer=True,layer_name='test_biot_limp')
biot_rigid = structure.Add_Biot_Rigid_Layer('JCA',25.4, 50000,200, .90, 1.2, 80, 110,save_layer=True,layer_name='test2_biot_rigid')
screen = structure.Add_Resistive_Screen(2.54, 50000, .90,save_layer=True,layer_name='test_screen')
maa = structure.Add_MAA_MPP_Layer(2.54, .5, 1,save_layer=True,layer_name='test_maa_mpp')
ef_mpp = structure.Add_MPP_EF_Layer(2.54, .5, 1,save_layer=True,layer_name='test_ef_mpp')

# Pull the layer information from the database and save to a .csv file
s = AcoustiBase()
s.summarize_layers()
```
32 changes: 32 additions & 0 deletions docs/Examples/layers_from_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Load layers from a database
Load the previously saved layers from the database and calculate the transmission loss
of one of the layers.

```python
from acoustipy import AcousticTMM

structure = AcousticTMM(incidence='Normal',air_temperature = 20)

# Add layers from the database
db = structure.Add_Layer_From_Database('test_DB')
dbm = structure.Add_Layer_From_Database('test_DBM')
jca = structure.Add_Layer_From_Database('test_JCA')
jcal = structure.Add_Layer_From_Database('test_JCAL')
jcapl = structure.Add_Layer_From_Database('test_JCAPL')
horoshenkov = structure.Add_Layer_From_Database('test_horoshenkov')
biot_limp = structure.Add_Layer_From_Database('test_biot_limp')
biot_rigid = structure.Add_Layer_From_Database('test2_biot_rigid')
screen = structure.Add_Layer_From_Database('test_screen')
maa = structure.Add_Layer_From_Database('test_maa_mpp')
ef_mpp = structure.Add_Layer_From_Database('test_ef_mpp')

# Calculate th narrow band transmission coefficients for the JCA layer
s = structure.assemble_structure(jca)
tl = structure.transmission_loss(s)

# Plot the transmission coefficients
structure.plot_curve([tl])
```
<br>

![](../assets/ex_layers_from_database.png)
Loading

0 comments on commit 8cafcd3

Please sign in to comment.