Skip to content

Commit

Permalink
Create a GudPy class (#487)
Browse files Browse the repository at this point in the history
* 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

* Load from project, save as project, export input file

* Fix test

* Create class

* Merge branch 'develop' into load-project

* Check if config is used

* Refactor code

* Refactor code

* Advance GudPy exception handling, fix test failiure on empty path

* Declare outpath as const

* Fix purge calls

* Separate gudrun gui from backend- make gudpy module to handle processes

* Check for errors

* Remove unused imports

* Support error handling

* Merge

* Check for errors

* Remove unused imports

* Create gudpy class and put iterators into single module

* Merge branch 'gudpy-class' of https://github.com/disorderedmaterials/GudPy into gudpy-class

* Update imports for iterators

* Update imports for iterators

* change config_ to config

* Moving funcs from main window to control, removing responsibilities from gudrunFile

* Update workers to thread, add progression functions

* Remove use of gudrunFile from OutputHandler

* Delete gui.gudpy

* Move running processes to control class

* Create process module, remove errorOccured, return exitcodes from runs

* Create gui.py to initialise application (rename gui.gudpy to gui.gui)

* Remove 'errorOccured' from gudpy process classes

* Delete process.py

* Create gudrun iterator

* Remove iteration functions from iterators

* Improve and updat composition iterator

* Add compositioniterate function

* Removed update from file

* Add iterators, start batch processing

* Move run containers & run individual files to gudpy class

* Update Composition Iterations

* Add iterate to GUI and connect signals & slots

* Move over main window functions to control

* Delete uneeded atributes from worker classes

* Update batch processing, finalise

* Simplify iteration dialog, return kwargs for iterator initialisation

* Update iterators in control.py

* Update iterators

* Move export and missingfilesdialog to io.py

* Get rid of gudpyGUI class, add names

* Autosave and initialise view with gudrunfile object

* Update imports

* Fix errors

* Fix output charts- use gudrunOutput obj

* Minor fixes, file reorganising

* Fix output organising and output reporting

* Use gudrunOutput for plotting

* Sort flow and updating widgets

* Remove organise output func:

* Fix output updating to only if results are there

* Update mainwidget to ui name change

* Minor update, restructuring, fixing outputChanged() signal

* Fix plotting & chart

* Creat test project dir

* Update tests

* Save gudrun outputs, return correct exitcodes, save exitcodes in process

* Update tests

* Fix missing data files import

* Remove unused imports

* Remove unused imports

* Load missing files dialog

* Load missing files dialog

* remove uneeded imports

* remove uneeded imports

* remove uneeded imports

* Lint

* Fix gudpy spelling, tests

* Fix gudrunfile initialisation assertion

* Fix errors

* Fix test errors, add output handling to iterators

* Remove whitespace from test sample names

* Debug

* Fix finding binaries

* Fix sample name whitespace

* Fix test errors

* Remove old purge function

* Give gudrun access to purge

* Fix runPurge -> pass in purge file correctly

* Fix bugs in tests

* Fix iterators, gui, rename class

* reinitialize yaml?

* Add exclude to iterator output organise

* Remove self.gudrunfile from composition

* Add gudrunfile to iteration dialog

* Add gudrunfile to iteration dialog

* Fix: GUI iterators

* Fix: in worker classes change progress signal/func to progressChanged to avoid naming conflict with progress attribute

* Fix: pass gudrunFile to iterators.organiseOutput()

* Fix: make IterationBaseWorker inherrit from QThread so run() function is properly called on thread start. Remove invalid gudrunFile.gudrunOutput variable from iterator.performIteration()

* Fix: iterators. Ensure init is properly called, results to include iterator name, stop execution if dialog is cancelled

* Delete accidental file

* Lint: remove whitespace

* Fix: iterators for test. Wavelength iter not appending outputs, wrong composition class used

* Fix: Properly report iterator results

* Fix: progress bar. Move updateProgressBar to view, rewrite variable instead of adding to it

* Debug messages for tests

* Fix: Remove correct filepath in teardown(), grab correct gudrunOutput in test inelasticity subtraction iterator

* Debugging- print the .gudw file

* Fix: Remove correct filepath in teardown(), grab correct gudrunOutput in test inelasticity subtraction iterator

Debugging- print the .gudw file

Debugging- print the .gudw file

* Update gitignore

* Debugging- print the .gudw file

* Revert good_water to previous state

* Refactor: Use context in gudfile tests & create one function for loading gudFiles

* Fix: composition iterator initialisation, iterator to inherrit from base class

* Lint: remove unused import

* Fix: composition iterator

* Fix: composition iterator tests & iterator to have sample args passed in

* Fix: output tree construction, check whether or not iterator is used

* Fix: composition iterator. Change process to be managed by gudpy.CompositionIterator

* Fix: gudrunoutput to construct GudFile object and return it instead of just the path, to prevent effects of overriding

* Fix: save loadfile location in GudrunFile

* Docs: add docstrings to gudpy.GudPy

* Fix: GUI processes, reinitialise gudpy object on new loads, checkPurge function to not wipe purgeLocation, check workerThread object for process type

* Feat: allow gudfile path to be specified in write_out()

* Fix: capitalise iterator names, modify inelastic iterator to set proper names

* Feat: save original gudrun file

* Fix: pass around purge object instead of purgeLocationPath

* Fix: check save location before running, fix iterator workflow

* Fix: overwrite in output handler to wipe out existing Gudrun folder

* Fix: management of purge object, startProcess() function to check and run purge, GUI iteration workflow

* Fix: check that prev exists in output_tree before using

* Feat: return if results are empty- don't show an empty results dialog

* Feat: display 'Default run' indicator

* Feat: tests to implement new gudrunOutput gudfiles, use context managers to avoid writing test files to home directory

* Refactor: remove underscores from functions

* Lint: reduce line length

* Fix: pass purge into iterators, remove underscores from functions

* Fix: only check if user wants to save if gudrunfile is initialised

* Fix: configuration dialog initialisation

* Fix: remove setPurgeLocation() function call

* Update gudpy/gui/widgets/core/control.py

Co-authored-by: Tristan Youngs <[email protected]>

* Comments

* Ask to save only if file is modified

* Stronger purge warning message

* Change 'appendDfs' to 'appendDataFiles'

* Feat: Create standard stripping function

* Fix: stripping function

---------

Co-authored-by: Spitz <[email protected]>
Co-authored-by: Tristan Youngs <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent ef566fb commit ade4cd4
Show file tree
Hide file tree
Showing 58 changed files with 4,483 additions and 5,506 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ resources_rc.py
*.vanrat
/.vs
/env/Scripts
.env
2 changes: 1 addition & 1 deletion gudpy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gui.gudpy import main
from gui.gui import main

if __name__ == '__main__':
import sys
Expand Down
6 changes: 3 additions & 3 deletions gudpy/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Container:
-------
"""

def __init__(self, config_=None):
def __init__(self, config=None):
"""
Constructs all the necessary attributes for the Container object.
Expand Down Expand Up @@ -110,8 +110,8 @@ def __init__(self, config_=None):
"yamlignore"
}

if config_:
self.parseFromConfig(config_)
if config:
self.parseFromConfig(config)

def __str__(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion gudpy/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class Format(Enum):
2: ["Thickness", "THICKNESS"],
3: ["Inner Radius", "INNER_RADIUS"],
4: ["Outer Radius", "OUTER_RADIUS"],
5: ["Density", "DENSITY"]
5: ["Density", "DENSITY"],
6: ["Inelasticity Subtraction", "INELASTICITY"]
}

IterationModes = enumFromDict("IterationModes", ITERATION_MODES)
8 changes: 8 additions & 0 deletions gudpy/core/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ class ChemicalFormulaParserException(Exception):

class YAMLException(Exception):
pass


class GudrunException(Exception):
pass


class PurgeException(Exception):
pass
6 changes: 4 additions & 2 deletions gudpy/core/file_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from zipfile import ZipFile, ZIP_DEFLATED
from pathlib import Path

from core import utils
from core.enums import CrossSectionSource


Expand Down Expand Up @@ -172,7 +173,7 @@ def exportMintData(
if not exportTo:
exportTo = os.path.join(
self.gudrunFile.projectDir,
Path(self.gudrunFile.path).stem + ".zip",
Path(self.gudrunFile.path()).stem + ".zip",
)
with ZipFile(exportTo, "w", ZIP_DEFLATED) as zipFile:
for sample in samples:
Expand All @@ -183,7 +184,8 @@ def exportMintData(
self.gudrunFile.instrument.dataFileType, "mint01"
),
)
safeSampleName = sample.name.replace(" ", "_").translate(
safeSampleName = utils.replace_unwanted_chars(
sample.name).translate(
{ord(x): "" for x in r"/\!*~,&|[]"}
)
if os.path.exists(path):
Expand Down
14 changes: 4 additions & 10 deletions gudpy/core/gud_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ def __init__(self, path):

self.path = path

# Construct the outpath
fname = os.path.basename(self.path)
ref_fname = "gudpy_{}".format(fname)
dir = os.path.dirname(os.path.abspath(self.path))
self.OUTPATH = f"{dir}{os.path.sep}{ref_fname}"
# Construct the OUTPATH
self.fname = os.path.basename(self.path)
self.name = ""
self.title = ""
self.author = ""
Expand Down Expand Up @@ -354,7 +351,7 @@ def __str__(self):

)

def write_out(self, overwrite=False):
def write_out(self, path):
"""
Writes out the string representation of the GudFile.
If 'overwrite' is True, then the initial file is overwritten.
Expand All @@ -369,9 +366,6 @@ def write_out(self, overwrite=False):
-------
None
"""
if not overwrite:
f = open(self.OUTPATH, "w", encoding="utf-8")
else:
f = open(self.path, "w", encoding="utf-8")
f = open(path, "w", encoding="utf-8")
f.write(str(self))
f.close()
Loading

0 comments on commit ade4cd4

Please sign in to comment.