Skip to content

Make pixdist2angdist faster#282

Open
AlexKurek wants to merge 2 commits into
lofar-astron:masterfrom
AlexKurek:Make-pixdist2angdist-faster
Open

Make pixdist2angdist faster#282
AlexKurek wants to merge 2 commits into
lofar-astron:masterfrom
AlexKurek:Make-pixdist2angdist-faster

Conversation

@AlexKurek
Copy link
Copy Markdown
Contributor

For 1.5 GB FITS the function is >2x faster.

before:
400452 2.451 0.000 21.837 0.000 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/readimage.py:585(pixdist2angdist)
after:
400452 2.103 0.000 9.663 0.000 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/readimage.py:585(pixdist2angdist)
.gaul files are identical.

Regarding "Trigonometry and bitwise identity" in the comments: I tried without this and there were numerical differences at 4. decimal place and beyond.

Copy link
Copy Markdown
Collaborator

@gmloose gmloose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though it's unclear to me how much speed improvement this will give for the whole (not just this function). Maybe @darafferty would like to double check?

@AlexKurek
Copy link
Copy Markdown
Contributor Author

AlexKurek commented May 21, 2026

These are the results from cProfile, so:
ncalls tottime percall cumtime percall filename:lineno(function)
21.837 - 9.663 = ~12 seconds for 1.5 GB FITS file on Xeon 6238R CPU. This is not much, but I assume that much larger files are being processed in surveys etc.

@AlexKurek
Copy link
Copy Markdown
Contributor Author

AlexKurek commented May 22, 2026

...let me explain a bit more on this.
ncalls shows, that this function is called 400k times, so vectorising the calls could be beneficial. However, this only makes sense when the function itself has been optimised as much as possible. Therefore, optimising a helper function can open the way to optimising the function that calls it.
tottime shows how much time is spent withing the function, not including numpy, scipy etc.
cumtime shows a total time the function takes in a PyBDSF run.

You can also use line_profiler (output in attachemnt):
import line_profiler
decorator for the function you want to profile:
@line_profiler.profile
Run:
LINE_PROFILE=1 python run_pybdsf.py
See output:
python -m line_profiler -rtmz profile_output.lprof

There is also memory_profiler :

from memory_profiler import profile
@profile # decorator
python -m memory_profiler --include-children run_pybdsf.py

line_profiler output: profile_output_2026-05-21T102741.txt

Another thing - results from snakeviz (snakeviz out.prof, where out.prof is the output from Cprofile) shows the relations between the functions:
Screenshot 2026-05-22 at 07-47-30 out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants