-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnc_data.py
44 lines (37 loc) · 1.27 KB
/
nc_data.py
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
import os
from aiida.orm import RemoteData
class NetCdfData(RemoteData):
def __init__(
self,
filepath=None,
remote_path=None,
g_att=None,
nc_dimensions=None,
other = {},
**kwargs,
):
"""
Data plugin for Netcdf files.
"""
super().__init__(**kwargs)
if filepath is not None:
filename = os.path.basename(filepath)
self.set_remote_path(remote_path)
self.set_filename(filename)
self.set_global_attributes(g_att, nc_dimensions)
if other:
for k,v in other.items():
self.base.attributes.set(k, v)
def set_filename(self, val):
self.base.attributes.set("filename", val)
def set_global_attributes(self, g_att, nc_dimensions):
self.base.attributes.set("global_attributes", g_att)
self.base.attributes.set("dimensions", nc_dimensions)
def ncdump(self):
"""Small python version of ncdump."""
print("dimensions:")
for k, v in self.base.attributes.get("dimensions").items():
print(f"\t {k} = {v}")
print("// global attributes:")
for k, v in self.base.attributes.get("global_attributes").items():
print(f"\t :{k} = {v}")