Skip to content

Commit

Permalink
Merge 630c576 into cb8bb94
Browse files Browse the repository at this point in the history
  • Loading branch information
wpreimes committed Nov 4, 2019
2 parents cb8bb94 + 630c576 commit c1ff0f3
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions ismn/interface.py
Expand Up @@ -541,18 +541,47 @@ def __init__(self, path_to_data, network=None):
in numpy file in folder path_to_data/python_metadata/
First initialization can take a minute or so if all ISMN
data is present in path_to_data
Parameters
---------
path_to_data : str
Path to the downloaded ISMN data
network : list or str, optional (default: None)
Name of a network in the initialised path or multiple networks as
a list of strings that are activated and loaded.
"""
self.path_to_data = path_to_data

# read cci landcover class names and their identifiers
config = configparser.ConfigParser()
config.optionxform = str
config.read_file(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'classifications.ini')))
landcover = dict(config.items('LANDCOVER'))
self.landcover = dict([(int(v), k) for k, v in landcover.items()])
self.climate = dict(config.items('KOEPPENGEIGER'))

self.activate_network(network)

if not os.path.exists(os.path.join(path_to_data, 'python_metadata', 'metadata.npy')):
os.mkdir(os.path.join(path_to_data, 'python_metadata'))
def activate_network(self, network):
"""
Load or update metadata for reading one or multiple networks.
Parameters
---------
network : list or str
Name of a network in the initialised path or multiple networks as
a list of strings that are loaded.
"""
if not os.path.exists(os.path.join(self.path_to_data, 'python_metadata', 'metadata.npy')):
os.mkdir(os.path.join(self.path_to_data, 'python_metadata'))
self.metadata = metadata_collector.collect_from_folder(
path_to_data)
self.path_to_data)
np.save(
os.path.join(path_to_data, 'python_metadata', 'metadata.npy'), self.metadata)
os.path.join(self.path_to_data, 'python_metadata', 'metadata.npy'), self.metadata)
#np.savetxt(os.path.join(path_to_data,'python_metadata','metadata.npy'), self.metadata,delimiter=',')
else:
self.metadata = np.load(
os.path.join(path_to_data, 'python_metadata', 'metadata.npy'),
os.path.join(self.path_to_data, 'python_metadata', 'metadata.npy'),
allow_pickle=True)

if network is not None:
Expand All @@ -572,14 +601,6 @@ def __init__(self, path_to_data, network=None):
self.metadata['latitude'],
setup_kdTree=False)

# read cci landcover class names and their identifiers
config = configparser.ConfigParser()
config.optionxform = str
config.read_file(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'classifications.ini')))
landcover = dict(config.items('LANDCOVER'))
self.landcover = dict([(int(v), k) for k, v in landcover.items()])
self.climate = dict(config.items('KOEPPENGEIGER'))

def list_networks(self):
"""
returns numpy.array of networks available through the interface
Expand Down

0 comments on commit c1ff0f3

Please sign in to comment.