Commit 3cb40951 authored by Charleux Ludovic's avatar Charleux Ludovic 💬
Browse files

Various updates

parent 2f088c93
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -46,3 +46,6 @@ examples/batch.png
docs/source/examples/datasets/.DS_Store
docs/source/examples/.DS_Store

docs/source/examples/FusedQuartz_batch.csv

docs/source/examples/FusedQuartz_batch.toml
+12 −13
Original line number Diff line number Diff line
%% Cell type:markdown id:3ef34832-7e33-4e8f-8e63-5407a120bf7b tags:

# Basic postprocessing with IndenToolBox

In this example, we'll look at tests carried out on fused quartz samples and measure their modulus.

**Important**: run the `pre_processing.ipynb` file before.

%% Cell type:code id:404d4a5c-2c85-46d2-8740-4680eb7205e3 tags:

``` python
%matplotlib widget
import indentoolbox as itb
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

pd.options.display.float_format = "{:.5e}".format
```

%% Cell type:markdown id:ca08c0b8-f2c6-44ed-b8d6-cad0469fda3b tags:

## Setup

%% Cell type:code id:b4d55889-f973-4554-bd86-47355e301285 tags:

``` python
root_path = "./my_batch"
root_path = "./FusedQuartz_batch"
batch = itb.core.Batch.load(root_path)
batch
```

%% Cell type:markdown id:5005aeab-7544-434c-b4a2-e49ab78391d9 tags:

## First look at the data

%% Cell type:code id:1ad6290e-b6b3-4e9d-ae76-8ce307c46275 tags:

``` python
# THE TIP
batch.tip
```

%% Cell type:code id:d664aa2f-a27c-4b97-90fa-1718b50cae05 tags:

``` python
# TEST DATA
print(batch.tests[0].data)
```

%% Cell type:code id:de10382a-265f-4e02-a26f-74b4ddd49874 tags:

``` python
batch.collect_steps(0).data
```

%% Cell type:markdown id:88e3a978-f06b-44d1-a580-c93eb6ac8ef2 tags:

## Basic Plots

%% Cell type:code id:ad7e70c3-15dc-442e-8cd9-8ad09988dedd tags:

``` python
plot_reject = False
colors = "rgb"
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
tests = batch.tests
Ntests = len(tests)
for Nt in range(Ntests):
    test = tests[Nt]
    if plot_reject == False and test.reject == False:
        test_data = test.data
        test_structure = [step.kind() for step in test.steps]
        for step_id, step_data in test_data.groupby("step"):
            ax.plot(
                step_data.disp * 1.0e9,
                step_data.force * 1.0e6,
                "-",
                lw=1.0,
                color=colors[step_id%len(colors)],
            )


ax.grid()
ax.set_xlabel("Displacement, $h$ [nm]")
ax.set_ylabel("Force, $P$ [µN]")
#plt.savefig("experimental_batch.png")
plt.show()

print(test_structure)
```

%% Cell type:markdown id:d02ba248-ce66-4a13-b817-85ce677b674e tags:

## Post-processing

In this section, we post-process our tests to extract basic data from the various steps. Indentoolbox can be used to collectively process one step of data from all trials and export the result as a dataframe. This is a powerful feature for batch processing, as is often the case with indentation.

First, we focus on the parabolic loading step:
First, we focus on the parabolic loading step. Please note that:
- The method `collect_steps` allows us to collect every occurrence of the same step in every test.
- The method `parabolic_fit` performs a parabolic fit on every step.

%% Cell type:code id:a4e1546e-e9b3-4952-bcaa-c0cf275eef8f tags:

``` python
loading_data = batch.collect_steps(0).parabolic_fit(displim = 50.e-9, htrunc = batch.tip.htrunc)
loading_data.index = loading_data.index.droplevel(1)
loading_data.index = loading_data.index.droplevel(1) #
print(loading_data)
```

%% Cell type:markdown id:f443ece1-065c-490e-9abe-321dc44ce0ce tags:

We then turn our attention to the unloading step:

%% Cell type:code id:0113b01c-1a5e-4d68-a7a6-3f698db5b69e tags:

``` python
unloading_data = batch.collect_steps(2).unloading_fit()
unloading_data.index = unloading_data.index.droplevel(1)
print(unloading_data)
```

%% Cell type:markdown id:3884af20-da48-4c67-aec7-1fd9b947f9fc tags:

And we apply the method of Oliver and Pharr to deduce the indentation modulus and then the Young's modulus.

%% Cell type:code id:7db18f0c-9b18-433e-b09b-deab242e5011 tags:

``` python
OP = itb.processing.OliverPharr(data = unloading_data, tip = batch.tip)
print(OP)
```

%% Cell type:code id:c02a3325-e18f-472f-832d-5f5a1a52a505 tags:

``` python
nu_samp = 0.17
```

%% Cell type:code id:b9d437f3-16c9-41e8-871e-0a92df23b3a1 tags:

``` python
OP["Esamp"] = OP.Eeqsamp * (1. - nu_samp**2)
print(OP)
```

%% Cell type:markdown id:13520e87-2535-4d27-a0ea-70e8e80e77d2 tags:

## Reverse analysis

In this section, we use several inverse analysis algorithms to retrieve the mechanical properties of the material under study. As this material is fused quartz, these methods are unsuitable for crystalline metals. See it as a demonstration, but disregard the results.

%% Cell type:code id:ba1156d4-3c90-4cac-b0a4-b9e43d3e1b51 tags:

``` python
test_id = 0
C = loading_data.loc[test_id, "C"]
S = unloading_data.loc[test_id, "S"]
hm = unloading_data.loc[test_id, "hm"]
Pm = loading_data.loc[test_id, "Pm"]
hf = unloading_data.loc[test_id, "hf"]
E_ind = batch.tip.young_modulus
nu_ind = batch.tip.poisson_coefficient
Wrev = unloading_data.loc[test_id, "W"]
Wtot = loading_data.loc[test_id, "W"]
Wirr = Wtot + Wrev
Wfrac = Wirr/Wtot
#Wfrac = 0.9
```

%% Cell type:code id:8a0ac424-c1fe-45b2-bedd-7a872cbceca1 tags:

``` python
gian99 = pd.DataFrame(itb.processing.GIAN99(hm = hm, hf = hf, S = S, C = C, nu = nu_samp, E_ind = E_ind, nu_ind = nu_ind))
print(gian99)
```

%% Cell type:code id:6ffd3513-9752-46d8-9ff4-0ab71ae8ed7a tags:

``` python
dao01 = pd.DataFrame(itb.processing.DAO01(S=S,C=C,Pm=Pm,Wfrac=Wfrac,hm=hm,hf=hf))
print(dao01)
```

%% Cell type:code id:43652db4-1336-4171-85e7-02f872fa4e18 tags:

``` python
casals05 = pd.DataFrame(itb.processing.CASA05(hm=hm, hf=hf, Pm=Pm, S=S, C=C))
print(casals05)
```

%% Cell type:code id:09e5eeba-6f3d-4b50-a30a-b779964b1457 tags:

``` python
```

%% Cell type:code id:e78e926a-a5b7-4288-b152-47e3f3addff4 tags:

``` python
```
+10 −19
Original line number Diff line number Diff line
%% Cell type:markdown id:2fde9efa-f9a1-4b78-8f0b-2ce5c5acef11 tags:

# Basic preprocessing with IndenToolbox

This notebook walks through turning raw nanoindentation exports into a structured `batch` ready for analysis with IndenToolbox.
You will load raw files, define the indenter tip and test protocol, complete essential metadata, and export the result for downstream processing.

## What you’ll do:

- Select and parse raw test files (CLI or widget UI).
- Define the indenter tip and test protocol.
- Fill metadata: date, operators, sample, device.
- Build a Batch and export `my_batch.toml` and `my_batch.csv`.
- Build a Batch and export `FusedQuartz_batch.toml` and `FusedQuartz_batch.csv`.

## Notes:

- Example data targets Hysitron TI‑950 files; CSM is also supported.
- Make sure ipywidgets is enabled (`%matplotlib widget`) for the UI.
- If your acquisition differs, adjust protocol and file encoding accordingly.

Run the notebook top‑to‑bottom. At the file selection step, choose either the command‑line path list or the interactive widgets, then proceed to create and dump the batch.

%% Cell type:code id:e5b552b6-295c-408a-be5f-86e801de3275 tags:

``` python
%matplotlib widget
import indentoolbox as itb
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
import datetime
import os
```

%% Cell type:code id:0f666561-ac8c-4aba-a27d-c1c3c9839ec9 tags:

``` python
setup = {}
```

%% Cell type:markdown id:f6a6e8a6-d407-4a35-bfbf-c8e6324bd0f3 tags:

## Tip

An indentation tip must be defined to allow interpretation of the tests.

In our experiments, we performed nanoindentation using a Berkovich diamond tip. However, for post-processing and modeling purposes, we approximate the indenter geometry as a spherocone. This simplified geometry, defined by its half angle and truncated length, facilitates the interpretation of the mechanical response while retaining key features of the contact mechanics.

Have a look at the [documentation on step classes](https://indentoolbox.readthedocs.io/en/latest/reference.html#tip-classes).

%% Cell type:code id:76dad05d-d314-4cf1-9395-2e2d6705c595 tags:

``` python
setup["tip"] = itb.core.SpheroConicalTip(angle = 70.3,
                                         htrunc = 15.e-9,
                                         young_modulus=1141.0e9,
                                         poisson_coefficient=0.14)
```

%% Cell type:markdown id:33695d1b-df4f-4212-b2bd-b19934bbc91d tags:

## Test protocol

In IndenToolbox, a batch is made up of several tests, which are themselves made up of steps. The test protocol defines the structure of these steps. It defines their nature and sequence. All tests in the same batch share the same structure.

Have a look at the [documentation on step classes](https://indentoolbox.readthedocs.io/en/latest/reference.html#step-classes).

%% Cell type:code id:2a8476cc-e526-4ae9-a939-50744fcda3d1 tags:

``` python
#protocol = None # If left to None, the test protocol will be inferred by the parser.
protocol = 3 * [None] + ["ConicalLoadingStep", "Step", "UnloadingStep"] # Use your own protocol: None ignores a step and otherwise a class name is provided
protocol
```

%% Cell type:markdown id:9aaffc56-0e31-4b1a-b7b2-dbf37d4221a7 tags:

## Select test *txt* files

There are two possible options here: define file paths directly on the command line, or use the graphical interface.

### Option 1 : command line

%% Cell type:code id:bc62fe07-ea57-481b-bd42-aef2bb9cc676 tags:

``` python
folder = "datasets/Hysitron_TI950/2011-06-28_Hysitron_TI950_Fused_Quartz/"
pathes = [f for f in os.listdir(folder) if f.endswith(".txt")]
pathes = sorted([f for f in os.listdir(folder) if f.endswith(".txt")])
pathes
```

%% Cell type:code id:8e4b369a-8f03-4b56-9c0f-35be7cdb87e1 tags:

``` python
file_format = "hysitron nano"
encoding = "ISO-8859-1"

tests = []
for path in pathes:
    data = open(f"{folder}{pathes[0]}", "rb").read().decode(encoding)
    data = open(f"{folder}{path}", "rb").read().decode(encoding)
    test = itb.core.Test.from_txt(
                content=data, protocol=protocol, file_format=file_format)
    display(test.data)
    tests.append(test)
setup["tests"] = tests
tests
```

%% Cell type:markdown id:50670883-3c1f-4931-8e61-12c2c6696935 tags:

### Options 2 : graphical interface

%% Cell type:code id:406e9cd4-4c2d-48e5-9910-3c066cdec890 tags:

``` python
#itb.gui.file_processing_widgets(setup, protocol)
```

%% Cell type:code id:3751eeb2-054b-4df5-b774-6dfea343d227 tags:

``` python
setup
```

%% Cell type:markdown id:642aed09-0b57-4b9e-a036-65929f7f1d29 tags:

## Date

%% Cell type:code id:5d07226b-afc2-40df-865f-4e0a54a14705 tags:

``` python
#itb.gui.date_selection_widget(setup)
```

%% Cell type:markdown id:6df1cf29-0776-4c5e-af8f-593673a17acd tags:

## Operators

%% Cell type:code id:20226972-1708-4b61-92aa-a5ee9a926592 tags:

``` python
operators = [
    itb.core.Operator(name = "Ludovic Charleux", institute= "Institut de Physique de Rennes"),
    itb.core.Operator(name = "Mariette Nivard", institute= "Institut de Physique de Rennes")]
setup["operators"] = operators
operators
```

%% Cell type:markdown id:9e6c91e3-cd27-44e1-94be-33b46564b7ba tags:

## Sample

%% Cell type:code id:f936f70b-29bd-43c3-9ea1-845ae6e69a59 tags:

``` python
sample = itb.core.Sample(name = "Fused Quartz", provider = "Hysitron")
setup["sample"] = sample
sample
```

%% Cell type:markdown id:5c251b44-e017-4fa0-a0db-6ad756f1ec1a tags:

## Device

%% Cell type:code id:0bc66f4a-37c9-489a-b085-2083ceefa93c tags:

``` python
device = itb.core.Device(name = "TI-950", institute = "Institut de Physique de Rennes", compliance = 0., provider = "Hysitron")
setup["device"] = device
device
```

%% Cell type:code id:c875cbd0-185e-4a2d-8958-35d0da27b875 tags:

``` python
setup
```

%% Cell type:markdown id:337ca5d0-8118-409a-8bb5-e2b3617e44f4 tags:

## Batch creation and dumping

%% Cell type:code id:ea1f5e71-4384-46dd-9b6a-96685437e5c2 tags:

``` python
batch = itb.core.Batch(**setup)
batch
```

%% Cell type:code id:45e8462e-4884-46d3-b464-24e1ef3de382 tags:

``` python
batch.dump("my_batch")
```

%% Cell type:code id:d777ae7a-50d1-4009-8927-1b07423d4ea9 tags:

``` python
```

%% Cell type:code id:198e1a72-9e77-47a8-b3aa-cdc9a5744dd0 tags:

``` python
```

%% Cell type:code id:c1e97c86-abe6-46e5-9f6b-d0a836ffd0ba tags:

``` python
batch.dump("FusedQuartz_batch")
```