-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·77 lines (60 loc) · 1.97 KB
/
Copy pathexample.py
File metadata and controls
executable file
·77 lines (60 loc) · 1.97 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
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
#
# Example on how to access case metadata information and reconstruct file names
#
# Ulf Andrae, SMHI, 2022
#
from cases import Cases
if True:
# Select cases and experiments, specify as a list or a dictionary with cases and runs within cases
# Select all
selection = {}
selection = []
selection = None
# Select one case
selection = [ 'finland_2017' ]
# Select one case and one run from this case
selection = { 'finland_2017' : ['cy43_deode_ref_fin'] }
# Load the data
example = Cases(selection=selection)
# print, try with different printlevels
example.print(printlev=1)
# Specify a selection of dates, leadtimes and file patterns
dates=[]
dates=['2017-08-10 12:00:00',
'2017-08-11 00:00:00']
leadtimes =[]
leadtimes =[0,1,2]
file_template = None
file_template = 'fc(.*)fp'
file_template = 'fc(.*)'
# Generate the file paths and names
files = example.reconstruct(dtg=dates,leadtime=leadtimes,file_template=file_template)
# Print the result
print('\nFilenames:')
[print(' ',f) for f in files]
#
# Example 2
#
if True:
selection = ['finland_2017','gavle_2021']
example2 = Cases(selection=selection,printlev=0)
example2.print(printlev=0)
case='gavle_2021'
print('\nCase:',case)
# Access one case from the cases class
files = example2.cases[case].reconstruct(leadtime=[0],file_template='(.*)fp')
print()
[print(f) for f in files]
case = 'finland_2017'
dates=['2017-08-10 12:00:00',
'2017-08-11 00:00:00']
print('\nCase:',case)
for run in example2.cases[case].runs:
# Access one run from the Exp class ( called runs here )
files = example2.cases[case].runs[run].reconstruct(leadtime=[0],file_template='(.*)fp',dtg=dates)
print(' Run:',run)
[print(' ', f) for f in files]
# Print the metadata for this case and run
print('\n--- metadata ---')
[print(' {:<20}: {}'.format(k,v)) for k,v in example2.cases[case].runs[run].__dict__.items() if k != 'data']