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:
%% Cell type:code id:f52a366b tags:
``` python
frompymagglobalimportModel
myModel=Model('CALS10k.2')
```
%% Cell type:markdown id:98302e49 tags:
%% Cell type:markdown id:13988168 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.
Sometimes it is helpful to generate data not from a model that's included in pymagglobal, but from an arbitrary set of coefficients. Provided they are in the ''standard order'', i.e. $g_1^0, g_1^1, g_1^{-1}, g_2^0, g_2^1, g_2^{-1}, ...$, this is also straight-forward using utility routines from pymagglobal:
%% Cell type:code id:fdbdfd1c tags:
``` python
frompymagglobal.coreimportcoefficients
epoch=-3000
# First generate coefficients at epoch
_,_,coeffs=coefficients(epoch,myModel)
# Generate new input locations at the given epoch
z_at=get_z_at(n_at,random=True,t=epoch)
```
%% Cell type:markdown id:e81a742d tags:
We use the pymagglobal routine `dsh_basis`, which evaluates the derivatives of the spherical harmonics up to a given degree at given inputs:
%% Cell type:code id:5924dde3 tags:
``` python
frompymagglobal.utilsimportdsh_basis
# dsh_basis was designed to work with a C backend,
# so the return array has to be allocated beforehand
# and is filled during the function call
base=np.empty((len(coeffs),3*z_at.shape[1]))
dsh_basis(myModel.l_max,z_at,base)
```
%% Cell type:markdown id:0d875959 tags:
Field values are then generated via a dot product:
%% Cell type:code id:a0a43e60 tags:
``` python
obs=coeffs@base
```
%% Cell type:markdown id:1c804ae2 tags:
The outputs are now given by obs, every third value is N, E, Z. To have a more convenient form, we reshape the output: