ibpmodel package
ibpmodel.ibpcalc module
This module contains the main functions and the auxiliary/control functions needed to calculate the IBP index.
- ibpmodel.ibpcalc.align_time_of_year(day_of_year, month)[source]
Guess day of year and month from each other.
- Parameters
day_of_year (int or ndarray of ints) – Time as the day of year, restricted to
0 < day_of_year <= 356
, with the value 0 meaning it should be calculated based on month (which gives the median day of the month).month (int or ndarray of ints) – Time as the month in the year, with january being month 1, so
0 < month <= 12
.
- Returns
day_of_year (int or ndarray of ints) – A recalculated possible copy of the day_of_year parameter.
month (int or ndarray of ints) – A recalculated copy of the month parameter.
Examples
>>> from ibpmodel import ibpcalc >>> import numpy as np >>> ibpcalc.align_time_of_year(0,6) (166, 6)
>>> ibpcalc.align_time_of_year(162,3) (162, 6)
>>> ibpcalc.align_time_of_year(0,np.arange(12)+1) (array([ 16, 45, 75, 105, 136, 166, 197, 228, 258, 289, 319, 350]), array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))
>>> ibpcalc.align_time_of_year( np.array([0,33,21,17,267,0,115,96,315,0,172,256]),np.arange(12)+1) (array([ 16, 33, 21, 17, 267, 166, 115, 96, 315, 289, 172, 256]), array([ 1, 2, 1, 1, 9, 6, 4, 4, 11, 10, 6, 9]))
- ibpmodel.ibpcalc.checkDoyMonth(day_month)[source]
Control if input is day of the year (int) or abbreviated month name (str).
- Parameters
day_month (int or str or list) – Value to be checked
- Returns
doy_out – list of days of the year
- Return type
list of int(s)
Example
>>> ibpcalc.checkDoyMonth(['Mar',200,1]) [74, 200, 1]
>>> ibpcalc.checkDoyMonth('Dec') [349]
- ibpmodel.ibpcalc.checkParameter(para, para_range)[source]
Check if para or element of para in para_range.
- Parameters
para (int or float or list) – Value to be checked
para_range (range) – searching range
- Returns
Numpy.array contains para.
- Return type
numpy.array
Example
>>> ibpcalc.checkParameter(3,range(0,5)) array([3])
>>> ibpcalc.checkParameter([0,1,2,3,4],range(0,5)) array([0, 1, 2, 3, 4])
- ibpmodel.ibpcalc.compute_lambda(longitude, params, f107, gosc_val, density, month=0)[source]
Computes the ‘lambda’ parameter. Lambda is the intensity, one of the parameters describing the final probability and modeled as a Poisson process.
- Parameters
longitude (float or ndarray of floats) – The longitude(s) of the point(s) we calculate lambda for.
params (array-like) – Parameter values from the model (CDF-file).
f107 (float or ndarray of floats) – The Solar Radio Flux (F10.7 index).
gosc_val (float or ndarray of floats) – result of method fourier_model()
density (ndarray of floats) – Density values from the model (CDF-file).
month (int or ndarray of ints, optional) – The number of months since the year started, meaning January would be 0. The default is 0.
- Return type
float or ndarray of floats
Examples
>>> from ibpmodel import ibpcalc >>> import numpy as np >>> ibpcalc.compute_lambda(1,[-232.54229262, 4.67324294], 123.4, 17.3, np.array([2.1,3.0]) ) 1084.307658528
>>> params = np.array([-232.54229262, 4.67324294, 1.34695254, -1.31448553, 1.09712955]) >>> densi_once = np.sin(np.arange(360)*np.pi/180) * 3 + 5 >>> ibpcalc.compute_lambda(1,[-232.54229262, 4.67324294], 123.4, 17.3, densi_once ) 1788.2556529203105
>>> densi_year = np.array([ (densi_once -3)* np.cos(month*np.pi/6) + 8 for month in range(12)]) >>> ibpcalc.compute_lambda(1,[-232.54229262, 4.67324294], 123.4, 17.3, densi_year, month=5) 1851.5944384882494
>>> months = np.array((np.sin(np.arange(20))+1) % 12, dtype='int') >>> ibpcalc.compute_lambda(1,[-232.54229262, 4.67324294], 123.4, 17.3, densi_year[:,months], month=months) array([2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391, 2149.6915391])
- ibpmodel.ibpcalc.compute_probability(time, expected_bubbles, expected_lifetime, mu, sigma)[source]
Computes the probability of Ionospheric Plasma Bubbles.
- Parameters
time (float or ndarray of floats) – The local time, can be eiter as an array or not.
expected_bubbles (float or ndarray of floats) – The expected amount of bubbles, can be eiter as an array or not.
expected_lifetime (float or ndarray of floats) – The expected lifetime of each bubble, can be eiter as an array or not.
mu (float or ndarray of floats) – The mean position of the probability distribution in the model, can be eiter as an array or not.
sigma (float or ndarray of floats) – The standard deviation of the probability distribution in the model, can be eiter as an array or not.
- Returns
The Ionospheric Bubble Index, value(s) between 0.0 and 1.0, it has the same length as all of the inputs
- Return type
float or ndarray of floats
Note
Plasma Bubbles are large-scale depletions compared to the background ionosphere, occurring in the equatorial F-region, in particular after sunset. They are assumably driven by Rayleigh-Taylor instability and already in the past extensively studied by different techniques, showing occurrence probabilities depending on evironmental parameters as season, location, local time and sun activity.
For a climatologic model of these dependencies, extracted from fairly long time series of distortions in the magnetic field readings of the LEO satellites CHAMP (2000-2010) and Swarm (since 2013) the function calculates a probability density.
Examples
>>> import numpy as np >>> from ibpmodel import ibpcalc >>> ibpcalc.compute_probability(0.0,0.5,0.5,0.5,0.5) 0.049701856965716384
>>> a = np.arange(24)+0.5 >>> ibpcalc.compute_probability(a,a,a,a,a) array([0.12259724, 0.32454412, 0.48001002, 0.5996932 , 0.69182957, 0.76275943, 0.81736377, 0.85940013, 0.89176121, 0.91667393, 0.93585262, 0.95061706, 0.96198326, 0.97073336, 0.9774695 , 0.98265522, 0.98664737, 0.98972067, 0.99208661, 0.99390799, 0.99531015, 0.99638959, 0.99722058, 0.9978603 ])
>>> ibpcalc.compute_probability(a,2*a,1.2,1.3,0.4) array([2.00069488e-02, 7.81272947e-01, 8.55868576e-01, 6.93670227e-01, 4.83704476e-01, 2.96120013e-01, 1.65026216e-01, 8.64714939e-02, 4.35684741e-02, 2.14048463e-02, 1.03395302e-02, 4.93490050e-03, 2.33423700e-03, 1.09629097e-03, 5.11888048e-04, 2.37840684e-04, 1.10040886e-04, 5.07234746e-05, 2.33043267e-05, 1.06755465e-05, 4.87751438e-06, 2.22316484e-06, 1.01112283e-06, 4.58962618e-07])
- ibpmodel.ibpcalc.compute_probability_exp(day_of_year, month, longitude, local_time, f107, data)[source]
Compute the Ionospheric Bubble index. Core routine to return a probability of the occurence of a bubble.
- Parameters
day_of_year (int or ndarray of ints) – Time as the day of year, restricted to
0 < day_of_year <= 356
, with the value 0 meaning it should be calculated based on month (which gives the median day of the month).month (int or ndarray of ints) – Time as the month in the year, with january being month 1,
0 < month <= 12
.longitude (float or ndarray of floats) – The geographical longitude(s),
-180 <= longitude <= 180
.local_time (float or ndarray of floats) – The local time, can be eiter as an array or not,
-6.0 <= local_time <= 24
.f107 (float or ndarray of floats) – The Solar Radio Flux (F10.7 index),
0.0 <= f107 <= 200.0
.data (dict) – Containing the parameters of the model (CDF-file).
- Returns
The Ionospheric Bubble Index, value(s) between 0.0 and 1.0, it has the same length as all of the inputs
- Return type
float or ndarray of floats
Examples
>>> from ibpmodel import ibpcalc >>> import numpy as np >>> data = ibpcalc.read_model_file() >>> ibpcalc.compute_probability_exp(0, 3, 12, 2, 17.3, data) 0.0016535983798842135
>>> ibpcalc.compute_probability_exp(0, 2, 12, 2, 17.3, data) 0.0
>>> parts = ibpcalc.tiler(np.arange(2,5), np.array([12,124]), np.arange(6)) >>> ibpcalc.compute_probability_exp(0, *parts, f107=17.3, data=data) array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 7.24797932e-03, 3.47038779e-03, 1.65359838e-03, 7.87395045e-04, 3.74847713e-04, 1.78430902e-04, 2.71409055e-03, 1.30214944e-03, 6.20242441e-04, 2.95263158e-04, 1.40545020e-04, 6.68965929e-05, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00])
Note
Rearranged/rewritten and optimized by Ask Neve Gamby <aknvg@space.dtu.dk>.
The resolution of the function gosc is higher than monthly. If a day_of_year is known, the results can be more precise.
It is now possible to calculate with either ndarrays or single values, for all parameters except data (which has a special structure). Note that this version is, compared with the initial version more closely resembling the original ‘R’ code, much more efficient due to vectorization.
- ibpmodel.ibpcalc.doyFromMonth(month)[source]
Calculate day of year from the 15th of the month
- Parameters
month (int) – Value as the month in the year, with january being month 1,
1 <= month <= 12
- Returns
Day of year.
- Return type
int
Example
>>> ibpcalc.doyFromMonth(7) 196
- ibpmodel.ibpcalc.fourier_model(coeffients, theta, periode=365.0)[source]
Computes a value based on a model of fourier components up to 2nd degree.
- Parameters
coeffients (array-like of numbers) – The coefficients of the fourier series up to second degree, with even numbers representing cosinus and odd sinus. The shape of coefficients must be (5,*theta.shape).
theta (number or ndarray of numbers) – The part representing the phase in the fourier expansion. It is in the same units as the periode.
periode (number, optional) – The amount of theta need for one periode of the 1st degree of the fourier expansion. Defaults to 365 (the days in a year).
- Returns
The shape of this is equivalent to the shape of theta.
- Return type
number or ndarray of numbers
Examples
>>> from ibpmodel import ibpcalc >>> import numpy as np >>> ibpcalc.fourier_model([0,1,-1,0,0],180) 1.0420963481067607
>>> ibpcalc.fourier_model([0,1,-1,-0.5,0.7],1,periode=10) -0.48044810416758793
>>> ibpcalc.fourier_model([0,1,-1,-0.5,0.7],np.arange(11),10) array([-0.3 , -0.4804481 , -0.218165 , 0.98765424, 2.0886424 , 1.7 , -0.03798462, -1.50224404, -1.53249278, -0.70496209, -0.3 ])
- ibpmodel.ibpcalc.monthFromDoy(doy)[source]
Calculate month from day of the year
- Parameters
doy (int) – Day of the year,
1 <= doy <= 365
.- Returns
Value as the month in the year, with january being month 1.
- Return type
int
Example
>>> ibpcalc.monthFromDoy(275) 10
- ibpmodel.ibpcalc.monthfromString(month_str)[source]
Convert abbreviated month name to int
- Parameters
month_str (str) – Abbreviated month name. [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’]
- Returns
Value as the month in the year, with january being month 1.
- Return type
int
Example
>>> ibpcalc.monthfromString('Mar') 3
- ibpmodel.ibpcalc.read_model_file(file=None)[source]
Load CDF content into a dictionary. If no file is declared, the CDF file included in the package will be used. (SW_TEST_IBP_CLI_2__00000000T000000_99999999T999999_0001.cdf)
- Parameters
file (file path, optional) – Path to cdf file containing parametors for the model. The default is None.
- Returns
Contains the content of the CDF file.
- Return type
dict
- ibpmodel.ibpcalc.tile_aggregate(result, *args, aggregator=numpy.mean)[source]
Compresses tiles and aggregate results on the last axis of tiled ranges
- Parameters
result (numpy.array) – Array that is aggregated.
*args (list or numpy.array) – Along the last element is crompressed.
aggregator (function, optional) – Specifies how to aggregate. the defaults is np.mean.
- Returns
last element is the compressed result
- Return type
list of numpy.array
Example
>>> from ibpmodel import ibpcalc >>> ibpcalc.tile_aggregate(np.array([3,2,3,3,2,1,2,1]), [10,12], [20,21,22,24]) (10, 12, array([2.75, 1.5 ]))
>>> ibpcalc.tile_aggregate(np.array([3,2]), np.array([12]), np.array([20,21])) (12, array([2.5]))
>>> ibpcalc.tile_aggregate( np.array([3,2,2,1,4,2,3,3,1,4,8,5,9,6,7,4,5,2,1,6,7,9,5,7]), [9,10,11], [20,21]), [7,8,5,6]) (array([ 9, 9, 10, 10, 11, 11]), array([20, 21, 20, 21, 20, 21]), array([2. , 3. , 4.5, 6.5, 3.5, 7. ]))
- ibpmodel.ibpcalc.tiler(*args)[source]
Provides mixed combinations of arguments.
Creates copies of the arguments that have length equal to the product of the length of the arguments. This results in an ordered set of all combinations of the individual values from each of the arguements.
- Parameters
*args (array-likes) – Each argument is an array-like of possibly different length.
- Returns
A list of ordered combination of the input arguments.
- Return type
list of array-likes
Examples
>>> from ibpmodel import ibpcalc >>> ibpcalc.tiler([1, 2, 3],['A', 'B']) [array([1, 1, 2, 2, 3, 3]), array(['A', 'B', 'A', 'B', 'A', 'B'], dtype='<U1')]
>>> ibpcalc.tiler([17,13],[1, 2, 3],['A', 'B']) [array([17, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13]), array([1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3]), array(['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'], dtype='<U1')]
ibpmodel.ibpforward module
This module contains the application functions for the calculation of the IBP index as well as the graphical visualization.
- ibpmodel.ibpforward.butterflyData(f107=150)[source]
Calculates the Ionospheric Bubble Propability Index for all months (using the center DOY of each month) and all integer longitudes (resolution of 5 degree) using Local_Time of range -5 to 1 and a fixed value of F10.7. IBP index is then averaged from the Local_Times.
- Parameters
f107 (int, optional) – The Solar Radio Flux (F10.7 index). The default is 150.
- Returns
out_data – [[month],[longitude],[IBP index]].
- Return type
numpy.array
- ibpmodel.ibpforward.calculateIBPindex(day_month=0, longitude=[-180, -175, -170, -165, -160, -155, -150, -145, -140, -135, -130, -125, -120, -115, -110, -105, -100, -95, -90, -85, -80, -75, -70, -65, -60, -55, -50, -45, -40, -35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175], local_time=numpy.arange, f107=150)[source]
Calculates the Ionospheric Bubble propability index based on the input parameters. Returns a pandas.DataFrame with input parameters and IBP index.
- Parameters
day_month (int or str or list, optional) – Day of year (int) or the month of the year (str). int: Day of the year,
0 <= doy <= 365
. The value 0 means it should be calculated based on every month. str: Abbreviated month name. [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’] The default is 0.longitude (int or list of ints, optional) – The geographical longitude(s),
-180 <= longitude <= 180
. The default is list(range(-180,181,5)).local_time (int or float or list, optional) – The local time,
-6.0 <= local_time <= 24
. The default is np.arange(-6,6.1,0.1).f107 (int or float or list, optional) – The Solar Radio Flux (F10.7 index),
0.0 <= f107 <= 200.0
. The default is 150.
- Returns
df – contains the columns: Doy (Day(s) of the year), Month (Month(s) from the day of the year), Lon (Longitude(s)), LT (Local Time(s)), F10.7 (solar index(es)), IBP (Ionospheric Bubble Index, value(s) between 0.0 and 1.0).
- Return type
pandas.DataFrame
- ibpmodel.ibpforward.plotButterflyData(f107=150, getFig=False)[source]
Create a contour plot of the result from function butterflyData().
- Parameters
f107 (int, optional) – The Solar Radio Flux (F10.7 index). The default is 150.
getFig (bool, optional) – True: return matplotlib.axes, False: show picture. The default is False.
- Return type
matplotlib.axes or bool
- ibpmodel.ibpforward.plotIBPindex(doy, f107=150, getFig=False)[source]
Create a contour plot of IBP index for the given day. The resolution along the longitude is 5 degree. Local time spans from 6 pm to 6 am with a resolution of 0.1 hours.
- Parameters
doy (int) – Day of the year.
f107 (int, optional) – The Solar Radio Flux (F10.7 index). The default is 150.
getFig (bool, optional) – True: return matplotlib.axes, False: show picture. The default is False.
- Return type
matplotlib.axes or bool