Skip to content

Commit

Permalink
Merge pull request #31 from domengorjup/master
Browse files Browse the repository at this point in the history
Fix backwards compatibility issues with pyIDI.info, pyIDI.close_video() and analyzing ndarray videos.
  • Loading branch information
itomac authored May 16, 2024
2 parents 4fe81c4 + 2eab861 commit 60a05a3
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 201 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ dmypy.json
/data/*.pkl

#other
server_user_id.txt
server_user_id.txt

/temp
109 changes: 85 additions & 24 deletions Showcas_LK.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Domen\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\copy.py:151: DeprecationWarning: Pickle, copy, and deepcopy support will be removed from itertools in Python 3.14.\n",
" rv = reductor(4)\n",
"C:\\Users\\Domen\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\copy.py:261: DeprecationWarning: Pickle, copy, and deepcopy support will be removed from itertools in Python 3.14.\n",
" y.__setstate__(state)\n"
]
}
],
"source": [
"import os\n",
"import sys\n",
Expand All @@ -25,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -42,9 +53,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Date': '2016/08/31',\n",
" 'Camera Type': 1,\n",
" 'Record Rate(fps)': 1,\n",
" 'Shutter Speed(s)': 1.0,\n",
" 'Total Frame': 101,\n",
" 'Original Total Frame': 101,\n",
" 'Start Frame': 0,\n",
" 'Image Width': 256,\n",
" 'Image Height': 128,\n",
" 'Color Type': 'Mono',\n",
" 'Color Bit': 16,\n",
" 'File Format': 'MRaw',\n",
" 'EffectiveBit Depth': 12,\n",
" 'EffectiveBit Side': 'Lower',\n",
" 'Comment Text': 'Generated sequence.<br>Modify measurement info in<br>created .cih file if necessary.'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"video.reader.info"
]
Expand All @@ -58,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -74,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -90,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -106,9 +142,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--- Starting new analysis ---\n",
" \n",
"Computation start: 2024-05-16 08:37:22.807458\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "13430c29596e4052b53b0ac8b85e5442",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Computation duration: 00:00:6.88\n",
"data\\data_synthetic_pyidi_analysis\\analysis_004\\ analysis_004\n"
]
}
],
"source": [
"displacementes = video.get_displacements(processes=2)"
]
Expand All @@ -122,26 +190,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"filename = 'data/data_synthetic_pyidi_analysis/analysis_001'\n",
"video_loaded, info_dict = pyidi.load_analysis(filename, )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -155,7 +216,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.12.2"
},
"toc": {
"base_numbering": 1,
Expand All @@ -172,5 +233,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
277 changes: 109 additions & 168 deletions Showcase.ipynb

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions pyidi/pyidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,11 @@ def get_displacements(self, autosave=True, **kwargs):
raise ValueError('IDI method has not yet been set. Please call `set_method()` first.')


# def close_video(self):
# """
# Close the .mraw video memmap.
# """
# if hasattr(self, 'mraw'):
# self.mraw._mmap.close()
# del self.mraw
def close_video(self):
"""
Close the .mraw video memmap.
"""
self.reader.close()


def create_analysis_directory(self):
Expand Down Expand Up @@ -230,7 +228,7 @@ def save(self, root=''):
'N': self.reader.N
},
'createdate': datetime.datetime.now().strftime("%Y %m %d %H:%M:%S"),
'cih_file': self.cih_file,
'cih_file': self.cih_file if type(self.cih_file) == str else 'ndarray',
'settings': self.method.create_settings_dict(),
'method': self.method_name
}
Expand Down Expand Up @@ -269,6 +267,11 @@ def gui(self):
def mraw(self):
warnings.warn('`self.mraw` is deprecated and will be removed in the next version. Please use `self.reader.mraw` instead.', DeprecationWarning)
return self.reader.mraw

@property
def info(self):
#warnings.warn('`self.info` is deprecated and will be removed in the next version. Please use `self.reader.info` instead.', DeprecationWarning)
return self.reader.info

# def gui(self):
# """Napari interface.
Expand Down
10 changes: 10 additions & 0 deletions pyidi/video_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, input_file, root=None):
self.N = info['Total Frame']
self.image_width = info['Image Width']
self.image_height = info['Image Height']
self.info = info

elif self.file_format in SUPPORTED_IMAGE_FORMATS:
image_prop = iio.improps(input_file)
Expand Down Expand Up @@ -189,6 +190,15 @@ def _get_frame_from_video_file(self, frame_number, use_channel='Y'):
raise ValueError('Unsupported channel! Only R, G, B and Y are supported.')

return image

def close(self):
"""
Close the video and clear the resources.
In case of a MRAW video, closes the memory map for "mraw" file format.
"""
if hasattr(self, 'mraw') and self.file_format in PHORTRON_HEADER_FILE:
self.mraw._mmap.close()
del self.mraw

def _rgb2luma(rgb_image):
"""Converts "RGB" image to "YUV" and returns only "Y" (luma) component.
Expand Down

0 comments on commit 60a05a3

Please sign in to comment.