From 405c44f7422ea38d5aae669f672a7f169a5a61ff Mon Sep 17 00:00:00 2001
From: Florian Obersteiner <florian.obersteiner@kit.edu>
Date: Thu, 7 Apr 2022 11:14:14 +0200
Subject: [PATCH] __str__ for Dataset

---
 src/icartt/dataset.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py
index 811c500..a20d933 100644
--- a/src/icartt/dataset.py
+++ b/src/icartt/dataset.py
@@ -317,7 +317,6 @@ class StandardNormalComments(collections.UserList):
         self.keywords["UNCERTAINTY"].naAllowed = False
         self.keywords["REVISION"].naAllowed = False
 
-
     def __str__(self):
         return "\n".join(f"{str(v)}" for v in self.keywords.values())
 
@@ -962,12 +961,18 @@ class Dataset:
             if not self.inputFhandle.closed:
                 self.inputFhandle.close()
 
-    def __repr__(self):
-        # TODO: this could be more meaningful
-        return "icartt.Dataset()"
-
     def __str__(self):
-        return f"ICARTT Dataset {self.makeFileName()}"
+        s = [
+            f"ICARTT Dataset {self.makeFileName()}, format index {self.format.value}",
+            f"data ID: {self.dataID}",
+            f"location ID: {self.locationID}",
+            f"PI: {self.PIName}",
+            f"Affiliation: {self.PIAffiliation}",
+            f"Mission: {self.missionName}",
+            f"Collection date, Revision date: {self.dateOfCollection}, {self.dateOfRevision}",
+            f"Variables ({len(self.variables)}):\n{', '.join(x for x in self.variables)}",
+        ]
+        return "\n".join(s)
 
     def __init__(
         self,
@@ -991,7 +996,7 @@ class Dataset:
         """
 
         self.format = format
-        self.version = None # TODO: should this be 2.0 by default?
+        self.version = None  # TODO: should this be 2.0 by default?
 
         self.dataID = "dataID"
         self.locationID = "locationID"
@@ -1038,12 +1043,11 @@ class Dataset:
 
             if not self.isValidFileName(pathlib.Path(f).name):
                 warnings.warn(f"{pathlib.Path(f).name} is not a valid ICARTT filename")
-            else: # try to obtain dataID and locationID from file name
+            else:  # try to obtain dataID and locationID from file name
                 parts = pathlib.Path(f).name.split("_")
                 if len(parts) > 2:
                     self.dataID = parts[0]
-                    self.dataID = parts[1]
-            # TODO: else -> split on "_", then the first part should be dataID, second part locationID
+                    self.locationID = parts[1]
 
             self.readHeader(delimiter)
             if loadData:
-- 
GitLab