Skip to content

Commit 2202d58

Browse files
rhinoellaSpitztrisyoungs
authored
Outputs Update #2 - Run Gudrun in Temporary Directory (#460)
* Adjusted handling of temp directory * Removed shutil.rmtree * Docstring update * Does not delete/replce existing outputs * Organised iterator files, fixed some bugs * Modified import statements to align with new directory structure * Stored strings in variables * Uniquify default parameter names * Created extra util functions for uniquifying names and filenames * Output file handling process change * Output file handling process change in main window * Modifying dialog functions as needed * Formatting * Removed debugging print statements * Removed debugging print statements * fixed duplication of sample background directory * Documentation and commenting * Documentation and commenting * Fixed iteration counting * Fixed wavelength subtraction iterator * Applied changes to batch processing * Attempting to fix windows build * Attempting to fix windows build * Fix windows build? Make sure dir exists * Creating gudrun file in temp directory * Comments * Gudrun runs in temporary directory, files are copied over * Organised and renamed, gave more responsibility to iterator objects * Fixed output handler resetting * Refactored and fixed output handler to work with new system * updated imports * updated imports * updated imports * Refactored mainwindow.py and fixed process * Moved dialogs to one module * Applied new changes to test * Removed unecessary parameter * removed unecessary import * Changed the way outputs work- directory now overwrites * Removed uneeded parameter * Removing previous output dir if exists * Combined naive organise and iterative into one function, changed the way files are moved over * Fixed spelling * Fixed issues, works as expected now * Updated docstrings and output handling function * Changed inelasticity menu name to be consistent * Better clarity of 'default' run, refactored code * Changed function naming to be private, updated to not require nCurrent * Added assertions and set run dir function * Updated parameters for new organiseoutput * Fixed and modified output tree * Updated inelasticity to be the only one that saves all iter outputs * removed unused import * Creating and asserting gudrun is run in tempdir * Fix bug * Bug fixes * Output file handler returns path information * Fixing nTotal in init composition * Fix tests * Fixing tests * Fixing tests * Formatting * Formatting * Bug fix * Fixing undeclared var issue * Fix write_out * Attempt to fix tests and improve iterators * Fixed errors * Fixed linting * Linting * WIP Fix * Changing temp directory control * Debug * Cwd change * Fix prev commit * Debugging * Attempt to fix test * lint * Create base class for output handler * Run purge in temp dir * Output organising fixes- proper gudfile path * Iterator fixes * Make each iteration run in new temp dir * Composition iterator * Iterate by composition * Iterate by composition * Formatting * Fix progress bar * Fix merge * Fixing tests * Fix wavelength iterator * Fix asserion- invalid use of try except * Use POpen instead of run * Remove print * Refactor purge file * Fix composition iterator * Fix wavelength iteration process * Create gudrun worker * Create gudrun worker * Fix iterator * Fix assertions * Improve purge running and fix issue * Removing unecessary organise output * Used threading instead of qprocess, altered purge dialog, secured temp dir * Refactor * Refactor * Fixes for new changes * Fixes for new changes * Fixes for new changes * Remove print * Linting * Verbose test * Verbose test * Verbose test * Fix hanging tests by manually error checking gudrun and stop using popen.wait() * Fix hanging tests by manually error checking gudrun and stop using popen.wait() * Fix exception for windows * Fixing tests * Debugging * Fix test error * Fix test error * Outputs fix 2.5 (#461) * Changed window title to only show filename (#456) * Changing temp directory control * Debug * Cwd change * Fix prev commit * Debugging * Attempt to fix test * Upgrade PySide version to 6.6.0 (#463) Co-authored-by: Spitz <[email protected]> * lint * Fix IDAaaS Setup Script (#471) * Install XCB cursor lib. * More RPM requirements. * Fixes November 2023 (#473) * Add window title modification placeholder. * Add detectorCalibrationFileName to GudPyFileLibray and harmonise name capitalisation to reflect UI. * Notify user that all files were found. * Fix file types for input file dialog. * Be more careful about raising that dialog. * Don't forget to re-enable GUI after failing to find gudrun_dcs binary. * Formatting. * Create base class for output handler * Run purge in temp dir * Output organising fixes- proper gudfile path * Iterator fixes * Make each iteration run in new temp dir * Composition iterator * Iterate by composition * Iterate by composition * Formatting * Fix progress bar * Fix merge * Fixing tests * Display live output from running processes (#474) * Live output of processes * Change 'setText' to append for smoother experience + remove unecessary code * Remove comment --------- Co-authored-by: Spitz <[email protected]> * Fix wavelength iterator * Fix asserion- invalid use of try except * Use POpen instead of run * Remove print * Refactor purge file * Fix composition iterator * Fix wavelength iteration process * Create gudrun worker * Create gudrun worker * Fix iterator * Fix assertions * Improve purge running and fix issue * Removing unecessary organise output * Used threading instead of qprocess, altered purge dialog, secured temp dir * Refactor * Refactor * Fixes for new changes * Fixes for new changes * Fixes for new changes * Remove print * Linting * Verbose test * Verbose test * Verbose test * Fix hanging tests by manually error checking gudrun and stop using popen.wait() * Fix hanging tests by manually error checking gudrun and stop using popen.wait() * Fix exception for windows * Fixing tests * Debugging * Fix test error * Fix test error --------- Co-authored-by: Spitz <[email protected]> Co-authored-by: Tristan Youngs <[email protected]> * Fix purge and bugs * Output YAML file to project directory * Update main_window.py * Fix export dialog and remove inputfiledir var * Create loadFile variable-GudrunFile * Fix incorrect var name * Fix tests with new loadFile variable * Print dicts * Retrieve gudfile using function * Apply suggestions from code review * Remove blank line * Fix tests * Fix write-out paths * Fix path to loadfile * Fix test * Remove actions step debug * Remove print debugging * Fix test * Fix test * Update ui * Fix test to use abspath * Use abspath * Remove abspath * Remove assertion * Fix test * Do abspath * Fix * Undo * try fix again * Remove paths from assertion * Debugging * debug * debug * attempt to fix test * Specify encoding * Debug * Remove debugging and parse data file directory as abspath * Include trailling slash to path * Include trailling slash to path * Debug again * Fix path on water.txt * Remove debugging * Test everything --------- Co-authored-by: Spitz <[email protected]> Co-authored-by: Tristan Youngs <[email protected]>
1 parent 5b2943a commit 2202d58

37 files changed

+1521
-1484
lines changed

.github/workflows/test/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ runs:
3232
shell: bash
3333
run: |
3434
cd gudpy
35-
nose2 --with-coverage --coverage-report xml --plugin nose2.plugins.junitxml --junit-xml test
36-
35+
nose2 --with-coverage --coverage-report xml --plugin nose2.plugins.junitxml --junit-xml --verbose test
3736
mkdir ../results
3837
mv nose2-junit.xml ../results/nose2-junit-${{ runner.os }}.xml
3938

gudpy/core/file_library.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def __init__(self, gudrunFile):
4040

4141
# Collect directories
4242
self.dirs = {
43-
"Input file directory": gudrunFile.instrument.GudrunInputFileDir,
4443
"Data file directory": gudrunFile.instrument.dataFileDir,
4544
"Gudrun start folder": gudrunFile.instrument.GudrunStartFolder,
4645
"Startup file folder": gudrunFile.instrument.startupFileFolder,
@@ -172,14 +171,14 @@ def exportMintData(
172171
):
173172
if not exportTo:
174173
exportTo = os.path.join(
175-
self.gudrunFile.instrument.GudrunInputFileDir,
174+
self.gudrunFile.projectDir,
176175
Path(self.gudrunFile.path).stem + ".zip",
177176
)
178177
with ZipFile(exportTo, "w", ZIP_DEFLATED) as zipFile:
179178
for sample in samples:
180179
if len(sample.dataFiles.dataFiles):
181180
path = os.path.join(
182-
self.gudrunFile.instrument.GudrunInputFileDir,
181+
self.gudrunFile.projectDir,
183182
sample.dataFiles.dataFiles[0].replace(
184183
self.gudrunFile.instrument.dataFileType, "mint01"
185184
),
@@ -195,12 +194,12 @@ def exportMintData(
195194
zipFile.write(path, arcname=os.path.basename(outpath))
196195
if includeParams:
197196
path = os.path.join(
198-
self.gudrunFile.instrument.GudrunInputFileDir,
197+
self.gudrunFile.projectDir,
199198
safeSampleName + ".sample",
200199
)
201200
if not os.path.exists(path):
202201
sample.write_out(
203-
self.gudrunFile.instrument.GudrunInputFileDir
202+
self.gudrunFile.projectDir
204203
)
205204
zipFile.write(path, arcname=os.path.basename(path))
206205

gudpy/core/gud_file.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from core.exception import ParserException
22

33
import os
4-
from os.path import isfile
54
import re
65
from decimal import Decimal, getcontext
76
getcontext().prec = 5
@@ -80,6 +79,7 @@ class GudFile:
8079
write_out(overwrite=False)
8180
Writes out the string representation of the GudFile to a file.
8281
"""
82+
8383
def __init__(self, path):
8484
"""
8585
Constructs all the necessary attributes for the GudFile object.
@@ -90,6 +90,18 @@ def __init__(self, path):
9090
path : str
9191
Path to the file.
9292
"""
93+
94+
# Handle edge cases - invalid extensions and paths.
95+
if not path:
96+
raise ParserException("Please supply a valid path.")
97+
98+
if not path.endswith(".gud"):
99+
raise ParserException(f"Attempted to parse {path}" +
100+
"\nOnly .gud files can be parsed.")
101+
102+
if not os.path.isfile(path):
103+
raise ParserException(f"{path} is not a valid path.")
104+
93105
self.path = path
94106

95107
# Construct the outpath
@@ -119,13 +131,6 @@ def __init__(self, path):
119131
self.stream = []
120132
self.output = ""
121133

122-
# Handle edge cases - invalid extensions and paths.
123-
if not self.path.endswith(".gud"):
124-
raise ParserException("Only .gud files can be parsed.")
125-
126-
if not isfile(self.path):
127-
raise ParserException("Please provide a valid path.")
128-
129134
# Parse the GudFile
130135
self.parse()
131136

@@ -273,10 +278,10 @@ def parse(self):
273278
else:
274279
percentage = float(re.findall(floatRegex, output)[0])
275280
if percentage < 100:
276-
diff = float(Decimal(100.0)-Decimal(percentage))
281+
diff = float(Decimal(100.0) - Decimal(percentage))
277282
self.output = f"-{diff}%"
278283
elif percentage > 100:
279-
diff = float(Decimal(percentage)-Decimal(100.0))
284+
diff = float(Decimal(percentage) - Decimal(100.0))
280285
self.output = f"+{diff}%"
281286
else:
282287
self.output = "0%"
@@ -288,10 +293,10 @@ def parse(self):
288293

289294
except Exception as e:
290295
raise ParserException(
291-
f"Whilst parsing {self.path}, an exception occured."
292-
" It's likely gudrun_dcs failed, and invalid values"
293-
" were yielded. "
294-
f"{str(e)}"
296+
f"Whilst parsing {self.path}, an exception occured."
297+
" It's likely gudrun_dcs failed, and invalid values"
298+
" were yielded. "
299+
f"{str(e)}"
295300
) from e
296301

297302
def __str__(self):

0 commit comments

Comments
 (0)