Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Grids with properties #485

Merged
merged 11 commits into from
Jun 27, 2024
Merged

Conversation

JulienDoerner
Copy link
Member

Dear all,

this PR introduces the loading of grids with given properties in the header.
The first implementation only allows property reading in the TXT files.
An example of the properties in the header looks like this

# GridProperties: Type Grid1f   origin: -4.92744e+20 -4.92744e+20 -1.44641e+19  gridsize: 512 512 16    spacing: 1.92855e+18 1.92855e+18 1.92855e+18    reflective: 0       clipVolume: 1   interpolation: TRILINEAR

all units are in SI base units (in this case m). The loading itself has the conversion variable as before.
Loading a grid can now be done as

grid = loadGrid3f("myGridFile.txt", 1 * gauss)

I also introduce the possibility to store the properties in the dumpGridToTxt function and additional tests for this grid reading/dumping.

To have an example, I adjusted the notebook with the grid-based glactic gas densities to use the grid property reading. The files on sciebo (additional resources) are already updated (additional line with the properties in the right format).

Copy link
Member

@lukasmerten lukasmerten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks overall good to me. Just a few minor comments

if (ipolType == NEAREST_NEIGHBOUR)
return "NEAREST_NEIGHBOUR";

return "NOT_UNDERSTOOD";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a more meaningful error message. Something like "ipolType not well defined: should be either TRILINEAR, TRICUBIC, or NEAREST_NEIGHBOUR".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not meant to be an error message. It is the conversion from the data-type to a string for saving.
To be consistent with the reading it has to be without spaces.

The alternative would be raising a runtime error at this point. In this case the saving would not run at all.

src/GridTools.cpp Outdated Show resolved Hide resolved
src/GridTools.cpp Outdated Show resolved Hide resolved
@lukasmerten lukasmerten merged commit fe44552 into CRPropa:master Jun 27, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants