Giter Club home page Giter Club logo

Comments (3)

mikaem avatar mikaem commented on June 6, 2024

Thanks a lot for creating this issue, and sorry that you have to be a guinea pig.
The Klein Gordon demo requires matplotlib and h5py-parallel to work. The latter is in my channel on anaconda cloud and I should really make it a dependency. Will do that. For now, try to uninstall h5py and install h5py-parallel. Or restart by doing
conda create --name shenfun -c conda-forge -c spectralDNS python=3.6 shenfun h5py-parallel matplotlib

from shenfun.

apatlpo avatar apatlpo commented on June 6, 2024

Ok, thanks, the code ran successfully.

I ran into a second issue which has more to do with my inexperience with hdf5 data.
As an oceanographer I am used to deal with netcdf and reading an hdf5 file is not straitghforward for me.
My guess is that you have somewhere code that does just that but I did not find it easily
but it would be nice if it was more visible.

Anyway I came up with a simple script in order to explore the output files:

import h5py
import matplotlib.pyplot as plt
import sys, time

def print_attrs(name, obj):
    print(name)
    for key, val in obj.attrs.items():
        print('    %s: %s'.format(key, val))

if len(sys.argv) > 1:

    # open file and print variables
    fname = sys.argv[1]
    f = h5py.File(fname, 'r')

    if len(sys.argv) == 2:

        f.visititems(print_attrs)

    else:

        # go within data tree
        g=f
        for i in range(2,len(sys.argv)):
            g=g[sys.argv[i]]
            print(g)
            if i==len(sys.argv)-1:
                flag=True
                for key, val in g.items():
                    if isinstance(val, h5py.Dataset):
                        flag=False
                        if len(val.shape)==2:
                            gname=g.name[1:].replace('/','_')+'_'
                            plt.figure()
                            plt.imshow(val)
                            #print(val[:,:])
                            plt.title(gname+' '+key)
                            plt.savefig(gname+key+'.png')
                            plt.close()
                        elif len(val.shape)==3:
                            print('Data is 3D')
                        elif len(val.shape) == 1:
                            print('Data is 1D')
                if flag:
                    g.visititems(print_attrs)
f.close()

from shenfun.

mikaem avatar mikaem commented on June 6, 2024

I only use hdf5 to visualise in parallel. In the end of KleinGordon.py there is a script that generates an xdmf file. This file (which uses pointers into the hdf5 file) can be opened by paraview for visualisation. For plotting in python it is really not necessary to go through the hdf5 format. Just plot the numpy arrays. Of course, in parallel this becomes a bit problematic:-)

from shenfun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.