Closed LiamPattinson closed 1 year ago
Hey, sorry for the long pause on this PR, and thanks for adding in some test data. I've made some further updates:
Gif_Maker
:
make_gif
pathlib.Path.rglob
to get files).time_reader
:
pandas.read_fwf
(fixed-width-file) to read input data file.pandas.DataFrame
with the new timesteps and indices. Does not write a file (though the user can do so easily using result.to_csv("myfile.csv")
).pyproject.toml
. This is recommended by PEP 517/518/621.pip install --upgrade pip
to get it to work, as some features were only recently added to the standard build tools.tests
folder, containing tests that can be run using pytest. The README explains how to run them. I'd highly advise reading up on pytest when you have a few minutes. The tests I've added already should give you some idea of how things work.Testing
! Pytest discovers tests based on the names of files/functions/classes, so some of the scripts in here would interfere. I opted to just add a new directory, and the old tests should be migrated here as each is upgraded to be pytest compatible.make_gif
and time_reader
. The reason I was able to work on these functions in the first place was because I had test data available, meaning I could ensure that any changes I made weren't breaking anything.pytest
on the tests
folder.I think that's about as far as I can take this PR without more testing data. I think that getting more tests in is the most important next step, as I'm currently not able to check whether any of the Paraview stuff works.
Let me know if you'd like me to revert any changes to the code (I realise I may have been a little overzealous in places). I'm also happy to explain any changes if you're not sure how they work.
I've made some changes to the project so that each of the scripts no longer depend on hard-coded file paths, and it's possible to
import
the files without running everything. Each script has been bundled into a function that takes input/output paths as arguments, and these can be set from the command line. I've also set up the project as an installable Python package, so you can do things like:Instructions for installing everything are in the updated README. If you still wish to run the individual files as scripts, you can still do so, as I've implemented a command line interface for each of them (you can run
python some_script.py --help
to get a nice explanation of how to run each one).Unfortunately, converting a script to a module containing a function means indenting an entire file, so according to this PR I've rewritten almost everything. In reality, not much has changed, and I've tried to avoid changing any of the core logic where possible.
I've submitted this as a work-in-progress, as I don't yet have access to sufficient testing data (Issue https://github.com/DomLonghorn/SciViPy/issues/37), so the closest I can get to ensuring that everything actually works is running
flake8
to make sure I haven't made any typos or syntax errors. I was sent a Jorek.vtk
file, but it looks like I'll need a CAD file too (not sure what that is in this context?), and I'll need BOUT files,.xyz
files,.txt
files fortime_reader
,.csv
files forcrystal_vis
, and a few images forgif_maker
. Looking at the comments throughout the code, it looks like it's usually run on large datasets and it can take up to an hour to finish. For testing purposes, I'd only need 1 or 2 files of each type, and they don't need to contain anything interesting -- just enough so I can verify that the code is working as expected.Changes:
setup.py
,setup.cfg
,pyproject.toml
,__init__.py
. These allow the package to be pip installable. There's quite a lot of confusing info out there on Python packaging, but I usually use this as a reference for setting it up using setuptools with asetup.cfg
file. This will likely be deprecated in a few months, as they're moving over to a method that puts everything inpyproject.toml
instead.Scripts
folder to the project nameSciViPy
. It's a common way to structure a Python project, and it makes packaging a bit easier.if __name__ == "__main__"
, so they can run as scripts or be imported as Python modules.argparse
to manage command line interface. No more hard-coded filepaths.pathlib.Path
overos
path functions.print
statementsPlanned further updates:
black
on submitted code and runflake8
checks.CapsNames
are classes, whilesnake_case_names
are functions or variables. However, I realise that it won't be possible to keep this consistent throughout the code, asparaview
doesn't appear to be written with any Python style in mind..csv
related -- it's just really good at managing columns of data.for
looping, and the loop over a directory can be performed outside the main function call.