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

adding dataplots.jl #385

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

adding dataplots.jl #385

wants to merge 11 commits into from

Conversation

erandichavez
Copy link

Comrade plotting functionality for observation data. Currently supports Makie figures and Makie subplots.

@ptiede
Copy link
Owner

ptiede commented Dec 23, 2024

This looks fantastic and I am really excited to get these in Comrade. The biggest thing that needs to change before merging is moving this to an extension. Other than that the rest of the comments are minor.

There is a potential generalization I mention but maybe we can work on that after this is merged.

obsdomain = domain(obsdata)
u = getfield.(getfield(obsdomain,:dims),:U)
v = getfield.(getfield(obsdomain,:dims),:V)
uvdist = hypot.(u,v)
Copy link
Owner

Choose a reason for hiding this comment

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

We have a dedicated function for uvdist

uvd = uvdist.(dt)

should work here

end
elseif field in (:U, :V, :Ti, :Fr)
obsdomain = domain(obsdata)
return getfield.(getfield(obsdomain,:dims),field)
Copy link
Owner

Choose a reason for hiding this comment

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

Again we should do something like

bls = dt.baseline
return getproperty(bls, field)


NamedTuple of the scatter plot keyword arguments
"""
function plotfields(obsdata::EHTObservationTable{}, field1::Symbol, field2::Symbol; axis_kwargs=(;), legend_kwargs=(;), scatter_kwargs=(;))
Copy link
Owner

Choose a reason for hiding this comment

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

We can replace EHTObservationTable{} with just EHTObservationTable. The {} shouldn't be needed.


νlist = unique(Fr) # multifrequency support

with_theme(theme_latexfonts()) do
Copy link
Owner

Choose a reason for hiding this comment

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

I'm a little hesitant to force this specific theme here, just because if someone wants to use a different theme, i.e. different global font sizes, this will not longer be permitted. I think we should probably just leave this off for now, and make an explicit example in the docs if you want LaTeX fonts.

end
end

function plotfields(obsdata::EHTObservationTable{}, field1::Symbol, field2::Symbol, site1::Symbol, site2::Symbol; axis_kwargs=(;), legend_kwargs=(;), scatter_kwargs=(;))
Copy link
Owner

Choose a reason for hiding this comment

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

Again the {} isn't really needed here.

amps = abs.(vis)
return amps
elseif field == :phase # calculate visibility phases
phases = atan.(imag(vis), real(vis))
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
phases = atan.(imag(vis), real(vis))
phases = angle.(vis)

will construct the complex argument with the same definition the EHT uses

phases = atan.(imag(vis), real(vis))
return phases
elseif field == :snr
snr = abs.(vis) ./ obsdata.noise
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
snr = abs.(vis) ./ obsdata.noise
sigma = Comrade.noise(obsdata)
snr = abs.(vis) .* inv.(sigma)

just so we keep to the standard format

Comment on lines 59 to 60
obsdomain = domain(obsdata)
u = getfield.(getfield(obsdomain,:dims),:U)
Copy link
Owner

Choose a reason for hiding this comment

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

getfield should typically be avoided since it signals internals that may not be guaranteed to work for minor revision bumps. For this we should extract the datatable and then grab the elements. So something like

Suggested change
obsdomain = domain(obsdata)
u = getfield.(getfield(obsdomain,:dims),:U)
dt = datatable(obsdomain)
u = dt.baseline.U
v = dt.baseline.V

obsdomain = domain(obsdata)
u = getfield.(getfield(obsdomain,:dims),:U)
v = getfield.(getfield(obsdomain,:dims),:V)
uvdist = hypot.(u,v)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
uvdist = hypot.(u,v)
uvd = uvdist.(dt)

We actually have a dedicated for this


:snr - signal to noise ratio
"""
function getobsdatafield(obsdata::EHTObservationTable{}, field::Symbol)
Copy link
Owner

Choose a reason for hiding this comment

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

Looking at this function is isn't quite guaranteed to give the things we want for all EHTObservationTables. The first step is probably to extract the table in a more friendly format, using the datatable function. This tries its best to uniformize everything into a flat table. The columns are usually

| baseline | measurement | noise |

where baseline itself is a table with all the elements, i.e. U, V, Ti, Fr, etc.

@ptiede
Copy link
Owner

ptiede commented Jan 9, 2025

@erandichavez
Copy link
Author

The plotting code has now been moved to an extension with all your suggestions implemented! (if I blew up your email with these commits i am so sorry)

end
end

function plotcaltable(
Copy link
Author

Choose a reason for hiding this comment

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

Also forgot to mention, I also wrote a function for automatically plotting caltables here!

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