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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Random editor stuff
*~
*.swp

# Python byte-compiled / optimized / DLL files
*.pyc
Expand All @@ -9,11 +10,14 @@ src/Python/dist/*
src/Python/tests/test_chunk*
src/Python/wcon.egg*
.pypirc
openworm/

#Matlab
*.asv

# Scala
src/scala/target/*
src/scala/**/target/*

/src/Python/example_saved_file.WCON
/src/Python/wcon/wcon_schema.json
17 changes: 17 additions & 0 deletions src/Python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pandas = "*"
six = "*"
numpy = "*"
psutil = "*"
jsonschema = "*"
scipy = "*"

[dev-packages]

[requires]
python_version = "3.9"
395 changes: 395 additions & 0 deletions src/Python/Pipfile.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/Python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "wcon"
version = "1.1.0"
authors = [
{ name="Kerr, R; Brown, A; Currie, M; OpenWorm", email="ichoran@gmail.com" },
]
description = "Worm tracker Commons Object Notation"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Bio-Informatics',
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
license = "MIT"

[project.urls]
Homepage = "https://github.com/openworm/tracker-commons"
Issues = "https://github.com/openworm/tracker-commons/issues"
6 changes: 6 additions & 0 deletions src/Python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
six
jsonschema
numpy
pandas
psutil
scipy
Binary file removed src/Python/tests/.bbb.wcon.swp
Binary file not shown.
3 changes: 2 additions & 1 deletion src/Python/tests/diagnostic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import time
import pprint as pp

sys.path.append('..')
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
from wcon import WCONWorms, MeasurementUnit
from wcon.measurement_unit import MeasurementUnitAtom

Expand Down
17 changes: 10 additions & 7 deletions src/Python/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import shutil
from scipy.constants import pi

sys.path.append('..')
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
from wcon import WCONWorms, MeasurementUnit
from wcon.measurement_unit import MeasurementUnitAtom


def setUpModule():
# If the wcon module is installed via pip, wcon_schema.json is included
# in the proper place. In the git repo it is not, however, so to test
# we must copy it over temporarily, then remove it once tests are done.
shutil.copyfile('../../../wcon_schema.json', '../wcon/wcon_schema.json')
# we must copy it over temporarily, then remove it once tests are done.
shutil.copyfile(os.path.join(dir_path, '..', '..', '..', 'wcon_schema.json'), os.path.join(dir_path, '..', 'wcon', 'wcon_schema.json'))


def tearDownModule():
os.remove('../wcon/wcon_schema.json')
os.remove(os.path.join(dir_path, '..', 'wcon', 'wcon_schema.json'))


def flatten(list_of_lists):
Expand Down Expand Up @@ -192,7 +192,9 @@ def _validate_from_schema(self, wcon_string):
except AttributeError:
# Only load _wcon_schema if this method gets called. Once
# it's loaded, though, persist it in memory and don't lose it
with open("../../../wcon_schema.json", "r") as wcon_schema_file:
wcon_schema_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'wcon_schema.json'))
with open(wcon_schema_path, "r") as wcon_schema_file:
self._wcon_schema = json.loads(wcon_schema_file.read())

# Now that the schema has been loaded, we can try again
Expand All @@ -204,7 +206,8 @@ def test_schema(self):
self._validate_from_schema(basic_wcon)

def test_equality_operator(self):
JSON_path = '../../../tests/minimax.wcon'
JSON_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'tests', 'minimax.wcon'))
w2 = WCONWorms.load_from_file(JSON_path)
w2.units['y'] = MeasurementUnit.create('m')
w2data = w2.data.copy()
Expand Down
8 changes: 8 additions & 0 deletions src/Python/wcon/measurement_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
import operator as op
from scipy.constants import convert_temperature, pi

def F2C(val):
return convert_temperature(val, 'F', 'C')
def C2F(val):
return convert_temperature(val, 'C', 'F')
def K2C(val):
return convert_temperature(val, 'K', 'C')
def C2K(val):
return convert_temperature(val, 'C', 'K')

def C2C(x):
"""
Expand Down
9 changes: 6 additions & 3 deletions src/Python/wcon/wcon_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def df_upsert(src, dest):
src.columns.isin(dest.columns)]

# Sort our slices so they will be lined up for comparison
dest_sliced.sort_index(inplace=True)
src_sliced.sort_index(inplace=True)
dest_sliced.sort_index(axis=1, inplace=True)
src_sliced.sort_index(axis=1, inplace=True)

# Align src_sliced's row/column labels to dest_sliced. The two
# were built with independent .isin() masks so column order may
Expand Down Expand Up @@ -231,7 +231,10 @@ def convert_origin(df):

# Now reset our 'ox' values to zero.
if offset in cur_worm.columns.get_level_values(0):
df.loc[:, (worm_id, offset)] = np.zeros(ox_column.shape)
df.loc[:, (worm_id, offset)] = np.zeros(ox_column.shape, dtype=pd.Int64Dtype)
else:
all_x_columns = cur_worm.loc[:, (coord)].fillna(0).astype('float64')
df.loc[:, (worm_id, coord)] = all_x_columns.values

# Drop the offset columns entirely from the dataframe.
# This is so DataFrames with and without offsets
Expand Down
1 change: 1 addition & 0 deletions src/scala/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.10.11
2 changes: 1 addition & 1 deletion tests/minimax.wcon
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"x":"mm",
"y":"m",
"ox":"mm",
"oy":"mm",
"oy":"mm",
"speed":"mm/s",
"curvature":"1/mm",
"width":"mm",
Expand Down
Loading