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

Fully parse .trm files #169

Merged
merged 14 commits into from
Jun 17, 2024
Merged

Fully parse .trm files #169

merged 14 commits into from
Jun 17, 2024

Conversation

jwreep
Copy link
Contributor

@jwreep jwreep commented Mar 9, 2024

Addresses #168

I've added a full parsing of the .trm files. Hopefully the naming scheme is reasonable, but happy to edit that. I've also changed the variable names for the conduction variables in the .phy files, which are more accurately heat fluxes.

(base) reep@Jeffreys-iMac pydrad % python
Python 3.11.7 (main, Dec 15 2023, 12:09:56) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pydrad.parse import Strand
>>> import os
>>> os.chdir('/path/to/HYDRAD/')
>>> s = Strand('.')
>>> p = s[50]
>>> dir(p)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_amr_filename', '_grid_centers', '_grid_widths', '_hstate_data', '_hstate_filename', '_index', '_ine_filename', '_master_time', '_phy_data', '_phy_filename', '_read_amr', '_read_hstate', '_read_ine', '_read_phy', '_read_trm', '_trm_data', '_trm_filename', 'column_emission_measure', 'coordinate', 'electron_collisions', 'electron_conduction', 'electron_dTEKEbydt', 'electron_density', 'electron_electric_field', 'electron_enthalpy', 'electron_heat_flux', 'electron_heating', 'electron_pressure', 'electron_radiative_loss', 'electron_temperature', 'grid_centers', 'grid_edges', 'grid_edges_left', 'grid_edges_right', 'grid_widths', 'hydrad_root', 'hydrogen_collisions', 'hydrogen_conduction', 'hydrogen_dTEKEbydt', 'hydrogen_electric_field', 'hydrogen_enthalpy', 'hydrogen_gravity', 'hydrogen_heating', 'hydrogen_numerical_viscosity', 'hydrogen_viscous_stress', 'ion_density', 'ion_heat_flux', 'ion_pressure', 'ion_temperature', 'level_population_hydrogen_1', 'level_population_hydrogen_2', 'level_population_hydrogen_3', 'level_population_hydrogen_4', 'level_population_hydrogen_5', 'level_population_hydrogen_6', 'mass_advection', 'mass_drhobydt', 'momentum_advection', 'momentum_drho_vbydt', 'momentum_gravity', 'momentum_numerical_viscosity', 'momentum_pressure_gradient', 'momentum_viscous_stress', 'peek', 'peek_emission_measure', 'sound_speed', 'spatial_average', 'time', 'velocity']
>>> p.mass_advection.unit
Unit("g / (s cm3)")
>>> p.mass_advection.shape
(448,)

Copy link

codecov bot commented Mar 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.27%. Comparing base (3ed98ff) to head (bb05eb4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #169      +/-   ##
==========================================
+ Coverage   69.00%   70.27%   +1.26%     
==========================================
  Files          11       11              
  Lines         713      730      +17     
==========================================
+ Hits          492      513      +21     
+ Misses        221      217       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jwreep
Copy link
Contributor Author

jwreep commented May 19, 2024

@wtbarnes, please review.

Copy link
Member

@wtbarnes wtbarnes left a comment

Choose a reason for hiding this comment

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

Sorry I let this completely fall off my radar. I'm fine with this as is though I'm a little concerned about how brittle this code is. By that I mean it relies on the correspondence between indices and particular property names and as currently implemented, that correspondence is hardcoded twice: once when reading from the files and then again when assigning parts of the data array to each property. I don't have any bright ideas on how to deal with this though.

pydrad/parse/parse.py Outdated Show resolved Hide resolved
@jwreep
Copy link
Contributor Author

jwreep commented May 20, 2024

I'll have a think about the "brittleness" aspect of it, so don't merge it yet. It's true that hard coding the indices is not great, particularly if the trm files were ever updated in HYDRAD. (I suppose it's not likely to happen, but I have in the past wondered if it would be helpful to split background heating apart into its own term.)

@jwreep
Copy link
Contributor Author

jwreep commented May 20, 2024

pandas.read_csv might be able to be used here, similarly to how the .phy files have np.loadtxt to parse them. You can skip rows with the pandas function, so it could be used to create four separate dataframes. Cleaner and likely more robust code, but I suspect it would be slower because it would have to be read the file four times essentially. There might be a clever way to read it once and split into four dataframes, though . . .

@jwreep
Copy link
Contributor Author

jwreep commented May 21, 2024

Right, all indices have been removed. This isn't perfectly robust to changes in HYDRAD, but all that would need to be done is to add any new items to the lists of terms if there's a change in any of the equations.

This probably isn't the most efficient since it reads the files multiple times, though.

@jwreep
Copy link
Contributor Author

jwreep commented May 21, 2024

This might need a new unit test. I just pushed a fix that would not have given the correct result. Perhaps checking that one of the columns is not zero everywhere?

@jwreep
Copy link
Contributor Author

jwreep commented Jun 17, 2024

@wtbarnes This one is ready for review. The changes should be more robust.

@wtbarnes
Copy link
Member

Great! This looks good to me. The lack of repetition between the correspondence of the indices and variable names should make this more robust to changes in the layout. Thanks for all of your effort on this!

@wtbarnes wtbarnes merged commit dd41f6a into rice-solar-physics:main Jun 17, 2024
14 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.

None yet

2 participants