示例#1
0
def test_warn_if_division_makes_too_small():
    "gravmag.tesseroid warn if not dividing further bc tesseroid got too small"
    # When tesseroids get below a threshold, they should not divide further and
    # compute as is instead. Otherwise results in ZeroDivisionError involving
    # some trigonometric functions.
    ds = 1e-6
    models = [
        [Tesseroid(-ds, ds, -ds, ds, 0, -1000, {'density': 100})],
        [Tesseroid(-1e-3, 1e-3, -1e-3, 1e-3, 0, -1e-2, {'density': 100})]]
    lat, lon = np.zeros((2, 1))
    h = np.array([0.1])
    warning_msg = (
        "Stopped dividing a tesseroid because it's dimensions would be below "
        + "the minimum numerical threshold (1e-6 degrees or 1e-3 m). "
        + "Will compute without division. Cannot guarantee the accuracy of "
        + "the solution.")
    for i, model in enumerate(models):
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            tesseroid.gz(lon, lat, h, model)
            msg = ("Failed model {}. Got {} warnings.\n\n".format(i, len(w))
                   + "\n\n".join([str(j.message) for j in w]))
            assert len(w) >= 1, msg
            assert any(issubclass(j.category, RuntimeWarning) for j in w), \
                "No RuntimeWarning found. " + msg
            assert any(warning_msg in str(j.message) for j in w), \
                "Message mismatch. " + msg
示例#2
0
def test_warn_if_too_small():
    "gravmag.tesseroid warns if ignoring tesseroid that is too small"
    ds = 1e-6 / 2
    models = [[Tesseroid(-ds, ds, -ds, ds, 0, -1000, {'density': 100})],
              [
                  Tesseroid(-1e-2, 1e-2, -1e-2, 1e-2, 0, -1e-4,
                            {'density': 100})
              ]]
    lat, lon = np.zeros((2, 1))
    h = np.array([10])
    warning_msg = ("Encountered tesseroid with dimensions smaller than the " +
                   "numerical threshold (1e-6 degrees or 1e-3 m). " +
                   "Ignoring this tesseroid.")
    for i, model in enumerate(models):
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            tesseroid.gz(lon, lat, h, model)
            msg = ("Failed model {}. Got {} warnings.\n\n".format(i, len(w)) +
                   "\n\n".join([str(j.message) for j in w]))
            assert len(w) >= 1, msg
            assert any(issubclass(j.category, RuntimeWarning) for j in w), \
                "No RuntimeWarning found. " + msg
            assert any(warning_msg in str(j.message) for j in w), \
                "Message mismatch. " + msg
示例#3
0
def score_test_set(model, lat, lon, height, data, njobs=1):
    """
    Score a given tesseroid model based on the Mean Square Error
    between the given data and the one predicted by the model.

    Parameters:

    * model : list of Tesseroids or TesseroidRelief
        The model to score
    * lat, lon, height : 1d-arrays
        The coordinates of the data points
    * data : 1d-array
        The observed data that will be compared to the predicted data
    * njobs : int
        The number of processes to use for the forward modeling

    Returns:

    * score : float
        The MSE

    """
    predicted = tesseroid.gz(lon, lat, height, model, njobs=njobs)
    score = np.sum((predicted - data)**2)/data.size
    return score
def test_gz():
    "gravmag.tesseroid.gz with optimal discretize against half a shell"
    shell = half_sph_shell.gz(heights, top, bottom, density)
    lons = np.zeros_like(heights)
    lats = lons
    tess = tesseroid.gz(lons, lats, heights, shellmodel)
    diff = np.abs(shell - tess) / np.abs(shell)
    assert np.all(diff <= 0.01), 'diff: %s' % (str(diff))
示例#5
0
def test_warn_if_too_small():
    "gravmag.tesseroid warns if ignoring tesseroid that is too small"
    ds = 1e-6/2
    models = [
        [Tesseroid(-ds, ds, -ds, ds, 0, -1000, {'density': 100})],
        [Tesseroid(-1e-2, 1e-2, -1e-2, 1e-2, 0, -1e-4, {'density': 100})]]
    lat, lon = np.zeros((2, 1))
    h = np.array([10])
    warning_msg = (
        "Encountered tesseroid with dimensions smaller than the "
        + "numerical threshold (1e-6 degrees or 1e-3 m). "
        + "Ignoring this tesseroid.")
    for i, model in enumerate(models):
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            tesseroid.gz(lon, lat, h, model)
            msg = ("Failed model {}. Got {} warnings.\n\n".format(i, len(w))
                   + "\n\n".join([str(j.message) for j in w]))
            assert len(w) >= 1, msg
            assert any(issubclass(j.category, RuntimeWarning) for j in w), \
                "No RuntimeWarning found. " + msg
            assert any(warning_msg in str(j.message) for j in w), \
                "Message mismatch. " + msg
def calculate(chunk):
    return tesseroid.gz(lons, lats, heights, chunk)
示例#7
0
scene.scene.camera.clipping_range = [9229054.5133903362, 54238225.321054712]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
myv.show()

# Create the computation grid
area = (-80, -30, -40, 10)
shape = (100, 100)
lons, lats, heights = gridder.regular(area, shape, z=250000)

start = time.time()
fields = [
    tesseroid.potential(lons, lats, heights, model),
    tesseroid.gx(lons, lats, heights, model),
    tesseroid.gy(lons, lats, heights, model),
    tesseroid.gz(lons, lats, heights, model),
    tesseroid.gxx(lons, lats, heights, model),
    tesseroid.gxy(lons, lats, heights, model),
    tesseroid.gxz(lons, lats, heights, model),
    tesseroid.gyy(lons, lats, heights, model),
    tesseroid.gyz(lons, lats, heights, model),
    tesseroid.gzz(lons, lats, heights, model)]
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

titles = ['potential', 'gx', 'gy', 'gz',
          'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
bm = mpl.basemap(area, 'merc')
mpl.figure()
mpl.title(titles[0])
mpl.contourf(lons, lats, fields[0], shape, 40, basemap=bm)
bm.drawcoastlines()
示例#8
0
plot_data(lat, lon, disturbance, shape, 'RdBu_r')
plt.title('Gravity disturbance')

# Terrain Correction
topo_data = load_icgem_gdf('../etopo1_15km.gdf', usecols=[-1])
topo, _ = down_sample([topo_data['topography_grd']], topo_data['shape'], 
                      every=downsample_every)
plot_data(lat, lon, topo, shape, cmap='terrain', cblabel='meters')
plt.title('Topography')
topo_model = make_mesh(area, shape, topo, reference=0) 
topo_density = 2891.87155*np.ones(topo_model.size)
# Density in the oceans is rho_water
topo_density[topo_model.relief < topo_model.reference] = -1852
topo_model.addprop('density', topo_density)

topo_effect = tesseroid.gz(lon, lat, height, topo_model, njobs=ncpu)

plot_data(lat, lon, topo_effect, shape, cmap='RdBu_r')
plt.title('Topographic gravitational effect')

bouguer = disturbance - topo_effect
plot_data(lat, lon, bouguer, shape, cmap='RdBu_r')
plt.title('Bouguer anomaly')

now = datetime.datetime.utcnow().strftime('%d %B %Y %H:%M:%S UTC')
header = '\n'.join([
    '# Generated by Grav_effects.py {date}'.format(date=now),
    '# shape (nlat, nlon):',
    '# {nlat} {nlon}'.format(nlat=shape[0], nlon=shape[1]),
    '# lat lon bouguer '])
with open('New_GravFem/GOCO05c_1d_15km.dat', 'w') as f:
scene.scene.camera.clipping_range = [9229054.5133903362, 54238225.321054712]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
myv.show()

# Create the computation grid
area = (-80, -30, -40, 10)
shape = (100, 100)
lons, lats, heights = gridder.regular(area, shape, z=250000)

start = time.time()
fields = [
    tesseroid.potential(lons, lats, heights, model),
    tesseroid.gx(lons, lats, heights, model),
    tesseroid.gy(lons, lats, heights, model),
    tesseroid.gz(lons, lats, heights, model),
    tesseroid.gxx(lons, lats, heights, model),
    tesseroid.gxy(lons, lats, heights, model),
    tesseroid.gxz(lons, lats, heights, model),
    tesseroid.gyy(lons, lats, heights, model),
    tesseroid.gyz(lons, lats, heights, model),
    tesseroid.gzz(lons, lats, heights, model)
]
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

titles = [
    'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'
]
bm = mpl.basemap(area, 'merc')
mpl.figure()
mpl.title(titles[0])