-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathH5extractor.py
More file actions
65 lines (49 loc) · 1.79 KB
/
H5extractor.py
File metadata and controls
65 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 28 14:01:06 2014
@author: User
"""
import pandas as pan
from Tkinter import Tk
import tkFileDialog
import re
import pandas as pan
def get_files(titlestring,filetype = ('.h5','*.h5')):
# Make a top-level instance and hide since it is ugly and big.
root = Tk()
root.withdraw()
# Make it almost invisible - no decorations, 0 size, top left corner.
root.overrideredirect(True)
root.geometry('0x0+0+0')
#
# Show window again and lift it to top so it can get focus,
# otherwise dialogs will end up behind the terminal.
root.deiconify()
root.attributes("-topmost",1)
root.focus_force()
filenames = []
filenames = tkFileDialog.askopenfilename(title=titlestring, filetypes=[filetype],multiple='True')
#do nothing if already a python list
if filenames == "":
print "You didn't open anything!"
return
if isinstance(filenames,list): return filenames
#http://docs.python.org/library/re.html
#the re should match: {text and white space in brackets} AND anynonwhitespacetokens
#*? is a non-greedy match for any character sequence
#\S is non white space
#split filenames string up into a proper python list
result = re.findall("{.*?}|\S+",filenames)
#remove any {} characters from the start and end of the file names
result = [ re.sub("^{|}$","",i) for i in result ]
root.destroy()
return result
def h5extractor(filename=[]):
if not filename:
filename=get_files('Select one HDF5 file to be parsed')
copoldat_NRB = pan.read_hdf(filename[0],'copol_NRB')
else:
copoldat_NRB = pan.read_hdf(filename,'copol_NRB')
return copoldat_NRB
if __name__=='__main__':
x=h5extractor()