Base analysis printing list of tuids when a new dataset is input
- Quantify version:
- Python version:
- Operating System:
Description
When analysis code is directly on a dataset, which has a tuid attribute but does not correspond to any datafile saved in the directory, it prints a list of all of the tuids from that day, which is annoying and unecessary.
What I Did
At the moment I am debugging some new measurement code, and I want to run a Basic2DAnalysis
on a particular dataset. This particular dataset has not been saved to my directory yet, so there is no corresponding experimental folder in my directory. Nonetheless, the dataset does have a tuid attribute and all other standard properties one would expect of a dataset generated in Quantify.
I run the analysis using ba.Basic2DAnalysis(dataset=dataset).run()
What Was Expected
It should just do the analysis like normal - only because we are entering a dataset rather than a tuid, the extract_data
method should also look through the directory, see that there is no experimental folder, create this folder and save the dataset there (this is done by the code block below).
if self.dataset is not None:
# pylint: disable=fixme
# FIXME: to be replaced by a validate_dateset see #187
if "tuid" not in self.dataset.attrs.keys():
raise AttributeError('Invalid dataset, missing the "tuid" attribute')
self.tuid = TUID(self.dataset.attrs["tuid"])
# an experiment container is required to store output of the analysis.
# it is possible for this not to exist for a custom dataset as it can
# come from a source outside of the data directory.
try:
locate_experiment_container(self.tuid)
except FileNotFoundError:
# if the file did not exist, an experiment folder is created
# and a copy of the dataset is stored there.
exp_folder = create_exp_folder(tuid=self.tuid, name=self.dataset.name)
write_dataset(
path=os.path.join(exp_folder, DATASET_NAME),
dataset=self.dataset,
)
What Actually Happened
The analysis does everything that is expected, only it also prints out a list of all of that day's tuids, which is cumbersome and unecessary.
The reason it does this is because the locate_experiment_container
function always prints out this list whenever it gets a FileNotFoundError
:
# This will raise a file not found error if no data exists on the specified date
exp_folders = list(filter(lambda x: tuid in x, os.listdir(daydir)))
if len(exp_folders) == 0:
print(os.listdir(daydir))
raise FileNotFoundError(f"File with tuid: {tuid} was not found.")
Perhaps there is a reason it was originally coded like this, but I find it unecessary for this use case. The try
except
statement in the extract_data
method supresses the FileNotFoundError
, but it does not suppress this list.
I would suggest getting rid of the list. But if we definitely want to keep it, perhaps we can include it in the text string to the FileNotFoundError
error, so that it can be suppressed by a try
except
statement.