Skip to content

Commit abcea4c

Browse files
committed
280225 commit
1 parent ef1066d commit abcea4c

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FittingFunction"
22
uuid = "7c8a6357-aefd-4570-aae0-a8cd991d38f9"
33
authors = ["Stefano Covino <stefano.covino@inaf.it> and contributors"]
4-
version = "0.14.0"
4+
version = "0.15.0"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/FittingFunction.jl

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export Gaussian
2424
export GetAtomicData
2525
export Jy2Ecm2sA
2626
export Mag2Counts
27+
export NorrisPulse
2728
export PL
2829
export Pol2Stokes
2930
export SBPL
@@ -221,7 +222,7 @@ Compute the discrete Fourier periodogram for the inpout signal.
221222
222223
- `signal` array of input data.
223224
- `fs` sampling in frequency of the input data (1/dt).
224-
- 'zerofreq' is true (false) to (not) include the zero frequency in the output.
225+
- 'zerofreq' is true (false) to (not) include the zero frequency in the output.
225226
226227
Outputs are two arrays: the frequencies and the powers.
227228
@@ -420,6 +421,64 @@ end
420421

421422

422423

424+
425+
"""
426+
NorrisPulse(x;pulsNorm,tmax,σ_rise,σ_decay,pulsSharpness,base)
427+
428+
Compute an asymmetric pulse shape according to the recipe reported in [Norris et al. (1996).](https://ui.adsabs.harvard.edu/abs/1996ApJ...459..393N/abstract).
429+
430+
# Arguments
431+
432+
- `x` input vector.
433+
- `pulsNorm` the nornalization of the pulse.
434+
- `tmax` the maximum of the pulse.
435+
- `σ_rise` the time-scale of the rising phase.
436+
- `σ_decay` the time-scale of the decaying phase.
437+
- `pulsSharpness` pulse sharpness parameter.
438+
- `base` signal level without the pulse.
439+
440+
441+
# Examples
442+
```jldoctest
443+
444+
NorrisPulse([1.,2.,3.,4.,5.],pulsNorm=1.5,tmax=3.,σ_rise=1.,σ_decay=2.,pulsSharpness=1.1,base=0.3)
445+
446+
# output
447+
448+
5-element Vector{Float64}:
449+
0.47585740398559895
450+
0.8518191617571635
451+
1.8
452+
1.2407748943132098
453+
0.8518191617571635
454+
```
455+
"""
456+
function NorrisPulse(x;pulsNorm,tmax,σ_rise,σ_decay,pulsSharpness,base)
457+
#
458+
f1(x) = base .+ pulsNorm .* exp.(-((abs.(x .- tmax)) ./ σ_rise).^pulsSharpness)
459+
f2(x) = base .+ pulsNorm .* exp.(-((abs.(x .- tmax)) ./ σ_decay).^pulsSharpness)
460+
#
461+
fv = [f1,f2]
462+
#
463+
return piecewise(x,[tmax,],fv)
464+
end
465+
466+
467+
468+
function piecewise(x::Float64, breakpts::Vector{Float64}, f::Vector{Function})
469+
@assert(issorted(breakpts))
470+
@assert(length(f) == length(breakpts)+1)
471+
b = searchsortedfirst(breakpts, x)
472+
return f[b](x)
473+
end
474+
475+
piecewise(X::Vector{Float64}, bpts, f) = [piecewise(x,bpts,f) for x in X ]
476+
477+
478+
479+
480+
481+
423482
"""
424483
PL(E,N,α;E0=1.)
425484

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ using Test
5050
#
5151
@test Z2N([1.,0.5,0.25], [1.,2.,2.5,3.5,5.]) == [0.4, 0.4000000000000002, 0.537258300203048]
5252
#
53+
@test NorrisPulse([1.,2.,3.,4.,5.],pulsNorm=1.5,tmax=3.,σ_rise=1.,σ_decay=2.,pulsSharpness=1.1,base=0.3) == [0.47585740398559895, 0.8518191617571635, 1.8, 1.2407748943132098, 0.8518191617571635]
54+
#
5355
end

0 commit comments

Comments
 (0)