#* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
#* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
#* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
#* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#* DEALINGS IN THE SOFTWARE.
#*
#*****************************************************************************/

import pyalps

# This is an example of how to easily calculate the mean of data stored in a hdf5 file.

filename = "testfile.h5"

# create the correct MCData object to load the data.
obs = pyalps.alea.MCScalarData()

# load the variable E saved in the file testfile.h5 into the mcdata object.
obs.load(filename, "simulation/results/" + pyalps.hdf5_name_encode("E"))

# calculate the mean
mean = pyalps.alea.mean(obs)

# print the result
print("The mean of E is: " + str(mean))

# write the result back to the file
ar = pyalps.hdf5.archive(filename, 1)
ar.write("simulation/results/" + pyalps.hdf5_name_encode("E") + "/mean/value",
         mean)
Exemple #2
0
#
# You should have received a copy of the ALPS Library License along with
# the ALPS Libraries; see the file LICENSE.txt. If not, the license is also
# available from http://alps.comp-phys.org/.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# ****************************************************************************

import pyalps as alps
import pyalps.hdf5 as h5
import pyalps.alea as alea

iar = h5.archive('loadobs.h5', 'r')

for name in iar.list_children('/simulation/results'):
    if iar.is_scalar('/simulation/results/' + alps.hdf5_name_encode(name) +
                     '/mean/value'):
        obs = alea.MCScalarData()
    else:
        obs = alea.MCVectorData()
    obs.load('loadobs.h5',
             '/simulation/results/' + alps.hdf5_name_encode(name))
    print name + ": " + str(obs)
Exemple #3
0
#* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
#* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
#* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#* DEALINGS IN THE SOFTWARE.
#*
#*****************************************************************************/

import pyalps

# This is an example of how to easily calculate the variance of data stored in a hdf5 file.

filename = "testfile.h5"

# create the correct MCData object to load the data.
obs = pyalps.alea.MCScalarData()

# load the variable E saved in the file testfile.h5 into the mcdata object.
obs.load(filename, "simulation/results/" + pyalps.hdf5_name_encode("E"))

# calculate the mean
variance = pyalps.alea.variance(obs)

# print the result
print("The variance of E is: " + str(variance))

# write the result back to the file
ar = pyalps.hdf5.archive(filename, 1)
ar.write(
    "simulation/results/" + pyalps.hdf5_name_encode("E") + "/variance/value",
    variance)
Exemple #4
0
#* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#* DEALINGS IN THE SOFTWARE.
#*
#*****************************************************************************/

import pyalps

# This is an example of how to calculate the running mean and the reverse running mean of data stored in a hdf5 file.

filename = "testfile.h5"

# create the correct MCData object to load the data.
obs = pyalps.alea.MCScalarData()

# load the variable E saved in the file testfile.h5 into the mcdata object.
obs.load(filename, "simulation/results/" + pyalps.hdf5_name_encode("E"))

# calculate the running mean
running_mean = pyalps.alea.running_mean(obs)

# calculate the reverse running mean
reverse_running_mean = pyalps.alea.reverse_running_mean(obs)

# print the result
print("The running mean of E is: " + str(running_mean))
print()
print("The reverse running mean of E is: " + str(reverse_running_mean))
print()


Exemple #5
0
def impl_calculation(name, save_path, calculate):

    usage = "Usage: %prog [options] FILE [FILE [...]]"
    parser = OptionParser(usage=usage)

    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="print detailed information")
    parser.add_option("-w",
                      "--write",
                      action="store_true",
                      dest="write",
                      help="write the result(s) back into the file(s)")
    parser.add_option(
        "-n",
        "--name",
        action="append",
        metavar="VAR",
        dest="variables",
        help=
        "variable name, can be specified multiple times [default: all variables]"
    )
    parser.add_option(
        "-p",
        "--path",
        action="store",
        metavar="HDF5-PATH",
        dest="path",
        help=
        "hdf5-path where the data is stored [default: \"/simulation/results\"]"
    )
    parser.set_defaults(verbose=False,
                        write=False,
                        variables=[],
                        path="/simulation/results")

    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.print_help()
        exit()

    variables = options.variables

    for filestring in args:
        ar = h5.archive(filestring, 1)
        if len(options.variables) == 0:
            variables = ar.list_children(options.path)
            if options.verbose:
                print("Variables in file " + filestring + ":  " +
                      " ".join(variables))

        for variablestring in variables:
            if ar.dimensions(options.path + "/" +
                             pyalps.hdf5_name_encode(variablestring) +
                             "/timeseries/data") == 1:
                obs = alea.MCScalarData()
                #_save = mcanalyze.write_dim_0
                #vector_save = mcanalyze.write_dim_1
            else:
                obs = alea.MCVectorData()
                #scalar_save = mcanalyze.write_dim_1
                #vector_save = mcanalyze.write_dim_2
            obs.load(
                filestring,
                options.path + "/" + pyalps.hdf5_name_encode(variablestring))
            result = calculate(obs)
            if options.verbose:
                print("The " + name + " of variable " + variablestring +
                      " in file " + filestring + " is: " + str(result))
            if options.write:
                ar.write(
                    options.path + "/" +
                    pyalps.hdf5_name_encode(variablestring) + "/" + save_path,
                    result)
    print("Done")
Exemple #6
0
# the terms of the license, either version 1 or (at your option) any later
# version.
#  
# You should have received a copy of the ALPS Library License along with
# the ALPS Libraries; see the file LICENSE.txt. If not, the license is also
# available from http://alps.comp-phys.org/.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
# DEALINGS IN THE SOFTWARE.
# 
# ****************************************************************************

import pyalps as alps
import pyalps.hdf5 as h5
import pyalps.alea as alea

iar = h5.archive('loadobs.h5', 'r')

for name in iar.list_children('/simulation/results'):
    if iar.is_scalar('/simulation/results/' + alps.hdf5_name_encode(name) + '/mean/value'):
        obs = alea.MCScalarData()
    else:
        obs = alea.MCVectorData()
    obs.load('loadobs.h5', '/simulation/results/' + alps.hdf5_name_encode(name))
    print name + ": " + str(obs)