From 850c5f120342f369e9663968f58a5b1d8da9295d Mon Sep 17 00:00:00 2001
From: dfrisinghelli <daniel.frisinghelli@gmail.com>
Date: Thu, 20 May 2021 15:35:50 +0200
Subject: [PATCH] EuroCordex inventory.

---
 Python/00_get_inventory.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Python/00_get_inventory.py

diff --git a/Python/00_get_inventory.py b/Python/00_get_inventory.py
new file mode 100644
index 0000000..f5ff519
--- /dev/null
+++ b/Python/00_get_inventory.py
@@ -0,0 +1,29 @@
+"""Inventory of EuroCordex simuations."""
+
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# externals
+import pandas as pd
+
+# locals
+from pysegcnn.core.utils import search_files
+
+# parameters defining a Cordex climate simulation
+CORDEX_PARAMETERS = ['Variable', 'Domain', 'Gcm', 'Scenario', 'Ensemble',
+                     'Rcm', 'Version', 'Frequency', 'Years']
+
+
+def get_inventory(path):
+
+    # find all netcdf files in path
+    inventory = search_files(path, '(.*).nc$')
+
+    # create dictionary: (filename: [simulation parameters])
+    inventory = {k: k.stem.split('_') for k in inventory}
+
+    # create a DataFrame
+    df = pd.DataFrame(data=inventory.values(), index=inventory.keys(),
+                      columns=CORDEX_PARAMETERS)
+
+    return df
-- 
GitLab