-
Notifications
You must be signed in to change notification settings - Fork 0
#7 Hdf5 writing added. #14
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # EHat.py | ||
| # EHat_calc.py | ||
| # 30/01/2019 | ||
| # Written by Soma Olasz | ||
| # | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| %%% extractFraction.m | ||
| %%% 16/12/2019 | ||
| %%% Written by Soma Olasz | ||
| %%% | ||
| %%% This script is created to calculate the runaway density | ||
| %%% of a NORSE calculation to Python languge. | ||
|
|
||
|
|
||
| function double = extractDistribution(NORSEobject) | ||
|
|
||
| % calculate the runaway generation rate | ||
| double = NORSEobject.runawayFraction(end); | ||
|
|
||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| %%% extractGrowthRate.m | ||
| %%% 16/12/2019 | ||
| %%% Written by Soma Olasz | ||
| %%% | ||
| %%% This script is created to calculate the runaway generation rate | ||
| %%% of a NORSE calculation to Python languge. | ||
|
|
||
|
|
||
| function double = extractDistribution(NORSEobject) | ||
|
|
||
| % calculate the runaway generation rate | ||
| double = (NORSEobject.runawayFraction(end)-NORSEobject.runawayFraction(1))/(NORSEobject.times(end)-NORSEobject.times(1)); | ||
|
|
||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Created on Thu Dec 12 12:00:00 2019 | ||
|
|
||
| @author: Soma Olasz | ||
| """ | ||
|
|
||
| # This function is created to write data to hdf5 file. | ||
|
|
||
| import h5py | ||
| import os | ||
| import pwd | ||
|
|
||
|
|
||
| def write_params(shotnumber, runnumber, input_list): | ||
|
|
||
| # Get the location of the hdf5 output | ||
| try: | ||
| hdf5_base = os.environ['HDF5_BASE'] | ||
|
|
||
| except KeyError: | ||
|
|
||
| try: | ||
| hdf5_base = os.environ['HOME'] | ||
|
|
||
| except KeyError: | ||
|
|
||
| hdf5_base = pwd.getpwuid(os.getuid()).pw_dir | ||
|
|
||
| # Get the shot and run numbers into formatted strings | ||
| str_shotnumber = str(shotnumber) | ||
| str_runnumber = str(runnumber).zfill(4) | ||
|
|
||
| # Define hdf5 output file | ||
| location = hdf5_base + '/euitm_' + str_shotnumber + str_runnumber + '_NORSE.h5' | ||
|
|
||
| # Init hdf5 file | ||
| hf = h5py.File(location, 'a') | ||
|
|
||
| # Go through all the input arguments. | ||
| for element in input_list: | ||
|
|
||
| try: | ||
| hf.create_dataset(element['Name'], data=element['Data'], maxshape = (None, element['Data'].shape[1]), chunks = element['Data'].shape) | ||
|
|
||
| except RuntimeError: | ||
|
|
||
| if element['Data'].shape[1] == hf[element['Name']].shape[1]: | ||
|
|
||
| hf[element['Name']].resize(hf[element['Name']].shape[0] + element['Data'].shape[0], axis = 0) | ||
| hf[element['Name']][-element['Data'].shape[0]:] = element['Data'] | ||
|
|
||
| else: | ||
| print("Length of input data is different from the length of data in the hdf5 file. Please write to a different hdf5 file.") | ||
| break | ||
|
|
||
|
|
||
| hf.close() | ||
|
|
||
| return | ||
|
|
||
| def write_dist(shotnumber, runnumber, input_list): | ||
|
|
||
| # Get the location of the hdf5 output | ||
| try: | ||
| hdf5_base = os.environ['HDF5_BASE'] | ||
|
|
||
| except KeyError: | ||
|
|
||
| try: | ||
| hdf5_base = os.environ['HOME'] | ||
|
|
||
| except KeyError: | ||
|
|
||
| hdf5_base = pwd.getpwuid(os.getuid()).pw_dir | ||
|
|
||
| # Get the shot and run numbers into formatted strings | ||
| str_shotnumber = str(shotnumber) | ||
| str_runnumber = str(runnumber).zfill(4) | ||
|
|
||
| # Define hdf5 output file | ||
| location = hdf5_base + '/euitm_' + str_shotnumber + str_runnumber + '_NORSE.h5' | ||
|
|
||
| # Init hdf5 file | ||
| hf = h5py.File(location, 'a') | ||
|
|
||
| # Go through all the input arguments. | ||
| for element in input_list: | ||
|
|
||
| try: | ||
| hf.create_dataset(element['Name'], data=element['Data'], maxshape = (None, element['Data'].shape[1], element['Data'].shape[2]), chunks = element['Data'].shape) | ||
|
|
||
| except RuntimeError: | ||
|
|
||
| if element['Data'].shape[1] == hf[element['Name']].shape[1] and element['Data'].shape[2] == hf[element['Name']].shape[2]: | ||
|
|
||
| hf[element['Name']].resize(hf[element['Name']].shape[0] + element['Data'].shape[0], axis = 0) | ||
| hf[element['Name']][-element['Data'].shape[0]:] = element['Data'] | ||
|
|
||
| else: | ||
| print("Length of input data is different from the length of data in the hdf5 file. Please write to a different hdf5 file.") | ||
| break | ||
|
|
||
|
|
||
| hf.close() | ||
|
|
||
| return | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should explore the use of standard headers, like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for two scripts, the rest will be dealt with separately, when dealing with the relevant issue.