rice-solar-physics / pydrad

Python tools for setting up HYDRAD runs and parsing output
https://pydrad.readthedocs.io
MIT License
4 stars 3 forks source link

Calculate time array without reading all AMR files #134

Closed jwreep closed 3 years ago

jwreep commented 3 years ago

Fixes #132

This is an attempt to calculate the time array without reading all AMR files (#132), so that initializing a strand is much faster. It defaults to the original method of reading all the files.

I tested it on simulations with three different cadences and end times and it seems to work. It grabs the time of the first profile, and then uses the cadence to create the full time array. The strand initializes instantly.

It assumes that there are no missing files, and that the cadence does not change in the middle of a simulation. These seem like fringe cases, though.

jwreep commented 3 years ago

Example:

>>> from pydrad.parse import Strand
>>> s = Strand('/path/to/my/sim')
>>> s.time[0:30]
<Quantity [0.  , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09,
           0.1 , 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19,
           0.2 , 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29] s>
wtbarnes commented 3 years ago

I'm still not wild about this, but I understand it is more practical. However, I would prefer that the default behavior be to read from the AMR files as this will always give the exact timestep (though I do understand that level of precision is likely not needed).

Maybe get_master_time could have aread_from_cfg keyword argument that would default to False so if one wanted to quickly get the time array, it would just be a matter of creating the Strand and passing read_from_cfg=True. If it is False, it just defaults back to reading from the AMR files.

jwreep commented 3 years ago

Fair enough. I added the keyword, and hope I did it correctly. It seems to be working:

>>> from pydrad.parse import Strand
>>> s = Strand('/path/to/sim')
>>> s2 = Strand('/path/to/sim', read_from_cfg=True)
>>> s.time[0:25]
<Quantity [0.      , 0.100001, 0.200001, 0.300001, 0.4     , 0.500004,
           0.600003, 0.700017, 0.800012, 0.900001, 1.      , 1.1     ,
           1.2     , 1.3     , 1.4     , 1.5     , 1.6     , 1.7     ,
           1.8     , 1.9     , 2.      , 2.1     , 2.2     , 2.3     ,
           2.4     ] s>
>>> s2.time[0:25]
<Quantity [0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2,
           1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2, 2.3, 2.4] s>