---
# System prepended metadata

title: Load LT mesh as numpy array
tags: [matplotlib, python, LightTools, numpy]

---

A helper function for reading the LT mesh

```
import numpy as np
import matplotlib.pyplot as plt
import cv2
import pandas as pd

def load_LT_mesh(mesh_path):
    # extract mesh dimension information
    with open(mesh_path, 'r') as f:
        mesh_dim_str = f.readlines()[2]
        mesh_dim_list = mesh_dim_str.split('\t')
    x_min = float(mesh_dim_list[3])
    x_max = float(mesh_dim_list[5])
    x_num = int(mesh_dim_list[1])    
    y_min = float(mesh_dim_list[4])
    y_max = float(mesh_dim_list[6])
    y_num = int(mesh_dim_list[2])
    # create meshgrid for plotting
    x = np.linspace(x_min, x_max, x_num)
    y = np.linspace(y_min, y_max, y_num)
    xx, yy = np.meshgrid(x, y)
    zz = np.flipud(np.loadtxt(mesh_path, skiprows=4, max_rows=y_num)) # flip the loaded mesh upside down for correct orientation
    return xx, yy, zz


xx, yy, zz = load_LT_mesh('.\\20230703\\Sheet_Mesh_30.1.txt')
plt.pcolormesh(xx, yy, zz)
```
### Loaded Mesh

![](https://hackmd.io/_uploads/ryUkqbeYn.png)

### LT Mesh (The regional analysis sub-mesh is ignored)

![](https://hackmd.io/_uploads/rJkh5Wxth.png)
