コード例 #1
0
def find_vis_cycles(testname):
    """Parses the output of the run to collect the cycles that were written."""
    try:
        keys, t, d = parse_ats.readATS(dirname(testname))
    except IOError:
        try:
            keys, t, d = parse_ats.readATS(dirname(testname),
                                           "visdump_surface_data.h5")
        except IOError:
            raise IOError(
                "Unable to open {0}/visdump_data.h5 (or the surface equivalent)"
                .format(testname))

    d.close()
    return [int(k) for k in keys]
コード例 #2
0
def ats_to_pflotran_bcs_h5(directory=".", output_filename="pflotran_bcs.h5"):
    ixy = mesh.meshCentroidsStructuredOrdering_3D(
        order=[
            "x",
        ], filename="visdump_surface_mesh.h5", directory=directory)

    keys, times, dat = parse_ats.readATS(directory,
                                         "visdump_surface_data.h5",
                                         timeunits='s')

    with h5py.File(os.path.join(directory, output_filename), 'w') as fout:
        fout.create_dataset("time [s]", data=np.array(times))
        T = fout.create_group("surface temperature [K]")
        for i, k in enumerate(keys):
            T.create_dataset(
                "%d" % i,
                data=dat['surface-temperature.cell.0'][k][:][ixy['id']])

        flx = fout.create_group("outward molar flux [mol m^-2 s^-1]")

        # need the face area
        face_areas = mesh.meshElemVolume(filename="visdump_surface_mesh.h5",
                                         directory=directory)

        for i, k in enumerate(keys):
            flux_dat = dat['surface_subsurface_flux.cell.0'][k][:]
            flux_dat = flux_dat / face_areas
            flx.create_dataset("%d" % i, data=flux_dat[ixy['id']])
コード例 #3
0
ファイル: plot_water_table.py プロジェクト: spvfly/ats
def water_table(dirname, datum=None, v86=False, patm=101325.):
    prefix = "" if v86 else "surface-"

    # get the ponded depth
    keys, times, dats = parse_ats.readATS(dirname, "visdump_surface_data.h5")
    pd = parse_ats.getSurfaceData(keys, dats, prefix + "ponded_depth")
    elev_surf = dats[prefix + "elevation.cell.0"][keys[0]][0]
    dats.close()

    if datum is None:
        datum = elev_surf
    datum_offset = elev_surf - datum

    # get the columnar pressure
    wt = np.zeros((len(keys), ), 'd')
    col_dat = column_data.column_data([
        'pressure',
    ], directory=dirname)
    for k in range(col_dat.shape[1]):
        if pd[k] > 0:
            wt[k] = pd[k] + datum_offset
        else:
            wt_index = np.where(col_dat[1, k, :] >= patm)[0]
            if len(wt_index) is 0:
                wt_index = 0
            else:
                wt_index = wt_index[-1]
            wt[k] = col_dat[0, k, wt_index] - datum
    return times, wt
コード例 #4
0
ファイル: plot_thaw_depth.py プロジェクト: xiajz/ats
def thaw_depth(dirname, datum=None, v86=False, T0=273.15):
    prefix = "" if v86 else "surface-"

    # get the unfrozen fraction, ponded depth
    keys,times,dats = parse_ats.readATS(dirname, "visdump_surface_data.h5")
    pd = parse_ats.getSurfaceData(keys, dats, prefix+"ponded_depth")
    uf = parse_ats.getSurfaceData(keys, dats, prefix+"unfrozen_fraction")
    elev_surf = dats[prefix+"elevation.cell.0"][keys[0]][0]
    dats.close()
    
    if datum is None:
        datum = elev_surf
    datum_offset = elev_surf - datum

    td = np.zeros((len(keys),),'d')
    # get the columnar temperature
    col_dat = column_data.column_data(['temperature',], directory=dirname)
    for k in range(col_dat.shape[1]):
        if uf[k] == 0.:
            td[k] = pd[k] + datum_offset
        else:
            td[k] = pd[k] * (1 - uf[k]) + datum_offset

            still_unfrozen = True
            c = col_dat.shape[2]-1
            while still_unfrozen and c >= 0:
                if col_dat[1,k,c] > T0:
                    td[k] = col_dat[0,k,c] - datum
                    c = c - 1
                else:
                    still_unfrozen = False
    return times, td
コード例 #5
0
ファイル: plot_water_table.py プロジェクト: amanzi/ats-dev
def water_table(dirname, datum=None, v86=False, patm=101325.):
    prefix = "" if v86 else "surface-"

    # get the ponded depth
    keys,times,dats = parse_ats.readATS(dirname, "visdump_surface_data.h5")
    pd = parse_ats.getSurfaceData(keys, dats, prefix+"ponded_depth")
    elev_surf = dats[prefix+"elevation.cell.0"][keys[0]][0]
    dats.close()
    
    if datum is None:
        datum = elev_surf
    datum_offset = elev_surf - datum

    # get the columnar pressure
    wt = np.zeros((len(keys),),'d')
    col_dat = column_data.column_data(['pressure',], directory=dirname)
    for k in range(col_dat.shape[1]):
        if pd[k] > 0:
            wt[k] = pd[k] + datum_offset
        else:
            wt_index = np.where(col_dat[1,k,:] >= patm)[0]
            if len(wt_index) is 0:
                wt_index = 0
            else:
                wt_index = wt_index[-1]
            wt[k] = col_dat[0,k,wt_index] - datum
    return times, wt
コード例 #6
0
def load_area_rain(args):
    k, t, d = parse_ats.readATS(args.directory, args.filename)
    cv = d[args.area_key][k[0]][:]
    area = cv.sum()
    rain = np.array([(d[args.rainfall_rate_key][key][:] * cv).sum()
                     for key in k]) * 86400
    return area, t * 365.25, rain  # units m^2, days, m^3/s
コード例 #7
0
    def __init__(self,
                 dirname,
                 names=None,
                 gravity=9.80665,
                 typical_density=55000.):
        """Create a simulation class.
        
        Usage:
          with MassBalanceFromVis(dirname) as sim:
              ...
        
        Arguments:
          dirname        | The directory where output is.
          names          | A dictionary mapping common names to variable names in the 
                         | visualization files.  Defaults are provided, and most 
                         | simulations need not override them. (default=None)
          gravity        | Magnitude of gravity (default=9.80665 is the standard ATS value used)
          typical_density| A typical molar density of liquid, used to print things in [m] instead of [mol]
        
        Note that this should typically be used in 'with ... as' context, as this opens file 
        resources which should be closed on exit.  Alternatively, close() can be called directly
        by the user.
        """
        self.dirname = dirname
        if names is not None:
            self._names.update(names)
        self.gravity = gravity
        self.p_atm = 101325.0

        # load the vis files
        self._keys, self.times, self._dat = parse_ats.readATS(dirname,
                                                              timeunits='d')
        self._keys_s, self.times_s, self._dat_s = parse_ats.readATS(
            dirname, 'visdump_surface_data.h5', timeunits='d')
        if len(self._keys) != len(self._keys_s):
            print "Warning: surface and subsurface visualization files are of different lengths! (%d, %d)" % (
                len(self._keys), len(self._keys_s))
        self.length = min(len(self._keys), len(self._keys_s))

        # save cell volume instead of loading it repeatedly
        self.volumes = self["cell volume", 0]
        self.volume = self.volumes.sum()
        self.areas = self["surface cell volume", 0]
        self.surface_area = self.areas.sum()

        self.typical_density = typical_density
コード例 #8
0
ファイル: mass_balance.py プロジェクト: amanzi/ats-dev
    def __init__(self, dirname, names=None, gravity=9.80665, typical_density=55000.):
        """Create a simulation class.
        
        Usage:
          with MassBalanceFromVis(dirname) as sim:
              ...
        
        Arguments:
          dirname        | The directory where output is.
          names          | A dictionary mapping common names to variable names in the 
                         | visualization files.  Defaults are provided, and most 
                         | simulations need not override them. (default=None)
          gravity        | Magnitude of gravity (default=9.80665 is the standard ATS value used)
          typical_density| A typical molar density of liquid, used to print things in [m] instead of [mol]
        
        Note that this should typically be used in 'with ... as' context, as this opens file 
        resources which should be closed on exit.  Alternatively, close() can be called directly
        by the user.
        """
        self.dirname = dirname
        if names is not None:
            self._names.update(names)
        self.gravity = gravity
        self.p_atm = 101325.0
        
        # load the vis files
        self._keys, self.times, self._dat = parse_ats.readATS(dirname, timeunits='d')
        self._keys_s, self.times_s, self._dat_s = parse_ats.readATS(dirname, 'visdump_surface_data.h5', timeunits='d')
        if len(self._keys) != len(self._keys_s):
            print "Warning: surface and subsurface visualization files are of different lengths! (%d, %d)"%(len(self._keys),len(self._keys_s))
        self.length = min(len(self._keys), len(self._keys_s))

        # save cell volume instead of loading it repeatedly
        self.volumes = self["cell volume",0]
        self.volume = self.volumes.sum()
        self.areas = self["surface cell volume",0]
        self.surface_area = self.areas.sum()
        
        self.typical_density = typical_density
コード例 #9
0
ファイル: sample.py プロジェクト: xiajz/ats
def model(pars,hostname,processor):

    # Modify base ats xml input file with pars dictionary and run ats
    m = atsxml.get_root('../test7-v_fwd.xml')
    atsxml.replace_by_path(m,['base_porosity','rest domain','value'],pars['poro_m'])
    atsxml.replace_by_path(m,['base_porosity','peat','value'],pars['poro_p'])
    atsxml.replace_by_path(m,['permeability','rest domain','value'],10**pars['perm_m'])
    atsxml.replace_by_path(m,['permeability','peat','value'],10**pars['perm_p'])
    atsxml.run(m,nproc=4,stdout='stdout.out',stderr='stdout.err',cpuset=processor) 

    # Read results from ats visualization files
    #keys,times,file handle
    k,t,f = parse_ats.readATS()
    # Collect point at middle of polygon 1 m deep
    # x,z = 7.17946807, 4.65764252
    # index for this location is 1733, see below how to find this
    # Create output dictionary that matches MATK observations
    out = {}
    out['Sl'] = f[u'saturation_liquid.cell.0/'+k[-1]][1733]
    out['T'] = f[u'temperature.cell.0/'+k[-1]][1733]

    # Return simulated values of interest
    return out
コード例 #10
0
ファイル: plot_surface_balance.py プロジェクト: xiajz/ats
        hackfactor = None
        if dirname == "run-transient4":
            hackfactor = 2.0

        if args.colors is None:
            if len(dirnames) > 1:
                c = cm(float(i) / (len(dirnames) - 1))
            else:
                c = 'b'
        else:
            if type(args.colors[i]) is float:
                c = cm(args.colors[i])
            else:
                c = args.colors[i]

        ktd = parse_ats.readATS(dirname,
                                get_filename_base('surface', domain_suffix))
        if version == 'dev-new':
            ktds = parse_ats.readATS(dirname,
                                     get_filename_base('snow',
                                                       domain_suffix))[2]
        else:
            ktds = None
        plot_surface_balance((ktd[0], ktd[1], (ktd[2], ktds)),
                             axs,
                             c,
                             label=dirname,
                             hackfactor=hackfactor,
                             version=version,
                             marker=marker,
                             domain_suffix=domain_suffix)
        if ktds is not None:
コード例 #11
0
fig, axes = plt.subplots(4, 2, sharex=True)

#fname = 'ThawData_Yr10_All.csv'
#with open(fname, 'wb') as csvFile:
#	writer = csv.writer(csvFile, delimiter=',')

for i in range(len(runPrefixList)):
    y = np.nan * np.ones([nruns, len(trange)], 'd')
    for j in range(nruns):
        directory = runPrefixList[i] + '_' + runDate + '.' + str(j + 1)
        isDir = os.path.isdir(os.getcwd() + '/' + directory)
        if not isDir:
            continue
        keys, times, dat = parse_ats.readATS(directory,
                                             "visdump_data.h5",
                                             timeunits='yr')
        col_dat = transect_data.transect_data(['saturation_ice'],
                                              keys=np.s_[trange],
                                              directory=directory)
        times_subset = times[trange]
        #col_dat structure:
        #col 1 = variable
        #col 2 = time
        #col 3 = x position
        #col 4 = z position
        z_surf = col_dat[1, 0, :, -1] + (
            col_dat[1, 0, :, -1] - col_dat[1, 0, :, -2]
        ) / 2.  # average of the uppermost and second-to-uppermost rows, shifted up to the top row
        z_bott = col_dat[1, 0, :, 0] - (
            col_dat[1, 0, :, 1] - col_dat[1, 0, :, 0]
コード例 #12
0
def water_table(dirname, datum=None, v86=False, patm=101325.):
    prefix = "" if v86 else "surface-"

    # get the ponded depth
    keys,times,dats = parse_ats.readATS(dirname, "visdump_surface_data.h5")
    pd = parse_ats.get2DSurfaceData(keys, dats, prefix+"ponded_depth")

    center = len(dats[prefix+"elevation.cell.0"][keys[0]])
    print ('Center location: ', center)
    
    elev_surf = dats[prefix+"elevation.cell.0"][keys[0]][center-1]
    dats.close()
    print ('Datum (surface elevation)', elev_surf)
    if datum is None:
        datum = elev_surf
    datum_offset = elev_surf - datum

    # get the columnar pressure
    wt = np.zeros((len(keys),),'d')
    wt_ss = np.zeros((len(keys),),'d')
    wt_surf = np.zeros((len(keys),),'d')
    thaw_depth = np.zeros((len(keys),),'d')
    wt_bottom = np.zeros((len(keys),),'d')
    
    col_dat = transect_data.transect_data(['pressure', 'temperature'], directory=dirname)
        
    vars = 2
    nvar, cycles, xnum, znum = col_dat.shape
    for k in range(col_dat.shape[1]):

        if pd[k, xnum-1] > 0:
            wt[k] = pd[k, xnum-1] + datum_offset
            wt_surf[k] = pd[k, xnum-1] + datum_offset
        else:
            wt_index = np.where(col_dat[vars ,k,xnum-1, :] >= patm)[0] #var 1
            
            temp_index = np.where(col_dat[vars+1 ,k,xnum-1, :] >= 273.25)[0] ##
            temp_data = col_dat[vars + 1,k,xnum-1, :] #var 2

            wt_index0 = wt_index
            
            if len(wt_index) is 0:
                wt_index = 0
                wt_index0 = 0
            else:
                wt_index = wt_index[-1]

            if (len(wt_index0) > 2):
                wt_index0 = wt_index0[-2]
                
            if (len(temp_index) is 0):
                temp_index =0
            else:
                temp_index = temp_index[0]
            
            if (temp_data[wt_index] > 273.25):
                wt[k] = col_dat[1,k,xnum-1, wt_index] - datum
            else:
                wt_ss[k] = col_dat[1,k,xnum-1, temp_index] - datum

                
        temp_index = np.where(col_dat[vars+1 ,k,xnum-1, :] >= 273.25)[0] ##

        if len(temp_index) > 0:
            thaw_depth[k] = col_dat[1,k,xnum-1, temp_index[0]] - datum
        
    return times, wt, wt_ss, wt_bottom, thaw_depth
コード例 #13
0
def water_table2D(dirname, datum=None, location='center', v86=False, patm=101325.):
    prefix = "" if v86 else "surface-"

    # get the ponded depth
    keys,times,dats = parse_ats.readATS(dirname, "visdump_surface_data.h5")
    pd = parse_ats.get2DSurfaceData(keys, dats, prefix+"ponded_depth")

    if location == 'center':
        center = len(dats[prefix+"elevation.cell.0"][keys[0]])
    elif location == 'trough':
        center = 1
        
    print ('Location: ', location, center)
    
    elev_cell = dats[prefix+"elevation.cell.0"][keys[0]][center-1]
    dats.close()
    print ('Datum (surface elevation)', elev_cell)
    if datum is None:
        datum = elev_cell
    datum_offset = elev_cell - datum

    # get the columnar pressure
    water_table = np.zeros((len(keys),),'d')
    thaw_depth = np.zeros((len(keys),),'d')

    
    col_dat = transect_data.transect_data(['pressure', 'temperature'], directory=dirname)
        
    vars = 2
    nvar, cycles, xnum, znum = col_dat.shape
    #print xnum
    xnum = center
    #print xnum
    for k in range(col_dat.shape[1]):

        if pd[k, xnum-1] > 0:
            water_table[k] = pd[k, xnum-1] + datum_offset
            #wt_surf[k] = pd[k, xnum-1] + datum_offset
            #print 'surface:: ',k, pd[k, xnum-1]
        else:
            #print 'subsurface: ', k, pd[k, xnum-1]
            wt_index = np.where(col_dat[vars ,k,xnum-1, :] >= patm)[0] #var 1
            
            temp_index = np.where(col_dat[vars+1 ,k,xnum-1, :] >= 273.25)[0] ##
            temp_data = col_dat[vars + 1,k,xnum-1, :] #var 2

            if len(wt_index) is 0:
                wt_index = 0
            else:
                wt_index = wt_index[-1]

            if (len(temp_index) is 0):
                temp_index =0
            else:
                temp_index = temp_index[0]
            
            if (temp_data[wt_index] > 273.25):
                water_table[k] = col_dat[1,k,xnum-1, wt_index] - datum
                
        temp_index = np.where(col_dat[vars+1 ,k,xnum-1, :] >= 273.2)[0] ##
        #print col_dat[vars+1 ,k,xnum-1, :], round(times[k]*365.25,2), k
        if len(temp_index) > 0:
            #print 'ALT: ', len(temp_index), temp_index[0], col_dat[vars+1 ,k,xnum-1, temp_index[0]]

            thaw_depth[k] = col_dat[1,k,xnum-1, temp_index[0]] - datum
        
    return times, water_table, thaw_depth, elev_cell
コード例 #14
0
ファイル: plot_surface_balance.py プロジェクト: spvfly/ats
    fig, axs = get_axs()

    fnames = args.INPUT_DIRECTORIES
    for i, fname in enumerate(fnames):
        hackfactor = None
        if fname == "run-transient4":
            hackfactor = 2.0

        if args.colors is None:
            if len(fnames) > 1:
                c = cm(float(i) / (len(fnames) - 1))
            else:
                c = 'b'
        else:
            if type(args.colors[i]) is float:
                c = cm(args.colors[i])
            else:
                c = args.colors[i]

        ktd = parse_ats.readATS(fname, "visdump_surface_data.h5")
        plot_surface_balance(ktd, axs, c, label=fname, hackfactor=hackfactor)
        ktd[2].close()

    plt.tight_layout()
    axs[0].legend(bbox_to_anchor=(0., 1., 3.6, .05),
                  loc=3,
                  ncol=len(fnames),
                  mode="expand",
                  borderaxespad=0.)
    plt.show()
コード例 #15
0
        print("Directory %s got version: %s and domain_suffix: %r"%(dirname,version, domain_suffix))
        hackfactor = None
        if dirname == "run-transient4":
            hackfactor = 2.0
            
        if args.colors is None:
            if len(dirnames) > 1:
                c = cm(float(i)/(len(dirnames)-1))
            else:
                c = 'b'
        else:
            if type(args.colors[i]) is float:
                c = cm(args.colors[i])
            else:
                c = args.colors[i]

        ktd = parse_ats.readATS(dirname, get_filename_base('surface', domain_suffix))
        if version == 'dev-new':
            ktds = parse_ats.readATS(dirname, get_filename_base('snow', domain_suffix))[2]
        else:
            ktds = None
        plot_surface_balance((ktd[0], ktd[1], (ktd[2],ktds)), axs, c, label=dirname, hackfactor=hackfactor, version=version, marker=marker, domain_suffix=domain_suffix)
        if ktds is not None:
            ktds.close()
        ktd[2].close()

    plt.tight_layout()
    axs[0].legend(bbox_to_anchor=(0., 1., 3.6, .05), loc=3,
               ncol=len(dirnames), mode="expand", borderaxespad=0.)
    plt.show()