sollan / alma

Fully automated (rodent) limb motion analysis toolbox for behavioral analysis with bodypart coordinate data, building upon markerless pose estimation.
GNU General Public License v3.0
13 stars 5 forks source link

AttributeError: 'NoneType' object has no attribute 'to_csv' #31

Closed SIM0N-W closed 1 year ago

SIM0N-W commented 1 year ago

Trying to test the Spontaneous walking parameter extraction using the file I have attached. E9_1_alma.csv

I have set the config file to the appropriate (1) frame_rate, (2) pixels_per_cm, and (3) right_to_left. However, when I press "Start parameter extraction", I am getting the following error:

[69, 124, 182, 245, 304]
0     nan
1     nan
2     nan
3    2.32
4     nan
Name: cycle duration (s), dtype: object
Traceback (most recent call last):
  File "G:\Shared drives\Rodent Gait\alma\Panels\AnalyzeStride.py", line 704, in ExtractParameters
    KinematicsFunctions.make_parameters_output(self.output_path, parameters_truncated)                    
  File "G:\Shared drives\Rodent Gait\alma\Functions\KinematicsFunctions.py", line 201, in make_parameters_output
    parameters.to_csv(pathname)
AttributeError: 'NoneType' object has no attribute 'to_csv'

Could you help me with this issue?

SIM0N-W commented 1 year ago

Also is there a way to refresh the GUI, or is closing the window then retyping "python ./alma.py" in CMD the current way?

SIM0N-W commented 1 year ago

The accurate px/cm length ratio is 28. However, if I change that ratio to anything below 17.6, it outputs a .csv and .svg file and gives me this error instead:

[69, 124, 182, 245, 304]
0    nan
1    nan
2    nan
3    nan
4    nan
Name: cycle duration (s), dtype: object
Traceback (most recent call last):
  File "C:\Users\Chan Lab White\Downloads\alma\Panels\AnalyzeStride.py", line 707, in ExtractParameters
    KinematicsFunctions.make_parameters_output(os.path.join(os.path.dirname(self.output_path), f'continuous_strides_parameters_{self.filename}.csv'), parameters_truncated)
  File "C:\Users\Chan Lab White\Downloads\alma\Functions\KinematicsFunctions.py", line 201, in make_parameters_output
    parameters.to_csv(pathname)
  File "C:\build\envs\alma\lib\site-packages\pandas\core\generic.py", line 3204, in to_csv
    formatter.save()
  File "C:\build\envs\alma\lib\site-packages\pandas\io\formats\csvs.py", line 184, in save
    f, handles = get_handle(
  File "C:\build\envs\alma\lib\site-packages\pandas\io\common.py", line 428, in get_handle
    f = open(path_or_buf, mode, encoding=encoding, newline="")
FileNotFoundError: [Errno 2] No such file or directory: 'G:\\Shared drives\\Rodent Gait\\RESULTS\\ALMA\\test_results\\continuous_strides_parameters_G:\\Shared drives\\Rodent Gait\\RESULTS\\ALMA\\test_results\\E9_1_alma.csv.csv'
sollan commented 1 year ago

Hi, I was able to see the parameters (instead of NaN's) after setting no_outlier_filter to True in the configurations. So the NaN's are due to the outlier filter, which only accepts step cycles that meet certain criteria: limb_len_max < 15 and stride_len_cm < 8 and \ cycle_dur_frame > 1 and step_height < 1.5 and stride_len_cm > 1 (units are in cm, calculated using the conversion ratio)

As noted in the config comments, this option applies to a spontaneous walking set up (because, presumably, when the animal walks freely, there might be more variation in step cycles, e.g. the walking speed can change because there is no constraint due to treadmill speed).

You might want to inspect and validate the results though (including based on the svg plot and manually going through the parameters for individual steps to see if they make sense), since the analysis for spontaneous walking was added more recently and wasn't tested as extensively as the methods for a treadmill walking set-up. There might also be some inaccuracy in the pixels_per_cm ratio that was set manually (as indicated by the outlier filter, which is sensitive to suspicious length parameters), or maybe your data is from a different animal model (perhaps larger - based on the px/cm ratio of 28, the step lengths would be above 8cm) that doesn't meet the same parameter standards?

Nevertheless, as a general rule, more datapoints used (averaged) to estimate the px-cm conversion ratio and more step cycles in the recording would lead to more accurate and meaningful analysis.

Regarding your other question: There is no "refresh" button. But if the GUI should refresh / go to the next step but doesn't, then there's a bug. If you could record the steps that led to a "stuck" screen, please let me know.

SIM0N-W commented 1 year ago

Thank you very much for the quick reply! I was hoping to become familiar with the toolkit by testing it using some roughly formatted sample data. Thank you for the advice to set the outlier filter to TRUE! The animal is a mouse. I very roughly calculated the px/cm ratio to 28. It might be larger than typical because the video is zoomed in and the x-resolution is only 1000 pixels. I note that because each video can only fit a low amount of strides, outcomes like DTW 5 & 10 strides will thus be unavailable. There are many nuances for me to learn regarding gait analysis and I am really grateful for your help 🙏.