Commit a6c5bdeb authored by Maximilian Schanner's avatar Maximilian Schanner
Browse files

Add example on how to generate data.

parent 7bee36b2
......@@ -8,3 +8,4 @@ Here we collect relevant examples. The list may grow over time.
:maxdepth: 2
example_1
example_2
This file complements pymagglobal.
It is licensed under CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
%% Cell type:markdown id:681fb4de tags:
# Generate synthetic data
%% Cell type:markdown id:7c938d6b tags:
Here we briefly show how `pymagglobal` can be used to generate synthetic data. We first set up the model we want to use to generate the synthetic data:
%% Cell type:code id:5380320c tags:
``` python
from pymagglobal import Model
myModel = Model('CALS10k.2')
```
%% Cell type:markdown id:98302e49 tags:
Next we have to generate a data distribution. We use `pymagglobal`s `get_z_at` routine, to generate `n_at` random locations, that are uniformly distributed on the sphere. Times are drawn uniformly as well.
%% Cell type:code id:68d9a6d8 tags:
``` python
from pymagglobal.utils import get_z_at
import numpy as np
from matplotlib import pyplot as plt
from cartopy import crs as ccrs
# the number of artificial records
n_at = 400
z_at = get_z_at(n_at, random=True)
# set the times to something arbitrary
z_at[3] = np.random.uniform(-1000, 1900, size=n_at)
# plot the records, convert co-lat to lat
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.Mollweide()})
ax.scatter(z_at[1], 90-z_at[0], transform=ccrs.PlateCarree())
ax.set_global()
ax.coastlines();
```
%% Cell type:markdown id:cbf80490 tags:
Finally we can evaluate the model at the inputs, to get synthetic ''observations'' of the field
%% Cell type:code id:ea10fa42 tags:
``` python
from pymagglobal.core import field
obs = field(z_at, myModel)
```
%% Cell type:markdown id:0c28838f tags:
Let's have a look at the records:
%% Cell type:code id:119a535b tags:
``` python
fig, axs = plt.subplots(1, 3, subplot_kw={'projection': ccrs.Mollweide()},
figsize=(15, 4))
titles = [r'$B_N$', r'$B_E$', r'$B_Z$']
for it in range(3):
axs[it].set_title(titles[it])
axs[it].scatter(z_at[1], 90-z_at[0], c=obs[it], transform=ccrs.PlateCarree())
axs[it].set_global()
axs[it].coastlines();
```
%% Cell type:markdown id:99e9b776 tags:
Declination, inclination and intensity records are also easily generated, by using the `field` kwargs:
%% Cell type:code id:8bda1baf tags:
``` python
obs_dif = field(z_at, myModel, field_type='dif')
fig, axs = plt.subplots(1, 3, subplot_kw={'projection': ccrs.Mollweide()},
figsize=(15, 4))
titles = [r'$D$', r'$I$', r'$F$']
for it in range(3):
axs[it].set_title(titles[it])
axs[it].scatter(z_at[1], 90-z_at[0], c=obs_dif[it], transform=ccrs.PlateCarree())
axs[it].set_global()
axs[it].coastlines();
```
This file complements pymagglobal.
It is licensed under CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment