Metadata-Version: 2.4
Name: imlresi
Version: 0.0.46
Summary: Tools for dealing with IML-Resi PowerDrill data.
Author-email: Jonathan Harrington <jh@aliente.ch>
License: MIT
Project-URL: Homepage, https://github.com/hammockman/imlresi-pypi
Project-URL: Issue Tracker, https://github.com/hammockman/imlresi-pypi/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ujson
Requires-Dist: requests
Requires-Dist: certifi
Requires-Dist: loguru
Requires-Dist: numpy<2.0,>1.24.4
Requires-Dist: pandas
Requires-Dist: rdata
Requires-Dist: duckdb
Provides-Extra: delta
Requires-Dist: deltalake; extra == "delta"
Requires-Dist: pyarrow; extra == "delta"
Provides-Extra: spark
Requires-Dist: pyspark; extra == "spark"
Requires-Dist: delta-spark; extra == "spark"
Provides-Extra: plot
Requires-Dist: matplotlib; extra == "plot"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: jsondiff; extra == "test"
Requires-Dist: deltalake; extra == "test"
Requires-Dist: pyarrow; extra == "test"
Dynamic: license-file

# imlresi
Tools for dealing with [IML-Resi PowerDrill](https://www.iml-service.com/product/iml-powerdrill/) data using python.

**THIS PACKAGE IS UNOFFICAL AND HAS BEEN DEVELOPED INDEPENDENT OF IML**

Current limitations:

1. Focus is on actual measurements made by the tool rather than meta-info.
1. Poor support for data generated in PD-Tools (e.g. "assessments").


## Install

https://pypi.org/project/imlresi/

```sh
pip install imlresi
```

Optional extras:

| extra | for |
|---|---|
| `imlresi[delta]` | Delta Lake export with the pure-Python delta-rs engine |
| `imlresi[spark]` | Delta Lake export through PySpark (e.g. Microsoft Fabric notebooks) |
| `imlresi[plot]` | `Trace.plot()` |
| `imlresi[test]` | running the test suite |


## Use

### Traces

`Trace` reads a single measurement in any of IML's formats: binary `.rgp`
(firmware up to 1.32), JSON `.rgp` (later firmware), `.pdc` (IML's iPad
app) and the two PD-Tools text exports.

```python
from imlresi import Trace

tr = Trace()
tr.read('trace.rgp')
tr.drill, tr.feed            # drill and feed amplitude profiles
tr.get_drilltime()           # instrument clock time
tr.get_latlon()              # from a .pdc location stamp
tr.to_json()                 # as IML's JSON trace format
tr.hash()                    # md5 of to_json(), e.g. as a database key
```

`Trace.process_using_resiapi(uri)` sends the trace to a Resi API server and
keeps the result, which is then available as e.g. `tr.get_ubdia()`.

### .Resi files

A `.Resi` file is the project file of the FWPA web app: an R list saved with
`saveRDS()`, holding a summary table (`df`) plus the traces and results for
each measurement.

```python
from imlresi import ResiResultSet, save_traces_to_dotresi, change_instrument_id

rs = ResiResultSet('project.Resi')
for r in rs:
    r.FileName, r.TreeID, r.DOB, r.drill
    r.recompute_den_trace()  # recompute the density profile

rs.to_dotresi('copy.Resi')

# build a .Resi file from raw traces, e.g. to upload to the web app
save_traces_to_dotresi([tr], 'new.Resi')

change_instrument_id('project.Resi', 'PD500-0755', output_filepath='fixed.Resi')
```

The same conversion from the command line:

```sh
traces2resi *.rgp -o new.Resi
```

### Databases

```python
rs.to_duckdb('resi.duckdb')                      # traces, results, rings, boards tables
rs = ResiResultSet.from_duckdb('resi.duckdb')

rs.to_deltalake('Tables/resi', mode='merge')     # needs imlresi[delta] or imlresi[spark]
```

`to_deltalake` uses PySpark when a Spark session is active and delta-rs
otherwise. Merging never replaces an existing table; only `mode='overwrite'`
does.


## Units

FeedSpeed is stored in mm/min in `.Resi` files, DuckDB and Delta tables, as
the web app does. Traces report it in cm/min (`Trace.get_feedspeed()`). See
[CHANGELOG.md](CHANGELOG.md) about data written by 0.0.45 and earlier.


## Development

```sh
pip install -e '.[test,spark]'
pytest
```

The Spark tests need a JDK and are skipped without PySpark.
