AniMAIRE


NameAniMAIRE JSON
Version 1.1.5 PyPI version JSON
download
home_pagehttps://github.com/ssc-maire/AniMAIRE-public
SummaryPython library for running the anisotropic version of MAIRE+
upload_time2024-04-22 10:42:52
maintainerNone
docs_urlNone
authorChris S. W. Davis
requires_pythonNone
licenseGNU General Public License v3.0
keywords anisotropic maire+ atmospheric ionizing radiation dose rates cosmic rays ground level enhancements gles protons alpha particles neutrons effective ambient equivalent aircraft aviation earth solar system sun space magnetic field
VCS
bugtrack_url
requirements numpy wheel pandarallel pandas ParticleRigidityCalculationTools scipy setuptools spacepy tqdm plotly numba metpy CosRayModifiedISO AsympDirsCalculator seaborn geopandas joblib spaceweather atmosphericRadiationDoseAndFlux
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![The AniMAIRE logo](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/AniMAIRE_logo.svg)

A Python toolkit for calculating dose rates and aircraft electronics upset rates in Earth's atmosphere based on any incoming proton or alpha particle spectra, with any pitch angle distribution. 

**N.B. Currently this tool only runs on Linux-based machines (not on Windows) and requires a copy of [MAGNETOCOSMICS](http://cosray.unibe.ch/~laurent/magnetocosmics/) to be installed.**

If you use this software for scientific research, please reference AniMAIRE as **C. S. W. Davis, F. Lei, F. Baird, K. Ryden and C. Dyer (2023). AniMAIRE version {version number}. https://github.com/ssc-maire/AniMAIRE-public , https://pypi.org/project/AniMAIRE/ . Surrey Space Center, University of Surrey.**. A scientific paper about this software is currently in production.

You can use AniMAIRE to produce dose rate data and maps throughout large space weather events and plot them like this:

<img src="https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp1_with_legend.svg" width="350"/> <img src="https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp5_with_legend.svg" width="350"/> 

Feel free to contribute to this package through forks and pull requests; the package is intended for usage and potential modification by the community. If you have any questions about this software, please contact myself, https://github.com/ChrisSWDavis, the primary author of this package.

<!-- ![An example map of dose rates during a large space weather event](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp1_with_legend.svg) | ![An example animation of dose rates during a large space weather event](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/39kft_heatmap_animation_no_contours_anisotropic.gif) -->

## Installation

To install this toolkit using the common pip Python method, run

```
pip install AniMAIRE
```

Otherwise, to install this toolkit from this Github repository, first clone this repository to your local system, and then from the cloned respository, run

```
sudo pip3 install .
```

in the cloned directory. 

Note that there are quite a few sizeable data files within some of the dependencies for this package that get copied during installation (on the order of about several hundred megabytes in total) so installation may take a couple of minutes.

**To use this package you must have a version of magnetocosmics installed, such that magnetocosmics can be run by typing 'magnetocosmics' the terminal, i.e. typing:**

```
$ magnetocosmics
```
outputs something like the following:
```


          ################################
          !!! G4Backtrace is activated !!!
          ################################


**************************************************************
 Geant4 version Name: geant4-11-00-patch-02 [MT]   (25-May-2022)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************

/h n m 1900.0 1905.0 1910.0 1915.0 1920.0 1925.0 1930.0 1935.0 1940.0 1945.0 1950.0 1955.0 1960.0 1965.0 1970.0 1975.0 1980.0 1985.0 1990.0 1995.0   2000.0    2005.0    2010.0    2015.0   2020.0    SV
mmm1900
Nyear 25
1900
Nyear 25

...

g       8       8
h       8       8
g       9       0
0.0     0       -999
XGSE in GEI (0.193332,-0.900173,-0.39027)
(0.0573796,-0.172205,0.983389)
-19.4809
Selected index20
XGSE in GEI (0.17509,-0.903305,-0.391643)
(0.0590434,-0.175608,0.982688)
-25.9091
Test93
Test97
Test
G4CashKarpRKF45 is called
```

Feel free to contribute to this package through forks and pull requests; the package is intended for usage and potential modification by the community. If you have any questions about this software, please contact myself, [https://github.com/ChrisSWDavis](https://github.com/ChrisSWDavis), the primary author of this package. 

While this package is new, it fundamentally relies on Magnetocosmics through the [AsympDirsCalculator package](https://github.com/ssc-maire/AsymptoticDirectionsCalculator-public), and it is likely that the community will eventually create a successor for Magnetocosmics. One attempt to do this is the [OTSO software](https://github.com/NLarsen15/OTSO), which is also designed to be open-source and community oriented. We hope that in the future, AniMAIRE could be integrated with OTSO. 

## Usage

After installation, to import the toolkit into a particular Python script, run 
```
from AniMAIRE import AniMAIRE
```
All of the main useful functions are contained within this `AniMAIRE` module, and all other modules contained in this toolkit are primarily intended to be accessed internally (although don't let that stop you from using or editing them for your own purposes if you wish).

The rest of the README file describes how to run AniMAIRE to produce dose rates for different input parameters. You can also look at and run the examples present in the `AniMAIRE_examples.ipynb` notebook, and the advanced examples in the `notebooks_and_data_and_figures_for_paper/GLE71_plots_for_paper.ipynb` notebook to learn and see in practice how AniMAIRE can be used.

## Testing that AniMAIRE is working

To test that AniMAIRE works, you can run:

```
from AniMAIRE import AniMAIRE
import datetime as dt

test_isotropic_dose_rates = AniMAIRE.run_from_spectra(
        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),
        Kp_index=3,
        date_and_time=dt.datetime(2006, 12, 13, 3, 0),
        array_of_lats_and_longs=[[65.0,25.0]],
)
```

in Python. This should produce some dose rates as output to `test_isotropic_dose_rates` in the format (the meaning of each column is explained later on in this README, under the "Simple isotropic runs and plotting" heading):

```
    latitude  longitude  altitude (km)      edose      adose      dosee       tn1       tn2       tn3           SEU           SEL
0       65.0       25.0         0.0000   0.010434   0.012526   0.010010  0.004431  0.002726  0.001826  2.725682e-16  2.725682e-11
1       65.0       25.0         3.0480   0.101553   0.117294   0.085010  0.051717  0.033506  0.022912  3.350616e-15  3.350616e-10
2       65.0       25.0         6.0960   0.669389   0.736989   0.456343  0.324250  0.210297  0.144131  2.102967e-14  2.102967e-09
3       65.0       25.0         7.6200   1.432404   1.525608   0.966025  0.658130  0.426616  0.292777  4.266156e-14  4.266156e-09
4       65.0       25.0         8.5344   2.147704   2.220632   1.416257  0.950846  0.614894  0.422072  6.148938e-14  6.148938e-09
5       65.0       25.0         9.4488   3.108676   3.124392   2.063826  1.319292  0.854931  0.586036  8.549315e-14  8.549315e-09
6       65.0       25.0        10.3632   4.377677   4.263813   2.692120  1.767081  1.142345  0.782749  1.142345e-13  1.142345e-08
7       65.0       25.0        11.2776   5.993970   5.643631   3.764450  2.292849  1.480059  1.010255  1.480059e-13  1.480059e-08
8       65.0       25.0        12.1920   7.953998   7.262904   5.017846  2.881359  1.850446  1.263386  1.850446e-13  1.850446e-08
9       65.0       25.0        13.1064  10.414874   9.115408   6.247418  3.514676  2.249009  1.532907  2.249009e-13  2.249009e-08
10      65.0       25.0        14.0208  13.242733  11.101641   7.800097  4.184576  2.665499  1.810092  2.665499e-13  2.665499e-08
11      65.0       25.0        14.9352  16.603692  13.430864   9.571582  4.865316  3.082233  2.086676  3.082233e-13  3.082233e-08
12      65.0       25.0        15.8496  20.842479  15.942018  11.573518  5.568722  3.503950  2.361370  3.503950e-13  3.503950e-08
13      65.0       25.0        16.7640  25.482167  18.658393  13.926003  6.254882  3.914514  2.628245  3.914514e-13  3.914514e-08
14      65.0       25.0        17.6784  31.020574  21.767530  16.937656  6.902852  4.295149  2.869582  4.295149e-13  4.295149e-08
15      65.0       25.0        18.5928  37.203113  24.734609  19.638953  7.495669  4.637948  3.081391  4.637948e-13  4.637948e-08
```

## Calculating dose rates at any location in Earth's atmosphere

The primary function for performing a run to calculate dose rates in `AniMAIRE` is the `run_from_spectra` function, which has the format:

```
def run_from_spectra(
        proton_rigidity_spectrum=None,
        alpha_rigidity_spectrum=None,
        reference_pitch_angle_latitude=None,
        reference_pitch_angle_longitude=None,
        proton_pitch_angle_distribution=isotropicPitchAngleDistribution(),
        alpha_pitch_angle_distribution=isotropicPitchAngleDistribution(),
        altitudes_in_kft=[0,10,20] + [i for i in range(25, 61 + 1, 3)],
        altitudes_in_km=None,
        Kp_index=None,
        date_and_time=dt.datetime.now(),
        array_of_lats_and_longs=default_array_of_lats_and_longs,
        array_of_zeniths_and_azimuths=np.array([[0.0, 0.0]]),
        cache_magnetocosmics_run=True,
        generate_NM_count_rates=False,
        use_default_9_zeniths_azimuths=False,
        **mag_cos_kwargs
)
```

`run_from_spectra` performs a run at a single date and time and Kp index to calculate dose rates across Earth's atmosphere based on proton, alpha particle, or proton + alpha particle spectra. **Particle spectra here must be described in units of cm-2 s-1 sr-1 (GV/n)-1, and with respect to rigidity in units of GV**.

Particle spectra and pitch angle distributions can be set as any 'callable' object in Python, i.e., a function, as shown in examples below. At least one particle spectrum must be specified, as well as a Kp index, so this function to execute successfully. For runs designed to simulate dose rates during particular dates and times, the argument `date_and_time` must also be supplied with a Python `datetime` corresponding to the timestamp being investigated (by default, the function assumes that the current date and time should be used).

Note that while this function can optionally take an alpha particle spectrum as an input, it actually interpolates the dose rates due to alpha particles to those of heavier ions too, so outputted dose rates due to an alpha particle spectrum are in fact the combined total of all ions heavier than protons.

Several types of runs can be performed with AniMAIRE; for instance, only vertical asymptotic directions are used to calculate dose rates by default. You can optionally set `use_default_9_zeniths_azimuths` to `True` to use the mean of nine different asymptotic directions to calculate dose rates, as was done by [Cramp et al. (1997)](https://doi.org/10.1029/97JA01947), to calculate dose rates during particularly complex events (note that this means calculations will take approximately nine times longer). You can also manually set your own choice of asymptotic directions for taking the average using the `array_of_zeniths_and_azimuths` variable.

`AniMAIRE` performs runs of the MAGNETOCOSMICS as part of dose rate calculations (using the [AsympDirsCalculator](https://github.com/ssc-maire/AsymptoticDirectionsCalculator) package), and these currently take up by far the majority of `AniMAIRE` runtime - on the order of over half an hour on the developer's computer versus less than 6 minutes for the rest of the program. Therefore if the `cache_magnetocosmics_run` argument is set to `True`, which it is by default, `AniMAIRE` will cache the results of MAGNETOCOSMICS simulations in the directory that `AniMAIRE` is run from in the generated `cachedMagnetocosmicsRunData` and `cacheAsymptoticDirectionOutputs` directories. This significantly speeds up any tasks where users wish to investigate a constant `Kp_index` and `date_and_time`, but wish to vary the spectrum and pitch angle distribution and investigate how dose rates are impacted, as magnetocosmics runs are only performed once. 

You can pass settings and variables to `AsympDirsCalculator` through adding additional keyword arguments to `run_from_spectra` with the same names as the arguments given on the [AsympDirsCalculator Github page](https://github.com/ssc-maire/AsymptoticDirectionsCalculator). These settings and variable get assigned to the `**mag_cos_kwargs` object, and passed to `AsympDirsCalculator` by `AniMAIRE`.

### Simple isotropic runs and plotting

A basic run of the `run_from_spectra` function might look like this:

```
from AniMAIRE import AniMAIRE
import datetime as dt

test_isotropic_dose_rates = AniMAIRE.run_from_spectra(
        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),
        Kp_index=3,
        date_and_time=dt.datetime(2006, 12, 13, 3, 0),
)
```

in this example, the proton rigidity spectrum is set to be a power law with a normalisation factor of 2.56 cm-2 s-1 sr-1 (GV/n)-1, and a spectral index of 3.41, using the commonly used `lambda` approach to create a function within a single line. Kp index is set to be 3, and the date and time to simulate are set to be 13th of December 2006, 03:00. This function will likely take at least several minutes to run, depending on the speed of the machine and number of cores, and should output a Pandas DataFrame to `test_isotropic_dose_rates`, giving:

```
	latitude	longitude	altitude (km)	edose	adose	dosee	tn1	tn2	tn3	SEU	SEL
0	-90.0	0.0	0.0000	0.010442	0.012540	0.010010	0.004437	0.002729	0.001828	2.729229e-16	2.729229e-11
1	-90.0	0.0	3.0480	0.101786	0.117658	0.085755	0.051895	0.033617	0.022979	3.361684e-15	3.361684e-10
2	-90.0	0.0	6.0960	0.672702	0.742332	0.457695	0.326731	0.211853	0.145046	2.118530e-14	2.118530e-09
3	-90.0	0.0	7.6200	1.442377	1.541670	0.975436	0.665785	0.431261	0.295516	4.312608e-14	4.312608e-09
4	-90.0	0.0	8.5344	2.165860	2.249419	1.426324	0.964791	0.623291	0.426927	6.232913e-14	6.232913e-09
...	...	...	...	...	...	...	...	...	...	...	...
42619	90.0	355.0	14.9352	16.953199	14.033322	9.762795	5.138425	3.234975	2.164808	3.234975e-13	3.234975e-08
42620	90.0	355.0	15.8496	21.327714	16.796347	11.858681	5.949880	3.711156	2.463976	3.711156e-13	3.711156e-08
42621	90.0	355.0	16.7640	26.122787	19.802434	14.318360	6.759204	4.182604	2.757482	4.182604e-13	4.182604e-08
42622	90.0	355.0	17.6784	31.856083	23.278901	17.431863	7.562120	4.638132	3.029771	4.638132e-13	4.638132e-08
42623	90.0	355.0	18.5928	38.265701	26.680896	20.232603	8.340509	5.067928	3.275415	5.067928e-13	5.067928e-08
```

when `test_isotropic_dose_rates` is printed.

The outputted dose rate (or flux) labels represent the following dose rate/flux types:

|label | dose rate/flux type|
|------|--------------------|
|adose| ambient dose equivalent in µSv/hr |
|edose| effective dose in µSv/hr |
|dosee| dose equivalent in µSv/hr |
|tn1| >1 MeV neutron flux, in n/cm2/s |
|tn2| >10 MeV neutron flux, in n/cm2/s |
|tn3| >60 MeV neutron flux, in n/cm2/s |
|SEU| single event upset rate for an SRAM device in upsets/second/bit |
|SEL| single event latch-up rate for an SRAM device in latch-ups/second/device |

These dose rates are produced by default at every latitude and longitude corresponding to 5 by 5 degree intervals across Earth's surface, and for altitudes of 0 kilofeet, 10 kilofeet, 20 kilofeet and between 25 kilofeet and 61 kilofeet at intervals of 3 kilofeet. This can be altered using the `altitudes_in_kft`, `altitudes_in_km` and `array_of_lats_and_longs`. 

Any particular altitudes the user wants to use can be supplied to `altitudes_in_kft` or `altitudes_in_km` as a `list` or numpy array. 

If you want to perform calculations only at a specific set of latitudes and longitudes you should use the `array_of_lats_and_longs` argument, supplying it as a 2 dimensional `list` or numpy array, where the first column refers to latitudes and the second column refers to longitudes. All longitudes in this case should be specified in terms of longitude east (i.e. 0.00 degrees - 359.99 degrees). **Using the `array_of_lats_and_longs` argument significantly speeds up the running of `AniMAIRE` if you're only interested in a small number of coordinates, so its use is highly recommended in those situations.**

There are many ways you could plot this data. Several example functions,`plot_dose_map` and `create_single_dose_map_plotly`, have been supplied in `AniMAIRE` that uses matplotlib or plotly to plot the dose rates across Earth (i.e. as a function of latitude and longitude) at a given altitude. Both of these functions are available in the `dose_plotting` submodule supplied with AniMAIRE. Their specifications are the following:
```
def plot_dose_map(map_to_plot,
                  plot_title=None,
                  plot_contours=True,
                  levels=3,
                    **kwargs)
```
for matplotlib plots, where map_to_plot is the Pandas DataFrame outputted by a run of `AniMAIRE`, with only one altitude selected. `plot_contours` can be switched on or off to control whether contours are added to the plot, and `levels` can be used to specify to number of contours and/or dose rates for the contours to correspond to. `hue_range` can also be supplied with a 2-value tuple to specify the limits of the colorbar to be plotted with the plot. 

To generate a plotly plot, you can run
```
def create_single_dose_map_plotly(DF_to_use,
                                selected_altitude_in_km)
```
where `DF_to_use` is the Pandas DataFrame outputted by a run of `AniMAIRE` and altitude is one of the altitudes in kilometers supplied to/outputted by the run.

To use the matplotlib function to create a map of the isotropic situation as given as an example above, you could run 
```
from AniMAIRE import dose_plotting
import matplotlib.pyplot as plt

dose_plotting.plot_dose_map(test_isotropic_dose_rates.query("`altitude (km)` == 12.1920"),
                                         hue_range=(0,9))

plt.show()
```

which should plot the following figure as a matplotlib plot:
![isotropic_test_plot](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Isotropic_40kft_example.svg)

and assign the plot to the `isotropic_dose_rate_map` variable for the user to use as they wish.

### Anisotropic runs

`run_from_spectra` defaults to an isotropic spectrum if no pitch angle distribution is supplied for either protons or alpha particles by the user.  

To run an anisotropic spectrum, differential pitch angle distributions must be supplied to the `proton_pitch_angle_distribution` and/or `alpha_pitch_angle_distribution` arguments in `run_from_spectra` along with a reference location specified in terms of latitude and longitude in the `reference_pitch_angle_latitude` and `reference_pitch_angle_longitude` arguments respectively. The pitch angle distributions must be supplied as 2 dimensional functions, where the first argument is the pitch angle, and the second argument is particle rigidity (in many cases the pitch angle distribution might not depend on rigidity, but for programmatic reasons the function must at least take in rigidity as an argument although it does not need to have a dependence on it). The pitch angle here must be specified in units of **radians**.

`reference_pitch_angle_latitude` and `reference_pitch_angle_longitude` are the reference latitude and longitude in GEO coordinates representing a pitch angle of 0 in the supplied pitch angle distribution used. `AniMAIRE` currently makes the assumption that incoming particle distributions are cylindrically symmetric about this reference direction, and therefore that only the pitch angle with respect to this latitude and longitude are required to calculate dose rates anisotropically across Earth. Incoming solar particle events are frequently oriented near to the direction of the Interplanetary Magnetic Field (IMF), so you could specify pitch angles relative to the IMF here, and use the latitude and longitude of the IMF as the reference latitude and longitude.

The pitch angle distributions and rigidity spectrum must be specified in units normalised such that the product of the pitch angle distribution and rigidity spectrum multiplied together is in units of **cm-2 s-1 sr-1 (GV/n)-1**. 

The pitch angle distributions can be specified using the Python `lambda` as with the rigidity spectra, but with 2 dimensions rather than 1. For example, to specify a Gaussian pitch angle distribution you could use:

```
import numpy as np

sigma = np.sqrt(0.19)

test_pitch_angle_dist_function = lambda pitch_angle,rigidity:np.exp(-(pitch_angle**2)/(sigma**2))
```
where `sigma` here has arbitrarily been chosen to be the square root of 0.19 for example purposes. 

here `pitch_angle_dist_function` would be a viable input as a pitch angle distribution to `run_from_spectra`. While the function itself does not depend on `rigidity`, `rigidity` is specified as the second argument of the function nonetheless, as required for calculations to work.

An example of using this might be:

```
import numpy as np
from AniMAIRE import AniMAIRE
import datetime as dt

sigma = np.sqrt(0.19)
pitch_angle_reference_latitude = -17.0
pitch_angle_reference_longitude = 148.0

test_pitch_angle_dist_function = lambda pitch_angle,rigidity:np.exp(-(pitch_angle**2)/(sigma**2))

test_anisotropic_dose_rates = AniMAIRE.run_from_spectra(
        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),
        proton_pitch_angle_distribution=test_pitch_angle_dist_function,
        reference_pitch_angle_latitude=pitch_angle_reference_latitude,reference_pitch_angle_longitude=pitch_angle_reference_longitude,
        Kp_index=3,
        date_and_time=dt.datetime(2006, 12, 13, 3, 0),
)
```

when run this should output a Pandas DataFrame to `test_anisotropic_dose_rates` with the same general output format as given in the previously described isotropic dose rates case. 

In this case printing `test_anisotropic_dose_rates` should output:
```
	latitude	longitude	altitude (km)	edose	adose	dosee	tn1	tn2	tn3	SEU	SEL
0	-90.0	0.0	0.0000	1.976895e-07	2.027961e-07	3.222401e-07	1.286575e-08	7.877480e-09	5.401425e-09	7.877480e-22	7.877480e-17
1	-90.0	0.0	3.0480	4.838923e-07	4.869626e-07	7.032983e-07	7.429541e-08	4.866265e-08	3.410940e-08	4.866265e-21	4.866265e-16
2	-90.0	0.0	6.0960	1.453834e-06	1.411544e-06	2.045308e-06	2.472576e-07	1.611648e-07	1.136527e-07	1.611648e-20	1.611648e-15
3	-90.0	0.0	7.6200	2.352658e-06	2.382057e-06	3.304989e-06	3.720997e-07	2.420436e-07	1.708843e-07	2.420436e-20	2.420436e-15
4	-90.0	0.0	8.5344	2.970462e-06	2.791970e-06	4.201789e-06	4.473736e-07	2.919136e-07	2.063902e-07	2.919136e-20	2.919136e-15
...	...	...	...	...	...	...	...	...	...	...	...
42619	90.0	355.0	14.9352	1.062397e-06	7.975138e-07	5.902218e-07	2.766678e-07	1.764588e-07	1.216189e-07	1.764588e-20	1.764588e-15
42620	90.0	355.0	15.8496	1.289216e-06	9.183397e-07	6.964574e-07	3.063998e-07	1.945207e-07	1.338582e-07	1.945207e-20	1.945207e-15
42621	90.0	355.0	16.7640	1.525359e-06	1.040969e-06	8.062018e-07	3.339381e-07	2.112220e-07	1.452375e-07	2.112220e-20	2.112220e-15
42622	90.0	355.0	17.6784	1.777447e-06	1.163693e-06	9.297615e-07	3.568426e-07	2.248452e-07	1.543556e-07	2.248452e-20	2.248452e-15
42623	90.0	355.0	18.5928	2.036052e-06	1.275021e-06	1.040287e-06	3.755276e-07	2.357292e-07	1.614028e-07	2.357292e-20	2.357292e-15
```

which will produce the following plot when
```
from AniMAIRE import dose_plotting
import matplotlib.pyplot as plt

dose_plotting.plot_dose_map(test_anisotropic_dose_rates.query("`altitude (km)` == 12.1920"),
                                         hue_range=(0,9))

plt.show()
```
is run, as was described previously in this README for isotropic plotting:

![anisotropic_test_plot](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Anisotropic_40kft_example.svg)


you can also produce similar plotly plots if you prefer plotly to matplotlib using:
```
from AniMAIRE import dose_plotting

anisotropic_dose_rate_map = dose_plotting.create_single_dose_map_plotly(test_anisotropic_dose_rates,
                            			      selected_altitude_in_km = 12.1920)
```
which generates the following plot:

![anisotropic_test_plot](https://user-images.githubusercontent.com/16866485/223751057-5d0cff98-cf9e-4654-b71f-d1ae55c75602.png)

### Functions for running `AniMAIRE` for specific situations and for a past timestamp

In addition to the quite general `run_from_spectra` function, `AniMAIRE` currently contains several functions for running calculations for specific types of spectra and situations, to make it easier for users to perform runs without having to determine and feed in spectra to `run_from_spectra` themselves.

The `run_from_DLR_cosmic_ray_power_law` function allows users to run full atmospheric dose rate calculations (for cosmic ray only/'quiet' time periods only) from just a date and time, or alternatively from just a single OULU count rate, or just a value of 'W parameter', as well as Kp index. This function utilises the [CosRayModifiedISO package](https://github.com/ssc-maire/CosRayModifiedISO) to determine the spectra due to protons and alpha particles during cosmic ray only time periods, and then runs `run_from_spectra` using both of those spectra under isotropic conditions. The specifications of `run_from_DLR_cosmic_ray_power_law` are:

```
def run_from_DLR_cosmic_ray_model(OULU_count_rate_in_seconds=None,
                                      W_parameter=None,
                                      Kp_index=None,
				      date_and_time=None,
                                      **kwargs)
```

`**kwargs` here can be used to supply any arguments you wish to `run_from_spectra` as specified previously, such as the list of altitudes and list of coordinates to perform calculations for. Details on what `OULU_count_rate_in_seconds` and `W_parameter` mean can be found at https://github.com/ssc-maire/CosRayModifiedISO . If either `OULU_count_rate_in_seconds` or `W_parameter` are used, only one of them should be specified. Otherwise, `AniMAIRE` will determined their values using the `date_and_time` parameter supplied.

In addition to running from the DLR-ISO isotropic cosmic ray model, you can also run `AniMAIRE` from a combined power law rigidity spectrum and Gaussian pitch angle distribution. This can be done using the `run_from_power_law_gaussian_distribution` function:

```
def run_from_power_law_gaussian_distribution(J0, gamma, deltaGamma, sigma, 
                                             reference_pitch_angle_latitude, reference_pitch_angle_longitude, 
                                             Kp_index,date_and_time,
                                             **kwargs)
```

Here `J0`, `gamma`, `deltaGamma`, `sigma`, `reference_pitch_angle_latitude`, `reference_pitch_angle_longitude` are all defined as specified in the format of papers like [Mishev, A., Usoskin, I. Analysis of the Ground-Level Enhancements on 14 July 2000 and 13 December 2006 Using Neutron Monitor Data. Sol Phys 291, 1225–1239 (2016). https://doi.org/10.1007/s11207-016-0877-2](https://link.springer.com/article/10.1007/s11207-016-0877-2).







            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ssc-maire/AniMAIRE-public",
    "name": "AniMAIRE",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "anisotropic MAIRE+ atmospheric ionizing radiation dose rates cosmic rays ground level enhancements GLEs protons alpha particles neutrons effective ambient equivalent aircraft aviation Earth solar system sun space magnetic field",
    "author": "Chris S. W. Davis",
    "author_email": "ChrisSWDavis@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/46/f5/c975b038f1959c16bb553710d2d409d953e59fc78791ff458ce1e9ba639e/animaire-1.1.5.tar.gz",
    "platform": null,
    "description": "![The AniMAIRE logo](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/AniMAIRE_logo.svg)\n\nA Python toolkit for calculating dose rates and aircraft electronics upset rates in Earth's atmosphere based on any incoming proton or alpha particle spectra, with any pitch angle distribution. \n\n**N.B. Currently this tool only runs on Linux-based machines (not on Windows) and requires a copy of [MAGNETOCOSMICS](http://cosray.unibe.ch/~laurent/magnetocosmics/) to be installed.**\n\nIf you use this software for scientific research, please reference AniMAIRE as **C. S. W. Davis, F. Lei, F. Baird, K. Ryden and C. Dyer (2023). AniMAIRE version {version number}. https://github.com/ssc-maire/AniMAIRE-public , https://pypi.org/project/AniMAIRE/ . Surrey Space Center, University of Surrey.**. A scientific paper about this software is currently in production.\n\nYou can use AniMAIRE to produce dose rate data and maps throughout large space weather events and plot them like this:\n\n<img src=\"https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp1_with_legend.svg\" width=\"350\"/> <img src=\"https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp5_with_legend.svg\" width=\"350\"/> \n\nFeel free to contribute to this package through forks and pull requests; the package is intended for usage and potential modification by the community. If you have any questions about this software, please contact myself, https://github.com/ChrisSWDavis, the primary author of this package.\n\n<!-- ![An example map of dose rates during a large space weather event](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Ani_GLE_only_timestamp1_with_legend.svg) | ![An example animation of dose rates during a large space weather event](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/39kft_heatmap_animation_no_contours_anisotropic.gif) -->\n\n## Installation\n\nTo install this toolkit using the common pip Python method, run\n\n```\npip install AniMAIRE\n```\n\nOtherwise, to install this toolkit from this Github repository, first clone this repository to your local system, and then from the cloned respository, run\n\n```\nsudo pip3 install .\n```\n\nin the cloned directory. \n\nNote that there are quite a few sizeable data files within some of the dependencies for this package that get copied during installation (on the order of about several hundred megabytes in total) so installation may take a couple of minutes.\n\n**To use this package you must have a version of magnetocosmics installed, such that magnetocosmics can be run by typing 'magnetocosmics' the terminal, i.e. typing:**\n\n```\n$ magnetocosmics\n```\noutputs something like the following:\n```\n\n\n          ################################\n          !!! G4Backtrace is activated !!!\n          ################################\n\n\n**************************************************************\n Geant4 version Name: geant4-11-00-patch-02 [MT]   (25-May-2022)\n                       Copyright : Geant4 Collaboration\n                      References : NIM A 506 (2003), 250-303\n                                 : IEEE-TNS 53 (2006), 270-278\n                                 : NIM A 835 (2016), 186-225\n                             WWW : http://geant4.org/\n**************************************************************\n\n/h n m 1900.0 1905.0 1910.0 1915.0 1920.0 1925.0 1930.0 1935.0 1940.0 1945.0 1950.0 1955.0 1960.0 1965.0 1970.0 1975.0 1980.0 1985.0 1990.0 1995.0   2000.0    2005.0    2010.0    2015.0   2020.0    SV\nmmm1900\nNyear 25\n1900\nNyear 25\n\n...\n\ng       8       8\nh       8       8\ng       9       0\n0.0     0       -999\nXGSE in GEI (0.193332,-0.900173,-0.39027)\n(0.0573796,-0.172205,0.983389)\n-19.4809\nSelected index20\nXGSE in GEI (0.17509,-0.903305,-0.391643)\n(0.0590434,-0.175608,0.982688)\n-25.9091\nTest93\nTest97\nTest\nG4CashKarpRKF45 is called\n```\n\nFeel free to contribute to this package through forks and pull requests; the package is intended for usage and potential modification by the community. If you have any questions about this software, please contact myself, [https://github.com/ChrisSWDavis](https://github.com/ChrisSWDavis), the primary author of this package. \n\nWhile this package is new, it fundamentally relies on Magnetocosmics through the [AsympDirsCalculator package](https://github.com/ssc-maire/AsymptoticDirectionsCalculator-public), and it is likely that the community will eventually create a successor for Magnetocosmics. One attempt to do this is the [OTSO software](https://github.com/NLarsen15/OTSO), which is also designed to be open-source and community oriented. We hope that in the future, AniMAIRE could be integrated with OTSO. \n\n## Usage\n\nAfter installation, to import the toolkit into a particular Python script, run \n```\nfrom AniMAIRE import AniMAIRE\n```\nAll of the main useful functions are contained within this `AniMAIRE` module, and all other modules contained in this toolkit are primarily intended to be accessed internally (although don't let that stop you from using or editing them for your own purposes if you wish).\n\nThe rest of the README file describes how to run AniMAIRE to produce dose rates for different input parameters. You can also look at and run the examples present in the `AniMAIRE_examples.ipynb` notebook, and the advanced examples in the `notebooks_and_data_and_figures_for_paper/GLE71_plots_for_paper.ipynb` notebook to learn and see in practice how AniMAIRE can be used.\n\n## Testing that AniMAIRE is working\n\nTo test that AniMAIRE works, you can run:\n\n```\nfrom AniMAIRE import AniMAIRE\nimport datetime as dt\n\ntest_isotropic_dose_rates = AniMAIRE.run_from_spectra(\n        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),\n        Kp_index=3,\n        date_and_time=dt.datetime(2006, 12, 13, 3, 0),\n        array_of_lats_and_longs=[[65.0,25.0]],\n)\n```\n\nin Python. This should produce some dose rates as output to `test_isotropic_dose_rates` in the format (the meaning of each column is explained later on in this README, under the \"Simple isotropic runs and plotting\" heading):\n\n```\n    latitude  longitude  altitude (km)      edose      adose      dosee       tn1       tn2       tn3           SEU           SEL\n0       65.0       25.0         0.0000   0.010434   0.012526   0.010010  0.004431  0.002726  0.001826  2.725682e-16  2.725682e-11\n1       65.0       25.0         3.0480   0.101553   0.117294   0.085010  0.051717  0.033506  0.022912  3.350616e-15  3.350616e-10\n2       65.0       25.0         6.0960   0.669389   0.736989   0.456343  0.324250  0.210297  0.144131  2.102967e-14  2.102967e-09\n3       65.0       25.0         7.6200   1.432404   1.525608   0.966025  0.658130  0.426616  0.292777  4.266156e-14  4.266156e-09\n4       65.0       25.0         8.5344   2.147704   2.220632   1.416257  0.950846  0.614894  0.422072  6.148938e-14  6.148938e-09\n5       65.0       25.0         9.4488   3.108676   3.124392   2.063826  1.319292  0.854931  0.586036  8.549315e-14  8.549315e-09\n6       65.0       25.0        10.3632   4.377677   4.263813   2.692120  1.767081  1.142345  0.782749  1.142345e-13  1.142345e-08\n7       65.0       25.0        11.2776   5.993970   5.643631   3.764450  2.292849  1.480059  1.010255  1.480059e-13  1.480059e-08\n8       65.0       25.0        12.1920   7.953998   7.262904   5.017846  2.881359  1.850446  1.263386  1.850446e-13  1.850446e-08\n9       65.0       25.0        13.1064  10.414874   9.115408   6.247418  3.514676  2.249009  1.532907  2.249009e-13  2.249009e-08\n10      65.0       25.0        14.0208  13.242733  11.101641   7.800097  4.184576  2.665499  1.810092  2.665499e-13  2.665499e-08\n11      65.0       25.0        14.9352  16.603692  13.430864   9.571582  4.865316  3.082233  2.086676  3.082233e-13  3.082233e-08\n12      65.0       25.0        15.8496  20.842479  15.942018  11.573518  5.568722  3.503950  2.361370  3.503950e-13  3.503950e-08\n13      65.0       25.0        16.7640  25.482167  18.658393  13.926003  6.254882  3.914514  2.628245  3.914514e-13  3.914514e-08\n14      65.0       25.0        17.6784  31.020574  21.767530  16.937656  6.902852  4.295149  2.869582  4.295149e-13  4.295149e-08\n15      65.0       25.0        18.5928  37.203113  24.734609  19.638953  7.495669  4.637948  3.081391  4.637948e-13  4.637948e-08\n```\n\n## Calculating dose rates at any location in Earth's atmosphere\n\nThe primary function for performing a run to calculate dose rates in `AniMAIRE` is the `run_from_spectra` function, which has the format:\n\n```\ndef run_from_spectra(\n        proton_rigidity_spectrum=None,\n        alpha_rigidity_spectrum=None,\n        reference_pitch_angle_latitude=None,\n        reference_pitch_angle_longitude=None,\n        proton_pitch_angle_distribution=isotropicPitchAngleDistribution(),\n        alpha_pitch_angle_distribution=isotropicPitchAngleDistribution(),\n        altitudes_in_kft=[0,10,20] + [i for i in range(25, 61 + 1, 3)],\n        altitudes_in_km=None,\n        Kp_index=None,\n        date_and_time=dt.datetime.now(),\n        array_of_lats_and_longs=default_array_of_lats_and_longs,\n        array_of_zeniths_and_azimuths=np.array([[0.0, 0.0]]),\n        cache_magnetocosmics_run=True,\n        generate_NM_count_rates=False,\n        use_default_9_zeniths_azimuths=False,\n        **mag_cos_kwargs\n)\n```\n\n`run_from_spectra` performs a run at a single date and time and Kp index to calculate dose rates across Earth's atmosphere based on proton, alpha particle, or proton + alpha particle spectra. **Particle spectra here must be described in units of cm-2 s-1 sr-1 (GV/n)-1, and with respect to rigidity in units of GV**.\n\nParticle spectra and pitch angle distributions can be set as any 'callable' object in Python, i.e., a function, as shown in examples below. At least one particle spectrum must be specified, as well as a Kp index, so this function to execute successfully. For runs designed to simulate dose rates during particular dates and times, the argument `date_and_time` must also be supplied with a Python `datetime` corresponding to the timestamp being investigated (by default, the function assumes that the current date and time should be used).\n\nNote that while this function can optionally take an alpha particle spectrum as an input, it actually interpolates the dose rates due to alpha particles to those of heavier ions too, so outputted dose rates due to an alpha particle spectrum are in fact the combined total of all ions heavier than protons.\n\nSeveral types of runs can be performed with AniMAIRE; for instance, only vertical asymptotic directions are used to calculate dose rates by default. You can optionally set `use_default_9_zeniths_azimuths` to `True` to use the mean of nine different asymptotic directions to calculate dose rates, as was done by [Cramp et al. (1997)](https://doi.org/10.1029/97JA01947), to calculate dose rates during particularly complex events (note that this means calculations will take approximately nine times longer). You can also manually set your own choice of asymptotic directions for taking the average using the `array_of_zeniths_and_azimuths` variable.\n\n`AniMAIRE` performs runs of the MAGNETOCOSMICS as part of dose rate calculations (using the [AsympDirsCalculator](https://github.com/ssc-maire/AsymptoticDirectionsCalculator) package), and these currently take up by far the majority of `AniMAIRE` runtime - on the order of over half an hour on the developer's computer versus less than 6 minutes for the rest of the program. Therefore if the `cache_magnetocosmics_run` argument is set to `True`, which it is by default, `AniMAIRE` will cache the results of MAGNETOCOSMICS simulations in the directory that `AniMAIRE` is run from in the generated `cachedMagnetocosmicsRunData` and `cacheAsymptoticDirectionOutputs` directories. This significantly speeds up any tasks where users wish to investigate a constant `Kp_index` and `date_and_time`, but wish to vary the spectrum and pitch angle distribution and investigate how dose rates are impacted, as magnetocosmics runs are only performed once. \n\nYou can pass settings and variables to `AsympDirsCalculator` through adding additional keyword arguments to `run_from_spectra` with the same names as the arguments given on the [AsympDirsCalculator Github page](https://github.com/ssc-maire/AsymptoticDirectionsCalculator). These settings and variable get assigned to the `**mag_cos_kwargs` object, and passed to `AsympDirsCalculator` by `AniMAIRE`.\n\n### Simple isotropic runs and plotting\n\nA basic run of the `run_from_spectra` function might look like this:\n\n```\nfrom AniMAIRE import AniMAIRE\nimport datetime as dt\n\ntest_isotropic_dose_rates = AniMAIRE.run_from_spectra(\n        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),\n        Kp_index=3,\n        date_and_time=dt.datetime(2006, 12, 13, 3, 0),\n)\n```\n\nin this example, the proton rigidity spectrum is set to be a power law with a normalisation factor of 2.56 cm-2 s-1 sr-1 (GV/n)-1, and a spectral index of 3.41, using the commonly used `lambda` approach to create a function within a single line. Kp index is set to be 3, and the date and time to simulate are set to be 13th of December 2006, 03:00. This function will likely take at least several minutes to run, depending on the speed of the machine and number of cores, and should output a Pandas DataFrame to `test_isotropic_dose_rates`, giving:\n\n```\n\tlatitude\tlongitude\taltitude (km)\tedose\tadose\tdosee\ttn1\ttn2\ttn3\tSEU\tSEL\n0\t-90.0\t0.0\t0.0000\t0.010442\t0.012540\t0.010010\t0.004437\t0.002729\t0.001828\t2.729229e-16\t2.729229e-11\n1\t-90.0\t0.0\t3.0480\t0.101786\t0.117658\t0.085755\t0.051895\t0.033617\t0.022979\t3.361684e-15\t3.361684e-10\n2\t-90.0\t0.0\t6.0960\t0.672702\t0.742332\t0.457695\t0.326731\t0.211853\t0.145046\t2.118530e-14\t2.118530e-09\n3\t-90.0\t0.0\t7.6200\t1.442377\t1.541670\t0.975436\t0.665785\t0.431261\t0.295516\t4.312608e-14\t4.312608e-09\n4\t-90.0\t0.0\t8.5344\t2.165860\t2.249419\t1.426324\t0.964791\t0.623291\t0.426927\t6.232913e-14\t6.232913e-09\n...\t...\t...\t...\t...\t...\t...\t...\t...\t...\t...\t...\n42619\t90.0\t355.0\t14.9352\t16.953199\t14.033322\t9.762795\t5.138425\t3.234975\t2.164808\t3.234975e-13\t3.234975e-08\n42620\t90.0\t355.0\t15.8496\t21.327714\t16.796347\t11.858681\t5.949880\t3.711156\t2.463976\t3.711156e-13\t3.711156e-08\n42621\t90.0\t355.0\t16.7640\t26.122787\t19.802434\t14.318360\t6.759204\t4.182604\t2.757482\t4.182604e-13\t4.182604e-08\n42622\t90.0\t355.0\t17.6784\t31.856083\t23.278901\t17.431863\t7.562120\t4.638132\t3.029771\t4.638132e-13\t4.638132e-08\n42623\t90.0\t355.0\t18.5928\t38.265701\t26.680896\t20.232603\t8.340509\t5.067928\t3.275415\t5.067928e-13\t5.067928e-08\n```\n\nwhen `test_isotropic_dose_rates` is printed.\n\nThe outputted dose rate (or flux) labels represent the following dose rate/flux types:\n\n|label | dose rate/flux type|\n|------|--------------------|\n|adose| ambient dose equivalent in \u00b5Sv/hr |\n|edose| effective dose in \u00b5Sv/hr |\n|dosee| dose equivalent in \u00b5Sv/hr |\n|tn1| >1 MeV neutron flux, in n/cm2/s |\n|tn2| >10 MeV neutron flux, in n/cm2/s |\n|tn3| >60 MeV neutron flux, in n/cm2/s |\n|SEU| single event upset rate for an SRAM device in upsets/second/bit |\n|SEL| single event latch-up rate for an SRAM device in latch-ups/second/device |\n\nThese dose rates are produced by default at every latitude and longitude corresponding to 5 by 5 degree intervals across Earth's surface, and for altitudes of 0 kilofeet, 10 kilofeet, 20 kilofeet and between 25 kilofeet and 61 kilofeet at intervals of 3 kilofeet. This can be altered using the `altitudes_in_kft`, `altitudes_in_km` and `array_of_lats_and_longs`. \n\nAny particular altitudes the user wants to use can be supplied to `altitudes_in_kft` or `altitudes_in_km` as a `list` or numpy array. \n\nIf you want to perform calculations only at a specific set of latitudes and longitudes you should use the `array_of_lats_and_longs` argument, supplying it as a 2 dimensional `list` or numpy array, where the first column refers to latitudes and the second column refers to longitudes. All longitudes in this case should be specified in terms of longitude east (i.e. 0.00 degrees - 359.99 degrees). **Using the `array_of_lats_and_longs` argument significantly speeds up the running of `AniMAIRE` if you're only interested in a small number of coordinates, so its use is highly recommended in those situations.**\n\nThere are many ways you could plot this data. Several example functions,`plot_dose_map` and `create_single_dose_map_plotly`, have been supplied in `AniMAIRE` that uses matplotlib or plotly to plot the dose rates across Earth (i.e. as a function of latitude and longitude) at a given altitude. Both of these functions are available in the `dose_plotting` submodule supplied with AniMAIRE. Their specifications are the following:\n```\ndef plot_dose_map(map_to_plot,\n                  plot_title=None,\n                  plot_contours=True,\n                  levels=3,\n                    **kwargs)\n```\nfor matplotlib plots, where map_to_plot is the Pandas DataFrame outputted by a run of `AniMAIRE`, with only one altitude selected. `plot_contours` can be switched on or off to control whether contours are added to the plot, and `levels` can be used to specify to number of contours and/or dose rates for the contours to correspond to. `hue_range` can also be supplied with a 2-value tuple to specify the limits of the colorbar to be plotted with the plot. \n\nTo generate a plotly plot, you can run\n```\ndef create_single_dose_map_plotly(DF_to_use,\n                                selected_altitude_in_km)\n```\nwhere `DF_to_use` is the Pandas DataFrame outputted by a run of `AniMAIRE` and altitude is one of the altitudes in kilometers supplied to/outputted by the run.\n\nTo use the matplotlib function to create a map of the isotropic situation as given as an example above, you could run \n```\nfrom AniMAIRE import dose_plotting\nimport matplotlib.pyplot as plt\n\ndose_plotting.plot_dose_map(test_isotropic_dose_rates.query(\"`altitude (km)` == 12.1920\"),\n                                         hue_range=(0,9))\n\nplt.show()\n```\n\nwhich should plot the following figure as a matplotlib plot:\n![isotropic_test_plot](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Isotropic_40kft_example.svg)\n\nand assign the plot to the `isotropic_dose_rate_map` variable for the user to use as they wish.\n\n### Anisotropic runs\n\n`run_from_spectra` defaults to an isotropic spectrum if no pitch angle distribution is supplied for either protons or alpha particles by the user.  \n\nTo run an anisotropic spectrum, differential pitch angle distributions must be supplied to the `proton_pitch_angle_distribution` and/or `alpha_pitch_angle_distribution` arguments in `run_from_spectra` along with a reference location specified in terms of latitude and longitude in the `reference_pitch_angle_latitude` and `reference_pitch_angle_longitude` arguments respectively. The pitch angle distributions must be supplied as 2 dimensional functions, where the first argument is the pitch angle, and the second argument is particle rigidity (in many cases the pitch angle distribution might not depend on rigidity, but for programmatic reasons the function must at least take in rigidity as an argument although it does not need to have a dependence on it). The pitch angle here must be specified in units of **radians**.\n\n`reference_pitch_angle_latitude` and `reference_pitch_angle_longitude` are the reference latitude and longitude in GEO coordinates representing a pitch angle of 0 in the supplied pitch angle distribution used. `AniMAIRE` currently makes the assumption that incoming particle distributions are cylindrically symmetric about this reference direction, and therefore that only the pitch angle with respect to this latitude and longitude are required to calculate dose rates anisotropically across Earth. Incoming solar particle events are frequently oriented near to the direction of the Interplanetary Magnetic Field (IMF), so you could specify pitch angles relative to the IMF here, and use the latitude and longitude of the IMF as the reference latitude and longitude.\n\nThe pitch angle distributions and rigidity spectrum must be specified in units normalised such that the product of the pitch angle distribution and rigidity spectrum multiplied together is in units of **cm-2 s-1 sr-1 (GV/n)-1**. \n\nThe pitch angle distributions can be specified using the Python `lambda` as with the rigidity spectra, but with 2 dimensions rather than 1. For example, to specify a Gaussian pitch angle distribution you could use:\n\n```\nimport numpy as np\n\nsigma = np.sqrt(0.19)\n\ntest_pitch_angle_dist_function = lambda pitch_angle,rigidity:np.exp(-(pitch_angle**2)/(sigma**2))\n```\nwhere `sigma` here has arbitrarily been chosen to be the square root of 0.19 for example purposes. \n\nhere `pitch_angle_dist_function` would be a viable input as a pitch angle distribution to `run_from_spectra`. While the function itself does not depend on `rigidity`, `rigidity` is specified as the second argument of the function nonetheless, as required for calculations to work.\n\nAn example of using this might be:\n\n```\nimport numpy as np\nfrom AniMAIRE import AniMAIRE\nimport datetime as dt\n\nsigma = np.sqrt(0.19)\npitch_angle_reference_latitude = -17.0\npitch_angle_reference_longitude = 148.0\n\ntest_pitch_angle_dist_function = lambda pitch_angle,rigidity:np.exp(-(pitch_angle**2)/(sigma**2))\n\ntest_anisotropic_dose_rates = AniMAIRE.run_from_spectra(\n        proton_rigidity_spectrum=lambda x:2.56*(x**-3.41),\n        proton_pitch_angle_distribution=test_pitch_angle_dist_function,\n        reference_pitch_angle_latitude=pitch_angle_reference_latitude,reference_pitch_angle_longitude=pitch_angle_reference_longitude,\n        Kp_index=3,\n        date_and_time=dt.datetime(2006, 12, 13, 3, 0),\n)\n```\n\nwhen run this should output a Pandas DataFrame to `test_anisotropic_dose_rates` with the same general output format as given in the previously described isotropic dose rates case. \n\nIn this case printing `test_anisotropic_dose_rates` should output:\n```\n\tlatitude\tlongitude\taltitude (km)\tedose\tadose\tdosee\ttn1\ttn2\ttn3\tSEU\tSEL\n0\t-90.0\t0.0\t0.0000\t1.976895e-07\t2.027961e-07\t3.222401e-07\t1.286575e-08\t7.877480e-09\t5.401425e-09\t7.877480e-22\t7.877480e-17\n1\t-90.0\t0.0\t3.0480\t4.838923e-07\t4.869626e-07\t7.032983e-07\t7.429541e-08\t4.866265e-08\t3.410940e-08\t4.866265e-21\t4.866265e-16\n2\t-90.0\t0.0\t6.0960\t1.453834e-06\t1.411544e-06\t2.045308e-06\t2.472576e-07\t1.611648e-07\t1.136527e-07\t1.611648e-20\t1.611648e-15\n3\t-90.0\t0.0\t7.6200\t2.352658e-06\t2.382057e-06\t3.304989e-06\t3.720997e-07\t2.420436e-07\t1.708843e-07\t2.420436e-20\t2.420436e-15\n4\t-90.0\t0.0\t8.5344\t2.970462e-06\t2.791970e-06\t4.201789e-06\t4.473736e-07\t2.919136e-07\t2.063902e-07\t2.919136e-20\t2.919136e-15\n...\t...\t...\t...\t...\t...\t...\t...\t...\t...\t...\t...\n42619\t90.0\t355.0\t14.9352\t1.062397e-06\t7.975138e-07\t5.902218e-07\t2.766678e-07\t1.764588e-07\t1.216189e-07\t1.764588e-20\t1.764588e-15\n42620\t90.0\t355.0\t15.8496\t1.289216e-06\t9.183397e-07\t6.964574e-07\t3.063998e-07\t1.945207e-07\t1.338582e-07\t1.945207e-20\t1.945207e-15\n42621\t90.0\t355.0\t16.7640\t1.525359e-06\t1.040969e-06\t8.062018e-07\t3.339381e-07\t2.112220e-07\t1.452375e-07\t2.112220e-20\t2.112220e-15\n42622\t90.0\t355.0\t17.6784\t1.777447e-06\t1.163693e-06\t9.297615e-07\t3.568426e-07\t2.248452e-07\t1.543556e-07\t2.248452e-20\t2.248452e-15\n42623\t90.0\t355.0\t18.5928\t2.036052e-06\t1.275021e-06\t1.040287e-06\t3.755276e-07\t2.357292e-07\t1.614028e-07\t2.357292e-20\t2.357292e-15\n```\n\nwhich will produce the following plot when\n```\nfrom AniMAIRE import dose_plotting\nimport matplotlib.pyplot as plt\n\ndose_plotting.plot_dose_map(test_anisotropic_dose_rates.query(\"`altitude (km)` == 12.1920\"),\n                                         hue_range=(0,9))\n\nplt.show()\n```\nis run, as was described previously in this README for isotropic plotting:\n\n![anisotropic_test_plot](https://raw.githubusercontent.com/ssc-maire/AniMAIRE-public/main/Anisotropic_40kft_example.svg)\n\n\nyou can also produce similar plotly plots if you prefer plotly to matplotlib using:\n```\nfrom AniMAIRE import dose_plotting\n\nanisotropic_dose_rate_map = dose_plotting.create_single_dose_map_plotly(test_anisotropic_dose_rates,\n                            \t\t\t      selected_altitude_in_km = 12.1920)\n```\nwhich generates the following plot:\n\n![anisotropic_test_plot](https://user-images.githubusercontent.com/16866485/223751057-5d0cff98-cf9e-4654-b71f-d1ae55c75602.png)\n\n### Functions for running `AniMAIRE` for specific situations and for a past timestamp\n\nIn addition to the quite general `run_from_spectra` function, `AniMAIRE` currently contains several functions for running calculations for specific types of spectra and situations, to make it easier for users to perform runs without having to determine and feed in spectra to `run_from_spectra` themselves.\n\nThe `run_from_DLR_cosmic_ray_power_law` function allows users to run full atmospheric dose rate calculations (for cosmic ray only/'quiet' time periods only) from just a date and time, or alternatively from just a single OULU count rate, or just a value of 'W parameter', as well as Kp index. This function utilises the [CosRayModifiedISO package](https://github.com/ssc-maire/CosRayModifiedISO) to determine the spectra due to protons and alpha particles during cosmic ray only time periods, and then runs `run_from_spectra` using both of those spectra under isotropic conditions. The specifications of `run_from_DLR_cosmic_ray_power_law` are:\n\n```\ndef run_from_DLR_cosmic_ray_model(OULU_count_rate_in_seconds=None,\n                                      W_parameter=None,\n                                      Kp_index=None,\n\t\t\t\t      date_and_time=None,\n                                      **kwargs)\n```\n\n`**kwargs` here can be used to supply any arguments you wish to `run_from_spectra` as specified previously, such as the list of altitudes and list of coordinates to perform calculations for. Details on what `OULU_count_rate_in_seconds` and `W_parameter` mean can be found at https://github.com/ssc-maire/CosRayModifiedISO . If either `OULU_count_rate_in_seconds` or `W_parameter` are used, only one of them should be specified. Otherwise, `AniMAIRE` will determined their values using the `date_and_time` parameter supplied.\n\nIn addition to running from the DLR-ISO isotropic cosmic ray model, you can also run `AniMAIRE` from a combined power law rigidity spectrum and Gaussian pitch angle distribution. This can be done using the `run_from_power_law_gaussian_distribution` function:\n\n```\ndef run_from_power_law_gaussian_distribution(J0, gamma, deltaGamma, sigma, \n                                             reference_pitch_angle_latitude, reference_pitch_angle_longitude, \n                                             Kp_index,date_and_time,\n                                             **kwargs)\n```\n\nHere `J0`, `gamma`, `deltaGamma`, `sigma`, `reference_pitch_angle_latitude`, `reference_pitch_angle_longitude` are all defined as specified in the format of papers like [Mishev, A., Usoskin, I. Analysis of the Ground-Level Enhancements on 14 July 2000 and 13 December 2006 Using Neutron Monitor Data. Sol Phys 291, 1225\u20131239 (2016). https://doi.org/10.1007/s11207-016-0877-2](https://link.springer.com/article/10.1007/s11207-016-0877-2).\n\n\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "Python library for running the anisotropic version of MAIRE+",
    "version": "1.1.5",
    "project_urls": {
        "Homepage": "https://github.com/ssc-maire/AniMAIRE-public"
    },
    "split_keywords": [
        "anisotropic",
        "maire+",
        "atmospheric",
        "ionizing",
        "radiation",
        "dose",
        "rates",
        "cosmic",
        "rays",
        "ground",
        "level",
        "enhancements",
        "gles",
        "protons",
        "alpha",
        "particles",
        "neutrons",
        "effective",
        "ambient",
        "equivalent",
        "aircraft",
        "aviation",
        "earth",
        "solar",
        "system",
        "sun",
        "space",
        "magnetic",
        "field"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e683687628bfb5e1cc31ecc584a015485dbc9144c568e5605a477ff0dd1bec5d",
                "md5": "1a6a6a7ab818437a6370d801fd35202c",
                "sha256": "56b618b16ebffed82cb14d5c3ff554d6fe53eb3323e1664c7633f9b2a5bc61ff"
            },
            "downloads": -1,
            "filename": "AniMAIRE-1.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a6a6a7ab818437a6370d801fd35202c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 52153,
            "upload_time": "2024-04-22T10:42:48",
            "upload_time_iso_8601": "2024-04-22T10:42:48.536207Z",
            "url": "https://files.pythonhosted.org/packages/e6/83/687628bfb5e1cc31ecc584a015485dbc9144c568e5605a477ff0dd1bec5d/AniMAIRE-1.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46f5c975b038f1959c16bb553710d2d409d953e59fc78791ff458ce1e9ba639e",
                "md5": "ff35e6a1b779dd439c0bacef07c417a2",
                "sha256": "6d27a105f8fed10918210552da57ae6fca6722485d9390c8bcde67a432636206"
            },
            "downloads": -1,
            "filename": "animaire-1.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "ff35e6a1b779dd439c0bacef07c417a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 58325,
            "upload_time": "2024-04-22T10:42:52",
            "upload_time_iso_8601": "2024-04-22T10:42:52.113754Z",
            "url": "https://files.pythonhosted.org/packages/46/f5/c975b038f1959c16bb553710d2d409d953e59fc78791ff458ce1e9ba639e/animaire-1.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 10:42:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ssc-maire",
    "github_project": "AniMAIRE-public",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.21.6"
                ]
            ]
        },
        {
            "name": "wheel",
            "specs": [
                [
                    ">=",
                    "0.43.0"
                ]
            ]
        },
        {
            "name": "pandarallel",
            "specs": [
                [
                    ">=",
                    "1.6.3"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "1.3.5"
                ]
            ]
        },
        {
            "name": "ParticleRigidityCalculationTools",
            "specs": [
                [
                    ">=",
                    "1.5.4"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    ">=",
                    "1.7.3"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    ">=",
                    "45.2.0"
                ]
            ]
        },
        {
            "name": "spacepy",
            "specs": [
                [
                    ">=",
                    "0.3.0"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    ">=",
                    "4.65.0"
                ]
            ]
        },
        {
            "name": "plotly",
            "specs": [
                [
                    ">=",
                    "5.9.0"
                ]
            ]
        },
        {
            "name": "numba",
            "specs": [
                [
                    ">=",
                    "0.57.1"
                ]
            ]
        },
        {
            "name": "metpy",
            "specs": [
                [
                    ">=",
                    "1.5.1"
                ]
            ]
        },
        {
            "name": "CosRayModifiedISO",
            "specs": [
                [
                    ">=",
                    "1.2.3"
                ]
            ]
        },
        {
            "name": "AsympDirsCalculator",
            "specs": [
                [
                    ">=",
                    "1.0.8"
                ]
            ]
        },
        {
            "name": "seaborn",
            "specs": [
                [
                    ">=",
                    "0.13.2"
                ]
            ]
        },
        {
            "name": "geopandas",
            "specs": [
                [
                    ">=",
                    "0.11.1"
                ]
            ]
        },
        {
            "name": "joblib",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "spaceweather",
            "specs": [
                [
                    ">=",
                    "0.2.4"
                ]
            ]
        },
        {
            "name": "atmosphericRadiationDoseAndFlux",
            "specs": [
                [
                    ">=",
                    "1.0.3"
                ]
            ]
        }
    ],
    "lcname": "animaire"
}
        
Elapsed time: 0.23970s