示例#1
0
from varglas.meshing import MeshGenerator, MeshRefiner
from varglas.io import DataInput
from varglas.data.data_factory import DataFactory
from pylab import *
from scipy.interpolate import interp2d

#===============================================================================
# data preparation :
out_dir = 'dump/meshes/'

# collect the raw data :
bamber = DataFactory.get_bamber()
rignot = DataFactory.get_rignot()
searise = DataFactory.get_searise()
gimp = DataFactory.get_gimp()

# create data objects to use with varglas :
dbm = DataInput(bamber, gen_space=False)
drg = DataInput(rignot, gen_space=False)
dsr = DataInput(searise, gen_space=False)
dgm = DataInput(gimp, gen_space=False)

drg.set_data_max('U_ob', boundary=1000.0, val=1000.0)
drg.set_data_min('U_ob', boundary=0.0, val=0.0)

#===============================================================================
# form field from which to refine :
## antarctica :: Info : 4449632 vertices 25902918 elements
#drg.data['ref'] = (0.02 + 1/(1 + drg.data['U_ob'])) * 50000
dbm.data['ref'] = 5 * dbm.data['H'].copy()
dbm.data['ref'][dbm.data['ref'] < 5000.0] = 5000.0
示例#2
0
config['log_history'] = True
config['mode'] = 'transient'
config['model_order'] = 'L1L2'
config['output_path'] = out_dir
config['t_start'] = 0.0
config['t_end'] = 35000.0
config['time_step'] = 10.0
config['periodic_boundary_conditions'] = False
config['velocity']['poly_degree'] = 2
config['enthalpy']['on'] = True
config['enthalpy']['N_T'] = 8
config['free_surface']['on'] = True
config['free_surface']['thklim'] = thklim
config['velocity']['transient_beta'] = 'stats'

bedmap2 = DataFactory.get_bedmap2()
db2 = DataInput(bedmap2, mesh=mesh)

db2.data['Sn'] = db2.data['S'] + thklim

B = db2.get_expression("B", near=True)
S = db2.get_expression("Sn", near=True)

model = Model(config)
model.set_mesh(mesh)


class Adot(Expression):
    Rel = 450000
    s = 1e-5
示例#3
0
""" Script that takes in lat,lon gps coordinates and returns the x,y coordinates."""
from pylab import *
from mpl_toolkits.basemap import Basemap
from varglas.data.data_factory    import DataFactory
from varglas.utilities            import DataInput
from fenics                       import *

# Get the Antarctica data sets
bedmap2 = DataFactory.get_bedmap2(thklim = 200)

data = bedmap2['mask']['map_data'][::-1]

db2 = DataInput(bedmap2)

x0 = -376234
y0 = -456870

x1 = -291856
y1 = -505791

x2 = 102477
y2 = 177085

x3 = 17833
y3 = 225849

lon0, lat0 = db2.p(x0,y0,inverse = True)
lon1, lat1 = db2.p(x1,y1,inverse = True)
lon2, lat2 = db2.p(x2,y2,inverse = True)
lon3, lat3 = db2.p(x3,y3,inverse = True)
示例#4
0
import varglas.model as model
from varglas.mesh.mesh_factory import MeshFactory
from varglas.data.data_factory import DataFactory
from varglas.io import DataInput
from varglas.helper import default_config
from fenics import *
from pylab import *

out_dir = 'dump/vars_jakobshavn/'
thklim = 1.0

# collect the raw data :
searise = DataFactory.get_searise(thklim=thklim)
bamber = DataFactory.get_bamber(thklim=thklim)
rignot = DataFactory.get_rignot()

# define the mesh :
mesh = Mesh('dump/meshes/jakobshavn_3D_5H_mesh_block.xml.gz')

# create data objects to use with varglas :
dsr = DataInput(searise, mesh=mesh)
dbm = DataInput(bamber, mesh=mesh)
drg = DataInput(rignot, mesh=mesh)

m = dbm.data['mask']

# calculate surface gradient :
gradM = gradient(m)
gM = sqrt(gradM[0]**2 + gradM[1]**2 + 1e-16)

gM[gM > 0.1] = 100.0
示例#5
0
    valid = intersect1d(valid, where(U_mag > 0)[0])
valid = intersect1d(valid, where(U_ob_v > 1e-10)[0])
valid = intersect1d(valid, where(abs(Mb_v) < 200)[0])
valid = intersect1d(valid, where(S_v > -100)[0])
valid = intersect1d(valid, where(Ts_v > 100)[0])
valid = intersect1d(valid, where(h_v > 0)[0])
valid = intersect1d(valid, where(S_v - B_v > 60)[0])
valid = intersect1d(valid, where(adot_v > -100)[0])

valid_f = Function(Q)
valid_f_v = valid_f.vector().array()
valid_f_v[valid] = 1.0
valid_f.vector().set_local(valid_f_v)
valid_f.vector().apply('insert')

measures = DataFactory.get_ant_measures(res=900)
dm = DataInput(measures, gen_space=False)

betaMax = 200.0

#ini_f = Function(Q)
#ini_f.vector()[:] = ini
#plotIce(dm, ini_f, name='ini', direc='images/stats/' + file_n,
#        cmap='gist_yarg', scale='log', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False, umin=1.0, umax=betaMax)
#
#Ubar_avg_f = Function(Q)
#Ubar_avg_f.vector()[:] = Ubar_avg
#plotIce(dm, Ubar_avg_f, name='Ubar_avg', direc='images/stats/' + file_n,
#        title=r'$\Vert \mathbf{\bar{u}}_{\bar{bv}} \Vert$', cmap='gist_yarg',
#        scale='log', numLvls=12, tp=False,
示例#6
0
import varglas.model              as model
from varglas.data.data_factory    import DataFactory
from varglas.mesh.mesh_factory    import MeshFactory
from varglas.io                   import DataInput, DataOutput
from varglas.helper               import default_config
from fenics                       import *
from scipy.io                     import loadmat

# get the input args :
out_dir = 'dump/bed/09/bv_smb/'
in_dir  = 'dump/bed/09/'

mesh   = Mesh(in_dir + 'submesh.xdmf')
Q      = FunctionSpace(mesh, 'CG', 1)

bamber = DataFactory.get_bamber()
dbm    = DataInput(bamber,  mesh=mesh)

S      = Function(Q)
B      = Function(Q)

File(in_dir + 'S_s.xml') >> S
File(in_dir + 'B_s.xml') >> B

adot_v = loadmat(in_dir + 'smb/smb.mat')
dbm.data['smb'] = adot_v['map_data']

adot = dbm.get_expression('smb', near=True)

config = default_config()
config['output_path']               = out_dir
"""
Create a grounding line contour.
"""

from varglas.data.data_factory import DataFactory
from varglas.utilities import DataInput, MeshGenerator
from numpy import *
from mpl_toolkits.basemap import Basemap

# Get the Antarctica data sets
bedmap2 = DataFactory.get_bedmap2()
db2 = DataInput(bedmap2)

# Get the grounding line by eliminating the shelves
db2.set_data_val('mask',1,127)

# Create a grounding line countour
mg = MeshGenerator(db2, 'mesh', '')
mg.create_contour('mask', 10, skip_pts=2)
mg.eliminate_intersections(dist=20)
cont = mg.longest_cont

# Convert (x,y) coordinates to (lon,lat)
cont_lons, cont_lats = db2.p(cont[:,0], cont[:,1], inverse = True)

# Convert (x,y) coordinates to (lon,lat)
cont_lons, cont_lats = db2.p(cont[:,0], cont[:,1], inverse = True)

# Convert to basemap coordinates
lat_0  = '-90'
lat_ts = '-71'
示例#8
0
from fenics                    import *
from varglas.solvers           import HybridTransientSolver
from varglas.data.data_factory import DataFactory
from varglas.mesh.mesh_factory import MeshFactory
from varglas.io                import DataInput, print_min_max
from varglas.helper            import default_config
from varglas.model             import Model

set_log_active(False)

thklim = 1.0

# collect the raw data :
searise = DataFactory.get_searise(thklim = thklim)
bamber  = DataFactory.get_bamber(thklim = thklim)

# load a mesh :
mesh  = MeshFactory.get_greenland_2D_5H()

# create data objects to use with varglas :
dsr   = DataInput(searise, mesh=mesh)
dbm   = DataInput(bamber,  mesh=mesh)

dbm.data['S'] = dbm.data['B'] + thklim

B     = dbm.get_expression('B',    near=True)
S     = dbm.get_expression('S',    near=True)
adot  = dsr.get_expression('adot', near=True)
T_s   = dsr.get_interpolation('T', near=True)

out_dir = 'dump/transient_H/'
示例#9
0
import varglas.physical_constants as pc
import varglas.model              as model
from varglas.mesh.mesh_factory    import MeshFactory
from varglas.data.data_factory    import DataFactory
from varglas.io                   import DataInput
from fenics                       import *

out_dir  = 'dump/vars_ant_spacing/'
thklim   = 1.0

# collect the raw data :
searise  = DataFactory.get_searise(thklim = thklim)
bamber   = DataFactory.get_bamber(thklim = thklim)
fm_qgeo  = DataFactory.get_gre_qgeo_fox_maule()
rignot   = DataFactory.get_gre_rignot()

# define the mesh :
mesh = Mesh('dump/meshes/gre_mesh_ant_spacing.xml')

# create data objects to use with varglas :
dsr     = DataInput(searise,  mesh=mesh)
dbm     = DataInput(bamber,   mesh=mesh)
dfm     = DataInput(fm_qgeo,  mesh=mesh)
drg     = DataInput(rignot,   mesh=mesh)
    
# change the projection of all data to Rignot projection :
dsr.change_projection(drg)
dbm.change_projection(drg)
dfm.change_projection(drg)

# get the expressions used by varglas :
示例#10
0
import varglas.model as model
from varglas.data.data_factory import DataFactory
from varglas.io import DataInput, print_min_max
from varglas.helper import plotIce
from fenics import *

out_dir = 'dump/basin_vars_low/'
thklim = 1.0
bedmap2 = DataFactory.get_bedmap2(thklim=thklim)

print_min_max(bedmap2['S'], 'S')

mesh = Mesh('dump/meshes/byrd_basin_mesh_low.xml')

#d2 = DataInput(bedmap2, gen_space=False)
d2 = DataInput(bedmap2, mesh=mesh)

#plotIce(d2, 'S', '.', 'gist_yarg', scale='lin', name=r'$S$',
#        numLvls=12, tp=False, tpAlpha=0.5)
#
#plotIce(d2, 'B', '.', 'gist_yarg', scale='lin', name=r'$B$',
#        numLvls=12, tp=False, tpAlpha=0.5)
#
#plotIce(d2, 'H', '.', 'gist_yarg', scale='lin', name=r'$H$',
#        numLvls=12, tp=False, tpAlpha=0.5)
#
#plotIce(d2, 'mask', '.', 'gist_yarg', scale='lin', name='mask',
#        numLvls=12, tp=False, tpAlpha=0.5)

S = d2.get_expression("S", )  #     near=True)
B = d2.get_expression("B", )  #     near=True)
示例#11
0
from varglas.meshing import MeshGenerator, MeshRefiner
from varglas.data.data_factory import DataFactory
from varglas.io import DataInput, print_min_max
from pylab import *
from scipy.interpolate import interp2d

#===============================================================================
# data preparation :
out_dir = 'dump/meshes/'

# get the data :
measure = DataFactory.get_ant_measures()
bedmap2 = DataFactory.get_bedmap2()

# process the data :
dbm = DataInput(measure, gen_space=False)
db2 = DataInput(bedmap2, gen_space=False)

dbm.set_data_min('U_ob', boundary=0.0, val=0.0)
db2.set_data_val("H", 32767, 0.0)
db2.set_data_val('S', 32767, 0.0)

# calculate surface gradient :
gradS = gradient(db2.data['S'])
gS_n = sqrt(gradS[0]**2 + gradS[1]**2 + 1e-16)

# create interpolation object to convert measures to bedmap2 coordinates :
interp = interp2d(db2.x, db2.y, gS_n)
gS_n = interp(dbm.x, dbm.y)
interp = interp2d(db2.x, db2.y, db2.data['mask'])
mask = interp(dbm.x, dbm.y)
示例#12
0
import varglas.physical_constants as pc
import varglas.model as model
from varglas.mesh.mesh_factory import MeshFactory
from varglas.data.data_factory import DataFactory
from varglas.io import DataInput
from varglas.helper import plotIce
from fenics import *
from pylab import *

# collect the raw data :
searise = DataFactory.get_searise()
bamber = DataFactory.get_bamber()
rignot = DataFactory.get_rignot()

# create data objects to use with varglas :
dsr = DataInput(searise, gen_space=False)
dbm = DataInput(bamber, gen_space=False)
drg = DataInput(rignot, gen_space=False)

# change the projection of all data to Rignot projection :
#drg.change_projection(dbm)

## get the expressions used by varglas :
#S     = dbm.get_expression('S',        near=True)
#B     = dbm.get_expression('B',        near=True)
#M     = dbm.get_expression('mask',     near=True)
#adot  = dsr.get_expression('adot',     near=True)
#T_s   = dsr.get_interpolation('T',     near=True)
#q_geo = dfm.get_interpolation('q_geo', near=True)
#u     = drg.get_interpolation('vx',    near=True)
#v     = drg.get_interpolation('vy',    near=True)
示例#13
0
File(ant_in_dir + 'B_s.xml')    >> a_B
File(ant_in_dir + 'adot_s.xml') >> a_adot
File(ant_in_dir + 'qgeo_s.xml') >> a_qgeo
File(ant_in_dir + 'beta_s.xml') >> a_beta
File(ant_in_dir + 'Mb_s.xml')   >> a_Mb
File(ant_in_dir + 'Tb_s.xml')   >> a_Tb
File(ant_in_dir + 'Ts_s.xml')   >> a_Ts
File(ant_in_dir + 'u_s.xml')    >> a_u
File(ant_in_dir + 'v_s.xml')    >> a_v
File(ant_in_dir + 'w_s.xml')    >> a_w
File('antarctica/dump/bed/balance_velocity/Ubar_s.xml') >> a_Ubar
File('antarctica/dump/bed/balance_water/q.xml')         >> a_qbar

#===============================================================================
# plotting :
bedmap1  = DataFactory.get_bedmap1(thklim=1.0)
d1       = DataInput(bedmap1, mesh=a_mesh)
  
cmap = 'gist_earth'
cmap = 'RdYlGn'
cmap = 'RdGy'
cmap = 'gist_gray'
cmap = 'Purples'
cmap = 'Reds'
cmap = 'Oranges'

plotIce(d1, 'B', '.', 'gist_yarg', scale='lin', name=r'$B$', 
        numLvls=12, tp=False, tpAlpha=0.5)

#===============================================================================
S = Function(Q)
B = Function(Q)

File(in_dir + 'S_s.xml') >> S
File(in_dir + 'B_s.xml') >> B

config = default_config()
config['output_path'] = out_dir
config['balance_velocity']['kappa'] = 5.0
config['model_order'] = 'SSA'

model = model.Model(config)
model.set_mesh(mesh)
model.set_surface_and_bed(S, B)
model.initialize_variables()

model.init_adot(in_dir + 'adot_s.xml')

F = solvers.BalanceVelocitySolver(model, config)

F.solve()

model.save_xml(model.Ubar, 'Ubar_5')

bedmap = DataFactory.get_bedmap1()
bm = DataInput(bedmap, gen_space=False)

do = DataOutput(out_dir)
do.write_matlab(bm, model.Ubar, 'Ubar_5', val=0.0)
示例#15
0
  valid  = intersect1d(valid, where(U_mag > 0)[0])
valid  = intersect1d(valid, where(U_ob_v > 1e-9)[0])
valid  = intersect1d(valid, where(abs(Mb_v) < 200)[0])
valid  = intersect1d(valid, where(S_v > -100)[0])
valid  = intersect1d(valid, where(Ts_v > 100)[0])
valid  = intersect1d(valid, where(h_v > 0)[0])
valid  = intersect1d(valid, where(S_v - B_v > 60)[0])
valid  = intersect1d(valid, where(adot_v > -100)[0])

valid_f          = Function(Q)
valid_f_v        = valid_f.vector().array()
valid_f_v[valid] = 1.0
valid_f.vector().set_local(valid_f_v)
valid_f.vector().apply('insert')

rignot   = DataFactory.get_gre_rignot()
drg      = DataInput(rignot, gen_space=False)

betaMax = 200.0

ini_f = Function(Q)
ini_f.vector()[:] = ini
plotIce(drg, ini_f, name='ini', direc='images/stats/' + file_n,
        cmap='gist_yarg', scale='log', numLvls=12, tp=False,
        tpAlpha=0.5, show=False, umin=1.0, umax=betaMax)

Ubar_avg_f = Function(Q)
Ubar_avg_f.vector()[:] = Ubar_avg
plotIce(drg, Ubar_avg_f, name='Ubar_avg', direc='images/stats/' + file_n,
        title=r'$\Vert \mathbf{\bar{u}}_{\bar{bv}} \Vert$', cmap='gist_yarg', 
        scale='log', numLvls=12, tp=False,
示例#16
0
from varglas.helper               import default_nonlin_solver_params
from varglas.utilities            import DataInput
from fenics                       import *
import varglas.model              as model

# Output directory
out_dir = 'age_bp/'

set_log_active(True)

# Load my mesh
mesh = Mesh('data/meshes/ant_mesh.xml')

# Get a bunch of data to use in the simulation 
thklim = 100.0
bedmap1   = DataFactory.get_bedmap1(thklim=thklim)
bedmap2   = DataFactory.get_bedmap2(thklim=thklim)

db1 = DataInput(bedmap1,  mesh=mesh)
db2 = DataInput(bedmap2,  mesh=mesh)

# This code is 
db2.data['B'] = db2.data['S'] - db2.data['H']
db2.set_data_val('H', 32767, thklim)
db2.data['S'] = db2.data['B'] + db2.data['H']

S      = db2.get_spline_expression("S")
B      = db2.get_spline_expression("B")
adot   = db1.get_spline_expression("adot")

# Setup the model
from varglas.helper               import default_nonlin_solver_params
from varglas.utilities            import DataInput
from fenics                       import *
import varglas.model              as model

# Output directory
out_dir = 'results_dir3/'

#set_log_active(True)
parameters["allow_extrapolation"] = True

mesh = Mesh('data/meshes/ant_mesh.xml')

# Get a bunch of data to use in the simulation 
thklim = 100.0
measures  = DataFactory.get_ant_measures(res=900)
bedmap1   = DataFactory.get_bedmap1(thklim=thklim)
bedmap2   = DataFactory.get_bedmap2(thklim=thklim)

dm  = DataInput(measures, mesh=mesh)
db1 = DataInput(bedmap1,  mesh=mesh)
db2 = DataInput(bedmap2,  mesh=mesh)

# Fix some stuff?
db2.data['B'] = db2.data['S'] - db2.data['H']
db2.set_data_val('H', 32767, thklim)
db2.data['S'] = db2.data['B'] + db2.data['H']

S      = db2.get_spline_expression("S")
B      = db2.get_spline_expression("B")
T_s    = db1.get_spline_expression("srfTemp")
示例#18
0
a_conv = arange(len(a_valid))
g_conv = arange(len(a_valid), len(g_valid) + len(a_valid))

a_valid_f = Function(a_Q)
a_valid_f_v = a_valid_f.vector().array()
a_valid_f_v[a_valid] = 1.0
a_valid_f.vector().set_local(a_valid_f_v)
a_valid_f.vector().apply('insert')

g_valid_f = Function(g_Q)
g_valid_f_v = g_valid_f.vector().array()
g_valid_f_v[g_valid] = 1.0
g_valid_f.vector().set_local(g_valid_f_v)
g_valid_f.vector().apply('insert')

measures = DataFactory.get_ant_measures(res=900)
dm = DataInput(measures, gen_space=False)

rignot = DataFactory.get_gre_rignot()
drg = DataInput(rignot, gen_space=False)

betaMax = 200.0

#===============================================================================

#plotIce(dm, a_valid_f, name='valid', direc=a_fn,
#        cmap='gist_yarg', scale='bool', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False)
#
#plotIce(drg, g_valid_f, name='valid', direc=g_fn,
#        cmap='gist_yarg', scale='bool', numLvls=12, tp=False,
示例#19
0
from varglas.io import DataInput, DataOutput
from fenics import *

# get the input args :
i = int(sys.argv[2])  # assimilation number
dir_b = sys.argv[1] + '/0'  # directory to save

# set the output directory :
out_dir = dir_b + str(i) + '/'
in_dir = 'vars/'

set_log_active(True)

thklim = 1.0

measures = DataFactory.get_ant_measures(res=450)
bedmap1 = DataFactory.get_bedmap1(thklim=thklim)
bedmap2 = DataFactory.get_bedmap2(thklim=thklim)

mesh = MeshFactory.get_ronne_3D_50H()

dm = DataInput(measures, mesh=mesh)
db1 = DataInput(bedmap1, mesh=mesh)
db2 = DataInput(bedmap2, mesh=mesh)

db2.data['B'] = db2.data['S'] - db2.data['H']
db2.set_data_val('H', 32767, thklim)
db2.data['S'] = db2.data['B'] + db2.data['H']

H = db2.get_nearest_expression("H")
S = db2.get_nearest_expression("S")
示例#20
0
""" This scripts builds a flat mesh for a rectangular region in Antarctica and 
refines it based on thickness. """

from varglas.data.data_factory import DataFactory
from varglas.utilities import DataInput, MeshGenerator, MeshRefiner
from fenics import *
from numpy import *
from pylab import *

thklm = 200.0
bm2 = DataFactory.get_bedmap2(thklm)
bedmap2 = DataInput(bm2)

# Load the domain coordinates
domain_coordinates = loadtxt('domain_coordinates1.out')

mesh_name = 'ant_mesh'

# Create a contour for the domain
#=======================================================
# Create a mesh file in the current directory 
m = MeshGenerator(bedmap2, mesh_name, '')
# Manually set the countour instead of calculating it automatically
m.set_contour(domain_coordinates)
# Write the contour points to the mesh file
m.write_gmsh_contour(100000, boundary_extend = False)
# Extrude the flat mesh 10,000 meters in the z dimension. The height of the 
# mesh can be automatically scaled to the proper height by the model object
m.extrude(10000, 14)
# We're finished with the flat mesh!
m.close_file()
示例#21
0
from varglas.data.data_factory import DataFactory
from varglas.mesh.mesh_factory import MeshFactory
from varglas.utilities import DataInput
from varglas.model import Model
from varglas.solvers import SteadySolver, TransientSolver
from varglas.physical_constants import IceParameters
from varglas.helper import default_nonlin_solver_params
from fenics import set_log_active, parameters

set_log_active(True)

thklim = 50.0

vara = DataFactory.get_searise(thklim=thklim)
mesh = MeshFactory.get_greenland_coarse()
dsr = DataInput(vara, mesh=mesh)

S = dsr.get_spline_expression('S')
B = dsr.get_spline_expression('B')
SMB = dsr.get_spline_expression('adot')
T_s = dsr.get_spline_expression('T')
q_geo = dsr.get_spline_expression('q_geo')
U_ob = dsr.get_spline_expression('U_ob')
Tn = vara['Tn']['map_data']

# create the model :
model = Model()

model.set_mesh(mesh)
model.set_geometry(S, B, deform=True)
model.set_parameters(IceParameters())
示例#22
0
File(in_dir + 'B_s.xml') >> B

config = default_config()
config['output_path'] = out_dir
config['model_order'] = 'SSA'

model = model.Model(config)
model.set_mesh(mesh)
model.set_surface_and_bed(S, B)
model.initialize_variables()

model.init_adot(in_dir + 'adot_s.xml')
model.init_Mb(in_dir + 'Mb_s.xml')
model.init_component_Ubar(in_dir + 'ubar_s.xml', in_dir + 'vbar_s.xml',
                          in_dir + 'wbar_s.xml')

model.save_pvd(model.adot, 'adot')

F = physics.SurfaceMassBalance(model, config)

F.solve()

model.save_pvd(model.adot, 'smb')
model.save_xml(model.adot, 'smb')

bamber = DataFactory.get_bamber(thklim=0.0)
dbm = DataInput(bamber, mesh=mesh)

do = DataOutput(out_dir)
do.write_matlab(dbm, model.adot, 'smb', val=0.0)