Skip to content

Commit

Permalink
added plot_methos.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
walra356 committed Jan 8, 2025
1 parent 098dbcc commit 7f0a4e2
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/src/pages/fits.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ cast_FORTRAN_format(str::String)
```@docs
FORTRAN_eltype_char(T::Type)
parse_FITS_TABLE(hdu::FITS_HDU)
```

## Plotting

```@docs
step125(x::Real)
select125(x)
steps(x::Vector{T} where T<:Real)
stepcenters(x::Vector{T} where T<:Real)
stepedges(x::Vector{T} where T<:Real)
edges(px, Δx=1.0, x0=0.0)
```
8 changes: 8 additions & 0 deletions src/CamiFITS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ export test_fits_edit_key!
export test_fits_delete_key!
export test_fits_rename_key!

export step125
export select125
export steps
export stepcenters
export stepedges
export edges

include("julia_toolbox.jl")
include("fits_objects.jl")
include("dicts.jl")
Expand All @@ -173,5 +180,6 @@ include("fits_public_sector.jl")
include("FORTRAN.jl")
include("fits_tests.jl")
include("test_fits_format.jl")
include("plot_methods")

end
143 changes: 143 additions & 0 deletions src/plot_methods.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# SPDX-License-Identifier: MIT

# author: Jook Walraven - 14-2-2023

# ==============================================================================
# plot_methods.jl
# ==============================================================================

# ==================================== step125(x) ============================================================

"""
step125(x)
Step used for deviding the number x in steps according to 1-2-5 scheme
#### Examples:
```
step125.([5,10,21.3,50,100.1])
5-element Vector{Int64}:
1
2
5
10
20
```
"""
function step125(x::Real)

m = CamiMath.log10_mantissa(x)
p = CamiMath.log10_characteristic(x)
v = 10^m
d = v > 7.9 ? 2.0 : v > 3.9 ? 1.0 : v > 1.49 ? 0.5 : 0.2

return max(1,round(Int, d *= 10^p))

end

# ==================================== select125(x) ===============================================================

"""
select125(x)
Select elements of the collection x by index according to 1-2-5 scheme
#### Examples:
```@docs
x = [1,2,4,6,8,10,13,16,18,20,40,60,80,100]
select125(x)
[2, 6, 10, 16, 20, 60, 100]
x = string.(x)
select125(x)
["2", "6", "10", "16", "20", "60", "100"]
x = 1:100
select125(x)
[20, 40, 60, 80, 100]
```
"""
select125(x) = (n = length(x); return [x[i] for i=step125(n):step125(n):n])

# ==================================== edges(x) ===============================================================

"""
edges(px [, Δx[, x0]])
Heatmap range transformation from pixel coordinates to physical coordinates,
with pixelsize Δx and offset x0, both in physical units.
#### Examples:
```@docs
px = 1:5
Δx = 2.5
x0 = 2.5
edges(px)
[0.5, 1.5, 2.5, 3.5, 4.5]
edges(px, Δx)
[1.25, 3.75, 6.25, 8.75, 11.25]
edges(px, Δx, x0)
[-1.25, 1.25, 3.75, 6.25, 8.75]
```
"""
edges(px, Δx=1.0, x0=0.0) = collect(px .* Δx) .-(x0 + 0.5Δx)

# =================================== steps(x) =============================================================

"""
steps(x)
Heatmap range transformation for steplength specification vector x
#### Examples:
```@docs
x = [4,2,6]
steps(x)
[0, 4, 6, 12]
```
"""
function steps(x::Vector{T} where T<:Real)

sum(x .< 0) == 0 || error("Error: $x - nagative step length not allowed")

return (s = append!(eltype(x)[0],x); [Base.sum(s[1:i]) for i Base.eachindex(s)])

end

# =================================== stepcenters(x) =============================================================

"""
stepcenters(x)
Stepcenter positions for steplength specification vector x
#### Examples:
```@docs
x = [4,2,6]
stepcenters(x)
[2.0, 5.0, 9.0]
```
"""
function stepcenters(x::Vector{T} where T<:Real)

s = append!(eltype(x)[0],x)

return [Base.sum(s[1:i]) + 0.5x[i] for i Base.eachindex(x)]

end

# =================================== stepedges(x) =============================================================

"""
stepedges(x)
Stepedges for steplength specification vector x
#### Examples:
```@docs
x = [4,2,6]
stepedges(x)
[0, 4, 6, 12]
```
"""
function stepedges(x::Vector{T} where T<:Real)

return steps(x)

end
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ using Dates
@test fits_terminology("s"; test=true)
@test fits_terminology(; test=true)

@test edges(1:5, 2.5, 2.5) == [-1.25, 1.25, 3.75, 6.25, 8.75]
@test steps([4, 2, 6]) == [0, 4, 6, 12]
@test stepcenters([4, 2, 6]) == [2.0, 5.0, 9.0]
@test stepedges([4, 2, 6]) == [0, 4, 6, 12]
@test select125([1, 2, 4, 6, 8, 10, 13, 16, 18, 20, 40, 60, 80, 100]) == [2, 6, 10, 16, 20, 60, 100]
@test step125.([5, 10, 21.3, 50, 100.1]) == [1, 2, 5, 10, 20]

end

0 comments on commit 7f0a4e2

Please sign in to comment.