Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #45

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7491673
Merge pull request #20 from amepproject/release-1.0.x
hechtprojects Apr 22, 2024
3ac846e
Merge pull request #28 from amepproject/release-1.0.x
hechtprojects May 22, 2024
3bc6c3e
Added table of neccesary changes.
kai-luca Jun 17, 2024
a484259
WIP: gotta get that bus.
kai-luca Jun 17, 2024
2c822ef
Fixed .gitignore to exclude test artifacts.
kai-luca Jun 18, 2024
65c9256
All tests in base are refactored, work with new data and are cleaned up.
kai-luca Jun 18, 2024
6eca206
All tests in continuum were bad. I removed them and will think about …
kai-luca Jun 18, 2024
b1ebca8
Notes were updated to fit state.
kai-luca Jun 18, 2024
7715ecf
Done up until test_functions. Think abut tests there.
kai-luca Jun 18, 2024
703bab3
load and order tests do not clutter up directories anymore.
kai-luca Jun 19, 2024
01d5e91
load and particle methods are fine now.
kai-luca Jun 19, 2024
76fbed3
pbc tests run fine now.
kai-luca Jun 19, 2024
257b24e
reader tests work fine. They generate only the needed erroneous data.
kai-luca Jun 19, 2024
7c3ef5f
spatialcor tests work fine and are clean.
kai-luca Jun 19, 2024
a6ab31e
timecor tests work fine and are clean.
kai-luca Jun 19, 2024
61d3a30
timecor tests work fine and are clean
kai-luca Jun 19, 2024
e787a99
Added some evaluate tests. They reck up some time when testing. But t…
kai-luca Jun 28, 2024
f341a40
Fixed the zombie dependencies.
kai-luca Jul 8, 2024
a2e9197
Cleaned up test artifacts and added them to .gitignore.
kai-luca Jul 9, 2024
912fc41
Merge branch 'main' into refactor_tests
kai-luca Jul 9, 2024
57da1f3
Migrated numpy.trapz to numpy.trapezoid depending on numpy.__version__.
kai-luca Jul 9, 2024
e35d138
Merge remote-tracking branch 'origin/refactor_tests' into refactor_tests
kai-luca Jul 9, 2024
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ build/
test/data
test/.coverage
test/coverage.xml
examples/data/continuum/traj.h5amep
examples/data/continuum/#traj.h5amep
examples/data/continuum/##temp*
examples/data/trajs/
examples/data/lammps/traj.h5amep
examples/data/lammps/#traj.h5amep
examples/data/lammps/##temp*
examples/data/invalid
9 changes: 7 additions & 2 deletions amep/continuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# =============================================================================
# IMPORT MODULES
# =============================================================================
from packaging.version import Version
import numpy as np
import scipy.fft as fft

Expand Down Expand Up @@ -782,8 +783,12 @@ def cluster_properties(
# set all grid points outside the cluster to zero
y[labels != i] = 0
# integral
N = np.trapz(y, x=X, axis=1)
N = np.trapz(N, x=Y[:, 0])
if Version(np.__version__)<Version("2.0.0"):
N = np.trapz(y, x=X, axis=1)
N = np.trapz(N, x=Y[:, 0])
else:
N = np.trapezoid(y, x=X, axis=1)
N = np.trapezoid(N, x=Y[:, 0])
sizes.append(N)

# calculate the radius of gyration and linear extension
Expand Down
46 changes: 32 additions & 14 deletions amep/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# =============================================================================
# IMPORT MODULES
# =============================================================================
from packaging.version import Version
import warnings
import numpy as np

Expand Down Expand Up @@ -1840,16 +1841,22 @@ def __compute(self):
(self.__k0[i][0]*np.cos(self.__theta) +\
self.__k0[i][1]*np.sin(self.__theta)))

ck += np.trapz(integrand, x=self.__theta, axis=1)

if Version(np.__version__) < Version("2.0.0"):
ck += np.trapz(integrand, x=self.__theta, axis=1)
else:
ck += np.trapezoid(integrand, x=self.__theta, axis=1)

ck = np.abs(ck/len(self.__k0))

# normalization
norm = np.trapz(self.__grt, x=self.__theta, axis=1)
if Version(np.__version__) < Version("2.0.0"):
norm = np.trapz(self.__grt, x=self.__theta, axis=1)
else:
norm = np.trapezoid(self.__grt, x=self.__theta, axis=1)

return ck/norm


def __getk(self):
r'''
Calculates the k vectors corresponding to the first peaks of
Expand Down Expand Up @@ -3191,15 +3198,26 @@ def __init__(
if self.__xmax is None:
if self.__use_density:
# integrated density
val_total_x = np.trapz(
self.__traj[-1].data(self.__ftype),
x = self.__traj[-1].grid[0],
axis=1
)
val_total = np.trapz(
val_total_x,
x = self.__traj[-1].grid[1][:, 0]
)
if Version(np.__version) < Version("2.0.0"):
val_total_x = np.trapz(
self.__traj[-1].data(self.__ftype),
x=self.__traj[-1].grid[0],
axis=1
)
val_total = np.trapz(
val_total_x,
x=self.__traj[-1].grid[1][:, 0]
)
else:
val_total_x = np.trapezoid(
self.__traj[-1].data(self.__ftype),
x=self.__traj[-1].grid[0],
axis=1
)
val_total = np.trapezoid(
val_total_x,
x=self.__traj[-1].grid[1][:, 0]
)
self.__xmax = val_total
else:
# total number of grid points
Expand Down
18 changes: 14 additions & 4 deletions amep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# =============================================================================
import os
import time
from packaging.version import Version

import numpy as np

Expand Down Expand Up @@ -1188,10 +1189,14 @@ def sq_from_gr(
'''
if twod:
ydata = ((gr - 1) * r).reshape(-1, 1) * special.jv(0, r.reshape(-1, 1) * q.reshape(1, -1))
return np.trapz(x=r, y=ydata, axis=0) * (2 * np.pi * rho) + 1
if Version(np.__version__) < Version("2.0.0"):
return np.trapz(x=r, y=ydata, axis=0) * (2 * np.pi * rho) + 1
return np.trapezoid(x=r, y=ydata, axis=0) * (2 * np.pi * rho) + 1
else:
ydata = ((gr - 1) * r).reshape(-1, 1) * np.sin(r.reshape(-1, 1) * q.reshape(1, -1))
return np.trapz(x=r, y=ydata, axis=0) * (4 * np.pi * rho / q) + 1
if Version(np.__version__) < Version("2.0.0"):
return np.trapz(x=r, y=ydata, axis=0) * (4 * np.pi * rho / q) + 1
return np.trapezoid(x=r, y=ydata, axis=0) * (4 * np.pi * rho / q) + 1


def sq_from_sf2d(
Expand Down Expand Up @@ -1273,7 +1278,10 @@ def msd_from_vacf(vacf, times):
Time values as 1D array.

'''
msd = 2*np.array([np.trapz((times[i]-times[:i+1])*vacf[:i+1], x=times[:i+1]) for i in range(len(times))])
if Version(np.__version__) < Version("2.0.0"):
msd = 2*np.array([np.trapz((times[i]-times[:i+1])*vacf[:i+1], x=times[:i+1]) for i in range(len(times))])
else:
msd = 2*np.array([np.trapezoid((times[i]-times[:i+1])*vacf[:i+1], x=times[:i+1]) for i in range(len(times))])
return msd, times


Expand Down Expand Up @@ -1385,7 +1393,9 @@ def domain_length(
s_fac = s_fac[q<=qmax]
q = q[q<=qmax]

return 2*np.pi*(np.trapz(s_fac, x=q)/np.trapz(s_fac*q, x=q))
if Version(np.__version__) < Version("2.0.0"):
return 2*np.pi*(np.trapz(s_fac, x=q)/np.trapz(s_fac*q, x=q))
return 2*np.pi*(np.trapezoid(s_fac, x=q)/np.trapezoid(s_fac*q, x=q))


# =============================================================================
Expand Down
Binary file modified examples/data/continuum.h5amep
Binary file not shown.
Binary file modified examples/data/lammps.h5amep
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [
"h5py >= 3.7.0",
"matplotlib >= 3.6.2",
"numba >= 0.56.4",
"numpy >= 1.21.6",
"numpy >= 1.26.6",
"scipy >= 1.10.0",
"scikit-image >= 0.20.0",
"tqdm >= 4.65.0"
Expand Down
Loading
Loading