Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/unitTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ jobs:

- name : Install Packages
run : |
pip install pytest pandas numpy seaborn
pip install scikit-learn scipy matplotlib
pip install -r requirements.txt

- name : Run unit tests
run : |
pytest Tests/test_TrajData.py
pytest Tests/test_Base.py
pytest Tests/test_ContourData.py
pytest Tests/test_AsymCalc.py
pytest Tests/test_Clustering.py
pytest MLexamples/Tests/test_Regression.py
pytest
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__pycache__/
*.py[cod]
*.egg-info/
.pytest_cache/
.venv/
.venv-test/
venv/
.ipynb_checkpoints/
*.out

# Generated by running the clustering tests/examples locally
Data/Clustering/
91 changes: 0 additions & 91 deletions AttoPhysics.pyproj

This file was deleted.

25 changes: 0 additions & 25 deletions MLexamples/Classification/MNIST/RunSGDClassifier.py

This file was deleted.

50 changes: 0 additions & 50 deletions MLexamples/MLexamples.pyproj

This file was deleted.

17 changes: 0 additions & 17 deletions MLexamples/Regression/IRIS/PredictIRIS.py

This file was deleted.

27 changes: 0 additions & 27 deletions Python.sln

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,24 @@
- Plotting algorithms
- ML learning tools
- Unit tests for modules

## Setup

```
pip install -r requirements.txt
```

## Tests

Run the full test suite with pytest from the repository root:

```
pytest
```

## Examples

`notebooks/examples.ipynb` consolidates the example scripts (clustering, trajectory
plotting, regression, IRIS, MNIST, ARC asymmetry, contour plotting) and calls the
underlying helper classes in `Source/` and `MLexamples/`. Some examples require
data files that aren't included in this repository — see the notes in each section.
48 changes: 24 additions & 24 deletions Source/Base/BaseDataHelper.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import string
from numpy import ndarray, void, loadtxt
from pandas import DataFrame
import os
from dataclasses import dataclass, field
from numpy import ndarray, loadtxt
from pandas import DataFrame


@dataclass(kw_only=True)
class BaseDataHelper:
"""For importing and manipulating file data"""
myDataFrame: DataFrame
myArray: ndarray

def __init__(self, _path: string, _fname: string):
self.path = _path
self.filename = _fname
path: str
filename: str
my_data_frame: DataFrame = field(init=False, default=None)
my_array: ndarray = field(init=False, default=None)

def CreateDataFrame(self):
df = DataFrame(self.myArray)
self.myDataFrame = df
def create_data_frame(self):
if self.my_array is None:
raise ValueError("my_array is empty - call load_to_array() first")
self.my_data_frame = DataFrame(self.my_array)

def GetDataFrame(self):
return self.myDataFrame
def get_data_frame(self):
return self.my_data_frame

def GetFilePath(self) -> string:
def get_file_path(self) -> str:
return self.path + self.filename

def LoadToArray(self) -> void:
cwd = os.getcwd()
filePath = BaseDataHelper.GetFilePath(self)
self.myArray = loadtxt(cwd + filePath)
def load_to_array(self) -> None:
file_path = os.path.normpath(os.getcwd() + self.get_file_path())
if not os.path.isfile(file_path):
raise FileNotFoundError(f"data file not found: {file_path}")
self.my_array = loadtxt(file_path)

def TruncateArray(self, size: int) -> void:
newArray = self.myArray[:size]
self.myArray = newArray
def truncate_array(self, size: int) -> None:
self.my_array = self.my_array[:size]

def GetArray(self) -> ndarray:
return self.myArray
def get_array(self) -> ndarray:
return self.my_array
19 changes: 10 additions & 9 deletions Source/Base/BasePlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, _helper: BaseDataHelper):
self.helper = _helper

def plotScatter(self, col1: string, col2: string, title="", fontsize=10, pointsize=0.001, save=False):
df = self.helper.GetDataFrame()
df = self.helper.get_data_frame()
dfOrbit = df[self.helper.orbit]
Xarray = np.asarray(df[col1])
Yarray = np.asarray(df[col2])
Expand All @@ -33,7 +33,7 @@ def plotScatter(self, col1: string, col2: string, title="", fontsize=10, pointsi
matplotlib.pyplot.close()

def plot2Scatter(self, col1: string, col2: string, col3: string, col4: string, title="", fontsize=10, pointsize=0.001, save=False):
df = self.helper.GetDataFrame()
df = self.helper.get_data_frame()
Xarray = np.asarray(df[col1])
Yarray = np.asarray(df[col2])
X2array = np.asarray(df[col3])
Expand All @@ -59,9 +59,9 @@ def PlotColourMesh(self, title=""):
'size': 10}
matplotlib.rc('font', **font) # increase all font size
fig, ax = plt.subplots(1, 1, figsize=(14, 8))
XRESI = self.helper.XRESI
YRESI = self.helper.YRESI
ZRESI = self.helper.ZRESI
XRESI = self.helper.x_resi
YRESI = self.helper.y_resi
ZRESI = self.helper.z_resi
_min = self.helper.min
_max = self.helper.max
ax.pcolormesh(XRESI, YRESI, ZRESI, norm=LogNorm(vmin=_min, vmax=_max),\
Expand All @@ -71,14 +71,15 @@ def PlotColourMesh(self, title=""):
plt.show()

def plotSeaborn(self, title: string = "", save: bool = False) -> np.void:
df = self.helper.GetDataFrame()
df = self.helper.get_data_frame()
sns.color_palette("pastel")
sns.pairplot(df, hue='orbit', kind="reg", plot_kws=dict(scatter_kws=dict(s=0.1)), height=1.5)
self.SaveOrShow(save, title)

def SaveOrShow(self, save: bool, title: string) -> np.void:
if save is True:
cwd = os.getcwd()
plt.savefig(cwd + self.helper.path + title + ".png")
else:
plt.show()
outputDir = cwd + self.helper.path
os.makedirs(outputDir, exist_ok=True)
plt.savefig(outputDir + title + ".png")
plt.show()
Loading
Loading