Skip to content

Commit

Permalink
Merge pull request #128 from LudwigBoess/RM_fix
Browse files Browse the repository at this point in the history
Rm fix
  • Loading branch information
LudwigBoess authored May 13, 2024
2 parents bf7c53e + b4ea082 commit f4622fd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SPHtoGrid"
uuid = "8a806948-229a-4117-b79b-c12ac366026f"
authors = ["LudwigBoess <[email protected]>"]
version = "0.4.6"
version = "0.4.7"

[deps]
Cosmology = "76746363-e552-5dba-9a5a-cef6fa9cc5ab"
Expand Down
10 changes: 10 additions & 0 deletions docs/src/effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ fo_image = map_path * "B.fits"
write_fits_image(fo_image, quantitiy_map, par, snap = snap, units = "muG")
```

## Faraday Rotation

You can map the Faraday Rotation due to the LOS magnetic field strength for RM maps, or for continuous rotation of polarized synchrotron emission using
```@docs
rotation_measure
```
For the latter we provide the simple helper function
```@docs
get_dz
```

## X-Ray emission

Expand Down
71 changes: 52 additions & 19 deletions src/effects/RM.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
# """
# rotation_measure(n_cm3::Real, B_par::Real; ν_obs=nothing)

# Computes the rotation measure of the parallel magnetic field along the LOS.
# """
# function rotation_measure(n_cm3::Real, B_par::Real; ν_obs=nothing)
# RM = 812 * n_cm3 * 1.e3 * B_par * 1.e6
# if !isnothing(ν_obs)
# RM *= c_light^2 * 1.e-4 / ν_obs
# end
# return mod(RM, π)
# end

"""
get_dz(M, rho, hsml)
Helper function to get the particle depth along the LOS.
Helper function to get the particle depth along the LOS in the given units.
All additional unit conversion must be performed by hand.
"""
get_dz(M, rho, hsml) = M / rho / (4 * hsml^2)

"""
rotation_measure(n_cm3::Real, B_los::Real, dz::Real; ν_obs=nothing)
Computes the rotation measure of the parallel magnetic field along the LOS.
## Arguments
- `n_cm3::Real`: Electron number density in [cm^-3].
- `B_los::Real`: Magnetic field strength along the LOS in [G].
## Returns
- `RM::Real`: Rotation measure in [rad/m^2].
## Mapping settings
- weight function: [`part_weight_physical`](@ref)
- reduce image: `false`
"""
function rotation_measure(n_cm3::Real, B_los::Real, dz::Real; ν_obs=nothing)
function rotation_measure(n_cm3::Real, B_los::Real)
# RM in rad/m^2
return faraday_prefac * n_cm3 * B_los * 100.0^2
end


"""
rotation_measure(n_cm3::Real, B_los::Real, dz::Real, ν_obs::Real)
Computes the rotation measure of the parallel magnetic field along the LOS at a given frequency.
To be used for continuous rotation of polarized emission along the LOS.
## Arguments
- `n_cm3::Real`: Electron number density in [cm^-3].
- `B_los::Real`: Magnetic field strength along the LOS in [G].
- `dz::Real`: Depth along the LOS in [cm]. See [`get_dz`](@ref) for a convenient helper function.
- `ν_obs::Real`: Observing frequency in [Hz].
## Returns
- `RM::Real`: Rotation measure in [rad/cm^2].
## Mapping settings
- weight function: [`part_weight_physical`](@ref)
- reduce image: `false`
- stokes: `true`
- sort_z: `true`
- `RM`: use output of this function.
"""
function rotation_measure(n_cm3::Real, B_los::Real, dz::Real, ν_obs::Real)
# RM in rad/cm^2
RM = faraday_prefac * n_cm3 * B_los
if !isnothing(ν_obs)
RM *= c_light^2 * dz / ν_obs
end
return mod(RM, π)

# for Stokes parameters we need rotation at given frequency
RM *= c_light^2 * dz / ν_obs^2

# store sign of rotation
_sign = sign(RM)

# reduce to minimum angle
return _sign * mod(RM, π)
end
1 change: 1 addition & 0 deletions src/effects/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ global const q_e = 1.602176487e-20 * c_light
global const yPrefac = σ_T * k_B / m_e / c_light^2
global const eV2cgs = 1.60218e-12
global const cgs2eV = 1.0/eV2cgs
global const kpc = 3.085678e21

# synchrotron
const global C_crit = 3q_e / (4π * m_e^3 * c_light^5) # Donnert+16, MNRAS 462, 2014–2032 (2016), Eg. 20
Expand Down
2 changes: 1 addition & 1 deletion src/effects/synchrotron_Hoeft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function analytic_synchrotron_HB07(rho_cgs::Array{<:Real}, m_cgs::Array{<:Real},

if isnothing(dsa_model)
# interpolate Ψ
η_tot = ηB * Ψ[Mach[i], T_keV[i]]
η_tot = ηB * Ψ(Mach[i], T_keV[i])
else
# evaluate DSA model
η_tot = ηB * η_Ms_acc(η_model, Mach[i])
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,12 @@ addprocs(2)
# check if the maximum density error is within 20% of the Gadget density
@test maximum(L1) < 0.2
end

@testset "Faraday Rotation" begin
@test rotation_measure(1.0, 1.0) SPHtoGrid.faraday_prefac * 1.e4

@test rotation_measure(1.0, 1.e-6, SPHtoGrid.kpc, 1.4e9) 2.6705855715515447
end
end

@testset "Image Functions" begin
Expand Down

2 comments on commit f4622fd

@LudwigBoess
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/106700

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.7 -m "<description of version>" f4622fd66ab0d838213d436d48b97058bddb8f6d
git push origin v0.4.7

Please sign in to comment.