Metadata-Version: 2.4
Name: abja_utils
Version: 1.0.0
Summary: A collection of reusable utilities for MIKE, FUNWAVE, and GIS workflows
Author-email: Abbas Jazaeri <abja@dhigroup.com>
License: Copyright (c) 2025 DHI Water and Environment Inc
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/abja-dhi/abja_utils
Project-URL: Repository, https://github.com/abja-dhi/abja_utils
Project-URL: Issues, https://github.com/abja-dhi/abja_utils/issues
Keywords: MIKE,mikeio,dfs2,FUNWAVE,GIS,bathymetry,geospatial,shapefile
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: matplotlib
Requires-Dist: cycler
Requires-Dist: mikeio
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: geopandas
Requires-Dist: shapely
Requires-Dist: pyproj
Requires-Dist: rasterio
Requires-Dist: alphashape
Provides-Extra: basemap
Requires-Dist: contextily; extra == "basemap"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: contextily; extra == "dev"
Dynamic: license-file

# abja_utils

A collection of reusable Python utilities for **MIKE**, **FUNWAVE-TVD**, and
**GIS** workflows — the tools I reach for across projects, packaged so they
install the same way on every machine.

## Installation

```cmd
pip install abja_utils
```

Optional extras:

```cmd
pip install "abja_utils[basemap]"   # web-tile basemaps for wind-vector plots
pip install "abja_utils[dev]"       # test dependencies
```

ArcPy-based helpers (`abja_utils.gis.arcpro`) require a licensed ArcGIS install;
see [ArcPy setup](#arcpy-optional) below.

## What's inside

| Subpackage | Highlights |
|------------|------------|
| `abja_utils.mike` | dfs2/mesh → shapefile, wind-vector plots, MIKE setup packaging |
| `abja_utils.gis` | concave hulls, bounding-box & snap rasters, NONNA-10 parsing, ArcPy bridge |
| `abja_utils.funwave` | FUNWAVE-TVD grid generation, depth-file ↔ GeoTIFF |
| `abja_utils.downloader` | *(work in progress)* Copernicus / HYCOM downloaders |
| top level | `use_style`, `Colors`, `subplots` — matplotlib styling helpers |

Subpackages import lazily, so `import abja_utils` stays fast; access them as
`abja_utils.mike`, `abja_utils.gis`, etc.

## Quick start

### MIKE — dfs2 to shapefile

Export one item at one timestep to a polygon shapefile (with `x_index` /
`y_index` columns). The item can be given by **name or index**, and the timestep
by **index or timestamp string**:

```python
import abja_utils as au

au.mike.dfs2_to_shapefile(
    "model.dfs2", "surface.shp",
    item="Surface elevation",     # or an integer index
    timestep="2018-01-01 01:00",  # or an integer index
)

# Or work with the GeoDataFrame directly:
gdf = au.mike.dfs2_to_geodataframe("model.dfs2", item=0, timestep=0)
```

Convert a mesh to element polygons, or plot true-north wind vectors:

```python
au.mike.mesh2poly("domain.mesh", "domain.shp")
au.mike.plot_wind_vectors("wind.dfs2", u_item=0, v_item=1, timestep=0)
```

Package a MIKE setup and every linked input into a self-contained zip:

```python
report = au.mike.package_mike_setup("model.m21fm")
print(report.summary())
```

### FUNWAVE — build a grid from a raster

```python
import abja_utils as au

result = au.funwave.generate_grid(
    xmin=-127.0, xmax=-126.0, ymin=48.1, ymax=48.5,
    dphi=30/3600, dtheta=30/3600,
    raster_path="dem.tif", out_txt_path="depth.txt",
    export_shapefile=True, export_clipped_raster=True,
)
au.funwave.txt2tif("depth.txt", "depth.tif", result["Mglob"], result["Nglob"],
                   result["dphi"], result["dtheta"])
```

### GIS

```python
import abja_utils as au

au.gis.bbox2shp(-127, -126, 48, 49, "bbox.shp", epsg=4326)
au.gis.make_snap_raster(-127, -126, 48, 49, epsg=4326, res=0.01,
                        output_fname="snap.tif")
hull = au.gis.concave_hull(points, alpha=2.0, plot=True)

from abja_utils.gis.nonna import parse_file
gdf = parse_file("nonna10.txt")
```

### Plotting style

Importing the package does **not** change your matplotlib configuration. Opt in
when you want the package's defaults (Times New Roman, inward ticks, a curated
colour cycle):

```python
import abja_utils as au
au.use_style()
fig, ax = au.subplots(figwidth=16, figheight=12)  # sizes in centimetres
ax.plot(x, y, color=au.Colors.blue2)
```

## ArcPy (optional)

`abja_utils.gis.arcpro` bridges to a licensed ArcGIS Pro install from a
standalone Python (matching major.minor version). Install the bridge with:

```python
from abja_utils.gis import install_arcpy
install_arcpy()   # Windows only
```

See [`src/abja_utils/data/README.md`](src/abja_utils/data/README.md) for details.

## Development

```cmd
pip install -e ".[dev]"
pytest
```

## License

MIT — see [LICENSE](LICENSE).
