Skip to content

Commit

Permalink
fix bayes for flex
Browse files Browse the repository at this point in the history
fix errors bayes for flex in win and linux platform
  • Loading branch information
steveshichen committed Apr 20, 2020
1 parent 12e289d commit b0f177c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
28 changes: 24 additions & 4 deletions examples/flex_wgm2012.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import matplotlib.pyplot as plt
from geoist.others.gdal import GDALGrid
from geoist.others.utils import map2DGrid
from geoist.others.utils import map2DGrid, grid2srf
from geoist.others.grid2d import Grid2D

import warnings
Expand Down Expand Up @@ -65,12 +65,29 @@
# project.__dict__.keys()
project.plot_admit_coh(kindex=7, contours=contours, mask=mask)
# Take random cell value within grid and set as attribute
project.cell = (250, 100)

cell = (250, 100)

project.cell = cell
# Plot admittance and coherence functions
project.estimate_cell(cell, atype='admit')
print(project.summary)
project.plot_functions()
# # EET
#project.inverse = 'L2'


# Switch again to `bayes`
project.inverse = 'bayes'
# Perform estimation, print summary and plot
project.estimate_cell(cell, atype='admit')
print(project.summary)
project.plot_functions(est='MAP')
from geoist.flex import plotting
plotting.plot_bayes_stats(project.trace, project.summary, project.map_estimate)
#project.plot_bayes_stats()

# # EET
project.inverse = 'L2'
#project.inverse = 'bayes'
print(project.inverse)
project.mask = mask
project.estimate_grid(30, atype='joint')
Expand All @@ -84,6 +101,9 @@
eetdict.ny = eetny
eetgrid = Grid2D(project.mean_Te_grid[::-1],eetdict)
eet_jw = eetgrid.project(p_jw)

# save grid2d data to file in the DATA_PATH
grid2srf(eet_jw, filename = 'chinaeet.grd')
# transform to jw
topo_jw = topo_m.project(p_jw)

Expand Down
2 changes: 1 addition & 1 deletion geoist/flex/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
global samples, tunes
draws = 500
tunes = 500
cores = 4
cores = 1 #4
4 changes: 2 additions & 2 deletions geoist/flex/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def plot_bayes_stats(trace, summary, map_estimate, title=None, save=None):
"""

from plateflex import estimate
from geoist.flex import estimate

# Extract results from summary and map_estimate
results = estimate.get_bayes_estimates(summary, map_estimate)
Expand Down Expand Up @@ -276,7 +276,7 @@ def plot_functions(k, adm, eadm, coh, ecoh, padm=None, pcoh=None, title=None, sa
"""

from plateflex import estimate
from geoist.flex import estimate

# Plot as 2 subplots
f, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
Expand Down
10 changes: 7 additions & 3 deletions geoist/others/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,22 @@ def grid2srf(grid, filename='outsrf.grd', fformat = 'asc'): # bin
"""
from geoist import DATA_PATH
from geoist.pfm.grdio import grddata
import numpy.ma as ma
g1out = grddata()
g1out.cols = grid.getGeoDict().nx
g1out.rows = grid.getGeoDict().ny
g1out.xmin = grid.getGeoDict().xmin
g1out.xmax = grid.getGeoDict().xmax
g1out.ymin = grid.getGeoDict().ymin
g1out.ymax = grid.getGeoDict().ymax
g1out.data0 = grid.getData()
mask = np.isnan(grid.getData())
mx = ma.array(grid.getData(),mask=mask)
g1out.data = mx[::-1] #grid.getData()
#g1out.data0[np.isnan(grid.getData())] = 1.701410009187828e+38
if fformat == 'asc':
g1out.export_surfer(Path(DATA_PATH, filename), False, 'ascii')
g1out.export_surfer(Path(DATA_PATH, filename), True, 'ascii')
else:
g1out.export_surfer(Path(DATA_PATH, filename), False, 'binary')
g1out.export_surfer(Path(DATA_PATH, filename), True, 'binary')
return g1out

def map2DGrid(ax, grid, tstr, xlen=1.0, ylen=1.0, isLeft=False,
Expand Down

0 comments on commit b0f177c

Please sign in to comment.