-
Notifications
You must be signed in to change notification settings - Fork 10
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
Scaling of initial K0 guesses with TIFF files #21
Comments
can you share the parameters you used as well? It's been a long time since I used softworx, and I can't remember off the top of my head, but it's conceivable that the spacings are expressed differently. I can tell you that on my OMX, for 488nm excitation, i use
(and in the log output for that wavelength, it settles on:
so if you're starting with maybe @linshaova, remembers whether there was a difference in the way GE expressed linespacing? |
Quick reply, thank you! I've attached the config file (without the modified ls): Why is the spacing 0.414641 if your input is 0.2035? We tried halving the line spacing and this caused it to fail (bad k0 fit) - I've just run it with a halved Halved line spacing log file ( |
it is indeed confusing! 😂 I need to look back into the source code a bit to figure that seeming contradiction out. The source code is here if you'd like to look yourself: cudasirecon/src/cudaSirecon/gpuFunctionsImpl.cu Lines 874 to 995 in 97af94d
I'll try to find out something more concrete for you, and maybe @linshaova will also have thoughts |
Hi everyone, Sorry for the confusion. Line spacing output from the code should be roughly twice the number you input with lin |
thanks @linshaova. @thomasmfish, I just double checked my softworx settings, and they are indeed very close to my cudasirecon settings (for dv files)... on softworx as well, I have a linespacing of ~208nm for the 488x/525m channel. So, I'm a bit surprised that your line spacing would be upwards of 400nm even on softworx. Are you doing anything unusual that would cause your lines to be spaced so far apart (like, are you using a low NA objective or doing something different?). one thing I'm remember now... if I recall correctly, dv files have an inverted Y axis compared to tiff files, and if you look at the two config files in our test data here, the angles are indeed different: Lines 1 to 5 in 97af94d
cudasirecon/test_data/config-tiff Lines 1 to 6 in 97af94d
so, perhaps, drop your linespacing back down to the one closer to 200nm, and flip the sign on all of your angles |
@linshaova Thanks for your input. I believe we were expecting the 2nd order line spacing to be found and it is only finding the 1st - @iandobbie has a much deeper understanding than I do, so hopefully he can confirm whether I'm using the correct terms here. We were expecting double the magnitude for the k0s and were confused by why the line spacing wasn't consistent, so we thought there might be some scaling issue somewhere (perhaps just for tiffs - hence the name of the issue). @tlambert03 We are using an NA of 0.9, and I've made sure the line spacings correctly match softworx for each wavelength, so I believe they should be correct. |
yeah, i agree, that would be the surprising thing, but I've definitely seen it "settle" into incorrect local minima before when it was way off.
in any case, the number that the software is expecting you to enter is definitely that outer order, so, if you are using a 0.9 NA lens then your spacing in the upper 300nm range does sound about right. My guess/hope is that if you stick with that spacing, and invert the angles, it should be fine :) let us know how it goes |
Inverting the angles causes the reconstructions to fail, and I realised that we did check the magnitude against an FFT and found it matched the 1st order magnitude. At this point, I think the issue may be that it is failing to find the 2nd order, which is why it is blurrier than expected. Or it's a scaling factor. I'll spend some time looking through in more detail today. |
Could you perhaps share the data? One more question: since you're able to reconstruct this in softworx, you must be using a dv file there right? (I don't recall them supporting tiff?). Just want to know whether this is a parameter issue, or a file type issue |
I think something in the code must be flipping the angles as the fits succeed and produce angles very similar to softworx and output spacings close to exactly twice the softworx output. The reconstructions we are getting end pretty sharply at about 300 nm rather than the 200 nm which made me think we were getting about 2^0.5 improvement from the coarse stripes rather than the 2x expected from a full 3d SIM reconstruction. I guess out issue must be something else, maybe the OTFs? there is a bit of variability but the fitting amplitudes look similar to the softworx results so I am surprised about the pretty dramatic reduction of the reconstruction resolution. Another avenue I have investigated but not got to the bottom of is possible differing scale of the Wienner parameter so we are effectively filter much more aggressively with the cuda code compared to the softworx reconstruction. Thanks for your help and pointers so far. We are getting towards a working pipeline with much faster reconstructions than previously. |
Tom will have to answer the data sharing issue, not mine to share I'm afraid
The original data are .dv files. Tom has code that is taking the .dv files and dumping them into the recon process based on the python code in the repository but with adaptions to suit their workflow. The issue may well be file type related and I tried to build the cuda code to work with .dv files but struggled with cuda library versions etc... I am traveling for a couple of weeks and only have a mac laptop with no nvidia card so can work on this until I return. |
The reason I don't think this is the case is "generally" is that I'm using very similar parameters (with dv files) in both softWoRx and cudasirecon. (Granted it's been a long time since I used softWoRx, but when I checked yesterday, the params I was using were the same as what I used to use). And when I did my original pipeline switch as you are doing, I eventually found extremely similar reconstruction results once I got the parameters right. However, I still almost exclusively use dv files and not tiff. That's why I'm currently less convinced by the theory that the code is wrong, and more curious about what might be different about your use case or file (eg tiff vs dv). I've never tried an air objective with low NA though, so it's possible that there's an error along those lines that I hadn't run into Might need to see the data to be of much more help |
I have been given permission to share the data, though I'm not sure about posting it publicly. How should I get it to you? As Ian said, we are using DV files in softworx. For cudasirecon, I am splitting the DV files by channel, saving to TIFFs and config files (the config containing settings from the DV metadata), then passing to pycudasirecon via numpy array. |
You can email a link? [email protected] I'll mention the following codebase as well: The code there is absolutely hideous 🤢 😅 and 10 years old (using python 2). I wrote it before I created the pycudasirecon wrapper and never got around to updating... but that's what all my users use on our OMX to split channels/try a bunch of OTFs, pick the best one, reconstruct and merge them back together, etc... it stays with dv/mrc files all the way through (but conceptually, it should be fine with tiff as well, we just didn't have tiff support when I wrote that). Might find something to compare to in there amidst all the flotsam :) |
Also inasmuch as you're ultimately using pycudasirecon, you might consider reading and splitting your dv files directly into numpy buffers (without writing to tiff intermediate) using mrc: https://github.com/tlambert03/mrc |
I'll collect it together in some kind of understandable way and send a link over, thanks! I'll have a look at otfsearch, that sounds useful (I won't judge, don't worry!) I am using mrc already but I decided to write to TIFF for two reasons:
|
sounds good! |
ok, I had a moment to look at the data (thanks for sending), and it is indeed related to the inversion of the Y axis in TIFF vs dv files that I was mentioning in #21 (comment). I opened your Let me know if you're able to successfully reconstruct with a flipped tiff, and (if you try) whether you're able to determine the proper angles to use for a non-flipped tiff |
Sorry for chiming in late! Why isn't flipping the sign (not turning around by π) of k0 angle enough if vertical flip is the only difference between TIFF and DV files? I think sign-flip should work for all angles if specific angle numbers are provided (separated by comma). If only the first k0 angle is specified, then at least the first angle after sign-flipping should work. |
it's a good question 😂 it's always possible I/we did something wrong here, but that was my observation so far, and haven't had time to dig deeper... fwiw, his angles are 0.264,-1.83, 2.353 ... and from the reconstruction it looks like angle 1 and 2 were found fine, but the last one wasn't... |
These angles are 2π/3 apart; is this by design? I'm just curious because in all incarnations of SIM I've encountered, the pattern angles are π/3 apart; but there's nothing wrong in theory using 2π/3 angle step. That aside, regarding the 3rd angle, would adding π to it not make any difference? |
I'm really sorry, but it looks like I made a mistake when sending over those files... The I guess this means that inverting the symbols on the angles is equivalent to flipping the array but I sent the wrong files, which confused things!
@iandobbie may be able to answer the 2π/3 question but I think it's just a historical oddity as the angles should work out as equivalent to π/3 steps but in a different order. |
oh, i see... so this issue isn't about a ("catastrophic") failure in reconstruction, it's more about the subtle difference in resolution bump between softworx and cudasirecon? Just to make sure we 're all on the same page here, and so @linshaova can see exactly what's being discussed here. I plotted the radial FFT plot of your raw/WF data, the softworx reconstruction (SIR) and the so, there does seem to be a slight bump in contrast out at the very highest frequencies in the softworx reconstruction compared to the cudasirecon, but I don't think that looks like a band has been completely missed. we of course don't have access to source code of softworx... not sure if they ever modified stuff after receiving the code from UCSF. @linshaova might have an idea (or further questions for you) on hints for why there is a slight detail in high res contrast between the two... can you confirm that the difference in the chart above is indeed what you're concerned with here? |
Thanks for the clarification. So every angle worked and flipping k0 angles worked for un-flipped TIFF? Regarding the slight lower signal strength of |
Oops, I didn't reply to your questions @tlambert03!
Yes, you are correct - the chart you plotted shows what we were talking about. Hopefully the FFTs for different Wiener numbers illustrate why we were concerned but perhaps there are some modifications in softworx, as you said. It would be interesting to see if they are doing something differently. I am pretty out of my depth on this but I was wondering if it could be using a different regularization parameter? It seems like there is a much sharper falloff with the cudasirecon Wiener filtering, which is especially visible at low Wiener numbers. |
I think it came from the combination of reduced high frequency resolution and the difference in k0 magnitudes, as missing the second order would align with such a difference. @iandobbie, is there anything I've missed? Yes to the red dashed lines. I'll have to check the raw data tomorrow though, sorry! The raw data pixel size is 0.125 with a zoomfactor of 2, so 0.0625. |
Given 0.125 μm pixel size in the raw data, and 0.9 NA objective (~0.3 μm resolution limit), the extent of the FFT should fill about 83% (0.125*2/0.3) of the Fourier space boundary, which is not the case shown in your FFT and I agree with you that the 2nd order does seem missing in all softworx and cudasirecon results. However, the cudasirecon processing log you provided in the first post seems like both orders are optimally extracted (the |
I have previously found that the softworx code was very fussy about the angles and the expected 180 deg shift didn't produce a reliable fit. I think you are correct that there is an expected quadrant and the shifts in Fourier space don't work for some "equivalent" angles. I never quite got to the bottom of this but generally just calculated the 180 deg rotated angle and see if that fit with what looked like good data and then checked which angle worked and saved that into a general configs. |
I believe that the zero angle is vertical, so a sign flip would fix a reflection in X and not Y. |
Tom and I spent some time with this process (Tom mostly!) and once we got it working it is clear there is less high frequency information and the log value of the stripes at double the expected value from the softwrox output made me think it was failing with regards to the fit and somehow using the low frequency stripes as effectively producing 2^0.5 resolution increase. I think this is not the issue but there is a strange issue that the higher resolution data is much more heavily attenuated with the cuda code over softworx. might be scaling and weinner filtering or some other issue. I am traveling for another week, so wont have access to a machine allowing me to do any testing until then. Thanks for all the thoughts and I think we should have a serious look at all the components, OTF, etc and also try to get the cuda code working with the mrc files to truely eliminate any mrc to tiff issues. |
The amplitude can be greater than 1 with cudasirecon, which doesn't seem to be the case for softworx. Is there any scaling applied?
I was seeing the same result (but flipped) if I flipped the TIFF as if I flipped the signs on the k0 angles...
I'll have a deeper look at the OTFs. I'll try and convert the softworx OTFs to see if I can use them directly. Also, I'll see if I can dig up some other test files from when the SIM was better calibrated. |
thanks all for your input and patience. it would be great to have you using cudasirecon @iandobbie and @thomasmfish, so let's definitely keep digging. I'll try to dig in on my side as well and re-examine the softworx/cudasirecon differences.
one of the best things we could do here is try to drop the dependency on the IVE libraries. they are ancient, unmaintained, restrictively licensed, and we're just barely limping along by linking against the pre-compiled libraries (and I believe they may only be working on linux). I'm going to try to port my python code back to cpp so that we can finally drop that dependency, and just directly ship cudasirecon on conda-forge with mrc support. |
Thank you @tlambert03 and @linshaova! You've been incredibly helpful. The code I'm using expands upon pycudasirecon, taking DV files, splitting them (saves as TIFFs, though not strictly necessary) and rejoins them, with some config handling. I'm planning on making it open source ASAP but this depends on my manager, who is on holiday. I'm not sure if it will be helpful at all, but I can let you know when it is available. I'm personally not too fussed about reading DV files directly, but rather about whether any parameters are (or processing is) different with TIFFs, but I either way would fix the problem for me. |
Yes getting rid of the IVE dependencies would be great, MRC files are not that complicated and supporting the OMX (API?) defined extended header fields for SIM would be good as this allows specification of both and excitation and emission wavelength etc... I am still awaiting news on a grant that would have a full time programmer who could definitely contribute to such an effort. I'll let you know if we get anywhere. |
I'm not seeing the big difference between the Softworx and cudasirecon regarding high-resolution attenuation, especially after lowering Wiener in the latter (do you, @tlambert03?). I see attenuation in both results and the only possibility that I can think of is the following. There is a Fourier space boundary, calculated to be equal to the theoretical conventional resolution, used in the code's final assembly steps. If that boundary were calculated wrongly somehow then one could see the attenuation such as in this example. However, the only way this simple number can be miscalculated is if the input wavelength and NA parameters (plus XY pixel size) were wrong. Can it be confirmed that the correct wavelength, NA and pixel size numbers are fed into the program (especially for TIFF because there's no header that contains the wavelength)? |
p.s.: The "log value of the stripes at double the expected value from the softworx" turns out to be non-issue: it's just a different convention of expressing the same value, which I hope I did explain clearly earlier on. |
Hi @linshaova, the config I shared has all the settings used (linked again here: config525.txt). Obviously the Weiner number changed for the above FFTs, but the rest should be consistent. When compared to the values in the softworx log, they seem correct. It could be useful to have an option to print out all the parameters for checking this. |
Thank you for sharing this again. Could you uncomment this line in
I'd like to see what the Also, is the background really 200? If you use a sCMOS camera, the background should be around 100 for almost all models. |
Using the OTF from softworx saved as a TIFF then processed with cudasirecon Definitely different filtering (this is visible in the reconstruction too). In terms of the background, I've no idea. I'm just using the value from softworx. I've tried with background set to 0 and didn't see a difference. I haven't tried building it myself, I'm using the conda version. |
Update: I obtained the real data via Talley. From measuring the radially averaged OTF, I can tell that the conventional resolution limit is about 77% of maximum frequency defined by the 125 nm pixel size. In the raw data, the maximum frequency thus defined is 1/(512*.125)*256 = 4 cycles/um, and therefore the .conventional resolution is about 3.06 cycles/um, roughly in the middle between Abbey and Rayleigh limit numbers (which makes sense). Using this number and the line spacing number of 0.394 um (translated into 1/.394 = 2.538 cycles/um), the outer edge of the SIM resolution limit would thus be 3.06+2.538 = 5.598 cycles/um, and in terms of percentage of this limit over the maximum frequency of 8 cycles/um in the SIM reconstruction (because of halved pixel size, 4 becomes 8), it's roughly 70% and consistent with the results' FFT images shown above. |
from the readme:
but @linshaova could probably answer any additional things if that explanation leaves open questions |
I have been thinking about where the differences between the two processing pipelines might come from. I understand Lin's arguments about the expected resolution but am trying to track down the significant differences we see. Obviously the line spacing is a red herring. With this eliminated I suspect that the OTF processing might be the most significant difference.
I think my next step is to try and setup both cuda and softworx reconstruction workflows and follow them through closely to see how the various steps compare. I am still away till the end of the week. |
Of course I missed the place that was right in front of me! I think I need to spend more time reading around it to understand that fully but I'm glad I have something to go by now. Thanks for highlighting that section for me.
There's definitely a sharper drop-off around just before 10 in the radial FFT plots of cudasirecon results, which I guess is what we're seeing here too.
I have set values per-wavelength but as I've never done it before, so I wouldn't be surprised if they could be improved. The reason I asked about the third leavekz value is that I've just left it as 5, matching how it is in softworx. In case it's useful:
I have been using the setting
Thank you so much for taking this time, especially while you're away. |
Probably not important but just in case, I've fixed the nobeadcomp setting issue - it was a silly mistake when parsing the config. Now the amplitudes are more comparable. The amplitudes do seem to be larger with softworx. Softworx:
cudasirecon:
Though those are using different OTFs (same PSFs). Using the same OTF softworx used, it gets a much lower amplitude:
Inspecting the OTFs, the softworx one is definitely less well trimmed (though they're both not great), and has pixel values that are slightly more than double that of in the cudasirecon OTFs. I'm not sure what could be causing that but I could manually adjust the softworx values to match and see if that helps. |
I've run this again with the data I've been told is better. I don't think the OTF is great on some channels but the 525 is looking good and has given good results, so I'm going to focus on that. Here's the FFT of two images that look a much closer match and don't have the blurring we've been seeing. Much more of what I called a "halo" on both, though definitely more significant with softworx. I have no idea why:
Here are the log files in case that's useful: I still need to try the simulated data but that's for another day. |
Hi all, sorry for the radio silence on this issue. Ian and I have been investigating things and it looks like the main difference is that softworx has no way to specify the One thing that I was unsure about is the apodization, as the options section of the logs we get from softworx contains:
I'm not sure how those settings would map to cudasirecon, or if one of those settings overrides the other in softworx. However, it looks like in cudasirecon, I also wanted to mention the project I've been working on, called PySIMRecon, in case it is of interest to you. The idea is to wrap cudasirecon/pycudasirecon with Python to allow the setting of default values that match a microscope, along with OTFs, so that it can be easily used for automatic processing. It handles splitting and recombining DV files and has a couple of other tools in it too. Also, on a personal note, I am moving on from my current job at the end of this month, so I unfortunately won't be able to continue the project. However, I will be installing PySIMRecon as part of the automatic processing pipeline we use, so it should continue to be maintained and developed. |
We are trying to compare cudasirecon output with that from softworx on some data we have already reconstructed with softworx. The cudasirecon is failing in a strange manner: we get a successful reconstruction but it appears to find stripes with exactly twice the expected line spacing. The the reconstructions have a small enhanced resolution but not the expected successful reconstruction.
We believe that the issue is that the initial k0 estimate is incorrectly calculated and the initial guess for the k0 position in pixels in Fourier space is incorrect. The angle is fine but the magnitude is half as big as expected.
I'm tagging @iandobbie as I'm working with him on this.
cudasirecon log (525nm)
softworx log
The text was updated successfully, but these errors were encountered: