I previously did a typical process flow: import movie->Patch motion->…, then I moved the raw movies to another data server. Now I come back and want to do local motion correction. How can I reimport the movie from another directory and link the movie to the existing Patch motion job?
Thanks, I should ask earlier. While I was trying different ways, I have cleared my J1 job and lost all previous files. Is there a way to link my J2 job (patch motion) to a new import movie job?
To mess around with linking of jobs, cryosparc-tools would probably be recommended. I’ll leave @hsnyder or @wtempel to explain that better than I.
The UID prefix that CryoSPARC loves so much is a bit of a pain at times, it makes recovering from SNAFUs like this a bit harder than it otherwise would be.
In your Local Motion Correction job, connect the motion-corrected micrographs first, then substitute the movie_blob and gain_ref_blob low-level inputs from the new external job by dragging them into the “Movies” input group:
Thank you for your script! I did a run and get the following thing. I cleared my J1 job previously when I tried different ways to solve the problem. Does your script need the untouched old J1 job?
/home/spuser/anaconda3/lib/python3.10/site-packages/cryosparc/job.py:380: UserWarning: *** CommandClient: (http://localhost:39003/load_job_input) HTTP Error 422 UNPROCESSABLE ENTITY; please check cryosparcm log command_vis for additional information.
Response from server: b'{"project_uid": "P7", "job_uid": "J392", "input_name": "old_movies", "slots": ["movie_blob", "gain_ref_blob"]}'
with make_json_request(self.cs.vis, "/load_job_input", data=data) as response:
Traceback (most recent call last):
File "/data/youwang/cryosparc_working/20230518_1014/CS-20230518-1014/update_imported_movies.py", line 45, in <module>
movies_dset = new_import_job.load_input(
File "/home/spuser/anaconda3/lib/python3.10/site-packages/cryosparc/job.py", line 380, in load_input
with make_json_request(self.cs.vis, "/load_job_input", data=data) as response:
File "/home/spuser/anaconda3/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/home/spuser/anaconda3/lib/python3.10/site-packages/cryosparc/command.py", line 225, in make_request
raise CommandError(error_reason, url=url, code=code, data=resdata)
cryosparc.errors.CommandError: *** (http://localhost:39003/load_job_input, code 422) HTTP Error 422 UNPROCESSABLE ENTITY; please check cryosparcm log command_vis for additional information.
Response from server: b'{"project_uid": "P7", "job_uid": "J392", "input_name": "old_movies", "slots": ["movie_blob", "gain_ref_blob"]}'
I assume I should make a change: old_import_movies_job_uid = “J2”. J2 is my patch motion job. Here is the output:
Traceback (most recent call last):
File “/data/youwang/cryosparc_working/20230518_1014/CS-20230518-1014/update_imported_movies.py”, line 29, in
new_import_job.connect(
File “/home/spuser/anaconda3/lib/python3.10/site-packages/cryosparc/job.py”, line 1289, in connect
self.cs.vis.connect_external_job( # type: ignore
File “/home/spuser/anaconda3/lib/python3.10/site-packages/cryosparc/command.py”, line 121, in func
raise CommandError(
cryosparc.errors.CommandError: *** (http://localhost:39003, code 400) Encountered ServerError from JSONRPC function “connect_external_job” with params {‘project_uid’: ‘P7’, ‘source_job_uid’: ‘J2’, ‘source_output’: ‘imported_movies’, ‘target_job_uid’: ‘J393’, ‘target_input’: ‘old_movies’, ‘slots’: [‘movie_blob’, ‘gain_ref_blob’], ‘title’: ‘’, ‘desc’: ‘’}:
ServerError: Source job P7-J2 does not have output imported_movies
Traceback (most recent call last):
File “/spshared/apps/cryosparc4/cryosparc_master/cryosparc_command/commandcommon.py”, line 195, in wrapper
res = func(*args, **kwargs)
File “/spshared/apps/cryosparc4/cryosparc_master/cryosparc_command/commandcommon.py”, line 264, in wrapper
return func(*args, **kwargs)
File “/spshared/apps/cryosparc4/cryosparc_master/cryosparc_command/command_vis/snowflake.py”, line 212, in connect_external_job
assert source_output_group, f"Source job {project_uid}-{source_job_uid} does not have output {source_output}"
AssertionError: Source job P7-J2 does not have output imported_movies
Ah my apologies, you also have to replace "imported_movies" in the new_import_job.connect() call with "micrographs" or whatever the output name was for your motion correction job. Example for Patch Motion Correction:
Thanks, It seems run through most part but end with:
Traceback (most recent call last):
File “/data/youwang/cryosparc_working/20230518_1014/CS-20230518-1014/update_imported_movies.py”, line 54, in
new_imported_path.symlink_to(mov)
AttributeError: ‘PurePosixPath’ object has no attribute ‘symlink_to’
Thanks, it works. But then I run local motion correction, it still shows can’t find file:
[libtiff error] TIFFOpen: /data/youwang/cryosparc_working/20230518_1014/CS-20230518-1014/J1/imported/014974633499939006110_20230518_1014_A020_G000_H003_D001.tif: No such file or directory
@parrot I believe this means you didn’t specify the correct path to the new location of the movies (with the new_movies_folder variable) or that this path is not available on the worker where Local Motion Correction is running (e.g., directory not mounted). Edit I noticed that the path still shows J1, that means the movies dataset was not updated correctly, so this last part does not apply.
This is tough to debug remotely. For the quickest resolution, you may want to fall back on re-doing Patch Motion Correction and then reassigning your existing particles to the newly motion-corrected exposures, as @wtempel suggested. The Reassign Particles to Micrographs job type’s prototypical use case is very similar to your own.
Thank you so much for the script! I just follow these steps and was able to re-link previously deleted movies.
Everything appears to work, and I can use the output of this external job for “local motion correction”.
However, the “reference based motion correction” didn’t work, with the following error.
Any suggestions as to why this failed? FYI, the movies are Falcon4 EER files.
I believe this happens when the actual frames of the movie that reference motion is processing does not match the end-frame recorded by an input Patch or Full-frame Motion Correction job. Did you by any chance connect motion-corrected micrographs instead of movies?
To fix this, you can try:
Re-run Patch Motion Correction, setting the “End frame” parameter to the minimum number of frames minus one
Modify the above script to also load the rigid_motion slot, and set the "rigid_motion/frame_end" column to (minimum number of frames minus one)
For the “reference motion correction” job, I did use the motion-corrected micrographs as the input. In addition, I modified the movie and gain blob sub-inputs to point to external job. These input settings help the “reference motion correction” reached a stage for actual calculation. In comparison, when I use the movie output as the input, the “reference motion correction” would complain about necessary inputs were absent and failed earlier.
I will try to re-run the Patch Motion Correction, which may take some time given the constraints of GPUs.
Regarding to your second suggestion, how do you load the rigid_motion slot in the external job? Does that mean I need to load both the “Import Movies” and the “Patch Motion Correction” jobs in the external job? Thanks!