{ "cells": [ { "cell_type": "markdown", "id": "08424f9f-7e8c-41b5-9fc6-5f82dbcb5d31", "metadata": {}, "source": [ "# Example of sampling\n", "\n", "Here we illustrate an example of how to generate samples using our small Python package `smpsite`. Many of the sampling capabilities are directly imported from `pmagpy`. " ] }, { "cell_type": "code", "execution_count": 1, "id": "668e70af-7010-407b-97a9-16585b89f6a3", "metadata": {}, "outputs": [], "source": [ "import pmagpy.pmag as pmag\n", "import pmagpy.ipmag as ipmag\n", "import matplotlib.pyplot as plt\n", "import smpsite as smp\n", "\n", "import numpy as np\n", "np.random.seed(666)\n", "\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "id": "6330c014-941a-414d-a787-6b60e2fbfe12", "metadata": {}, "source": [ "## Define the parameters of the sample\n", "\n", "We define a parameter class defined inside `smpsite` that allow us to specify all the parameters of interest at the same time. These parameters include:\n", "- `N`: Total number of sites\n", "- `n0`: Number of samples per site\n", "- `kappa_within_site`: Concentration parameter of the Fisher distribution within each site\n", "- `site_lat`: Latitude of the site\n", "- `site_long`: Longitude of the site\n", "- `outlier_rate`: Fraction of samples that are randomly taken from the uniform distribution in the sphere, with `0.0` representing no outliers and `1.0` representing all outliers. \n", "- `secular_method`: Method used to sample the VGPs. It includes `G`, `tk03` and `Fisher`. \n", "- `kappa_secular`: In case of `secular_method=\"Fisher\"`, it specifies the concentration parameter of the Fisher distribution. " ] }, { "cell_type": "code", "execution_count": 2, "id": "7828bea3-3d38-40f3-a140-ab9ce4ffdd05", "metadata": {}, "outputs": [], "source": [ "params0 = smp.Params(N=10,\n", " n0=5,\n", " kappa_within_site=100,\n", " site_lat=10, \n", " site_long=0,\n", " outlier_rate=0.10,\n", " secular_method=\"G\",\n", " kappa_secular=None)" ] }, { "cell_type": "markdown", "id": "8dbc2a35-a1aa-4c2f-9793-f49604a3e7e1", "metadata": {}, "source": [ "## Generate the sample\n", "\n", "Once the parameters are specified, we can simulate the sample data:" ] }, { "cell_type": "code", "execution_count": 8, "id": "827556d5-e9ac-4051-b355-38fc904c268c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 14.1 ms, sys: 3.15 ms, total: 17.2 ms\n", "Wall time: 14.5 ms\n" ] }, { "data": { "text/html": [ "
\n", " | sample_site | \n", "vgp_long | \n", "vgp_lat | \n", "vgp_dec | \n", "vgp_inc | \n", "is_outlier | \n", "
---|---|---|---|---|---|---|
0 | \n", "0 | \n", "280.282044 | \n", "83.501645 | \n", "353.484155 | \n", "21.414245 | \n", "0 | \n", "
1 | \n", "0 | \n", "14.416591 | \n", "82.931243 | \n", "1.834416 | \n", "31.189287 | \n", "0 | \n", "
2 | \n", "0 | \n", "36.734976 | \n", "80.135259 | \n", "6.179545 | \n", "32.762066 | \n", "0 | \n", "
3 | \n", "0 | \n", "88.887877 | \n", "81.402596 | \n", "8.730835 | \n", "19.522055 | \n", "0 | \n", "
4 | \n", "0 | \n", "333.817067 | \n", "80.131814 | \n", "355.417757 | \n", "34.274430 | \n", "0 | \n", "