Skip to content
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

Include zscale #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Include zscale #28

wants to merge 2 commits into from

Conversation

Devagio
Copy link

@Devagio Devagio commented May 12, 2021

This DS9/IRAF feature allows defining the image scale according to IRAF's z-scale and returns a minimum and maximum color. This fixes #27

Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your contribution! Besides a few comments I wrote down (only the first time I found a specific issue, but they're repeated several times across this file), however there are many things to improve:

  1. there are no docstrings and no references for what you're doing, it's really hard to follow what you do if you don't explain it
  2. there are no tests anywhere
  3. this code isn't actually used anywhere

Comment on lines +1 to +6
MAX_REJECT = 0.5
MIN_NPIXELS = 5
GOOD_PIXEL = 0
BAD_PIXEL = 1
KREJ = 2.5
MAX_ITERATIONS = 5
Copy link
Member

Choose a reason for hiding this comment

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

Please, have a read of the performance tips in the Julia manual: https://docs.julialang.org/en/v1/manual/performance-tips/. Not using non-constant global variables is the very first issue. Some of these variables aren't even used in more than a function, so making them global isn't even useful.

Comment on lines +9 to +26
function flatten(image)

# colapses into one dimension (Float64) a 2D array in row-major (C-style flattening)

rows = size(image)[1]
cols = size(image)[2]
n_pxls = rows * cols

result = Array{Float64}(undef, n_pxls)

k = 1
for i in 1:rows, j in 1:cols
result[k] = image[i, j]
k += 1
end

return result
end
Copy link
Member

Choose a reason for hiding this comment

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

This is what image[:] does, this function isn't needed

nl = size(image)[2]

stride = maximum([1.0, sqrt((nc - 1) * (nl - 1) / maxpix)])
stride = Int128(round(stride))
Copy link
Member

Choose a reason for hiding this comment

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

Why Int128?

src/zscale.jl Show resolved Hide resolved
Comment on lines +54 to +55
sumz = 0
sumsq = 0
Copy link
Member

Choose a reason for hiding this comment

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

These variables will likely be type-unstable

end


function zsc_sample(image, maxpix)
Copy link
Member

Choose a reason for hiding this comment

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

What is this function actually doing and how? Please add docstrings to functions.

end


function zsc_compute_sigma(flat, badpix)
Copy link
Member

Choose a reason for hiding this comment

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

Also here (and everywhere) a docstring would be useful. Please also explain the meaning of the mean or sigma equal to nothing (which I'm not sure is a good idea)


function zsc_fit_line(samples, npix, krej, ngrow, maxiter)

# calculate slope and intercept for the algorithm
Copy link
Member

Choose a reason for hiding this comment

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

Which algorithm? There is no reference to what you're doing here.

src/zscale.jl Show resolved Hide resolved
center_pixel = Int128(round((npix + 1) / 2))
median = samples[center_pixel]
else
Int128(round(npix / 2))
Copy link
Member

Choose a reason for hiding this comment

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

What is this line doing?

Copy link
Author

Choose a reason for hiding this comment

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

It is supposed to be:
center_pixel = Int128(round(npix / 2))
Will rectify it with other changes.

@Devagio
Copy link
Author

Devagio commented May 16, 2021

Okay thank you for such a detailed response; I'll begin working on your suggestions.
Apologies for the mistakes and sub-optimal code, I'm new to both Julia and open-source.

@mileslucas
Copy link
Member

@Devagio I've coded zscale in Julia over at PlotUtils.jl, you can use that as a reference if you like. It's been a while since I wrote that code, you may find ways to improve upon it. Otherwise you may wish to just copy it, this decouples any reliance on the Plots.jl-verse.

@giordano
Copy link
Member

Given the fact we're going towards #29, I'm not sure we really need to add a zscale implementation here.

@sefffal
Copy link
Member

sefffal commented Mar 27, 2022

With regards to #29, right now I have it re-exporting zscale from PlotUtils so that one can pass clims=zscale ∘ collect.
The collect is necessary for now with either this PR or the one from PlotUtils, since for performance reasons, functions passed to clims should accept an iterable. This way they can loop through the data without allocations when possible.
I think the z-scale algorithm does need a full materialized copy of the array, so perhaps it's type signature could be to loosened to allow iterables and then just collect them.

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.

IRAF z-scale
4 participants