Skip to content

Commit

Permalink
Grid cell precision fixes (#177)
Browse files Browse the repository at this point in the history
* set default value for max cells sufficiently high

* limit number of sig figs in loop length

* round->ceil in min_cells

* bump to 3.10 support, catch utc deprecation warning

* fix tests for new loop length precision
  • Loading branch information
wtbarnes authored Nov 5, 2024
1 parent 2a31ec1 commit 557e41a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
with:
toxdeps: tox-pypi-filter
envs: |
- macos: py311
- windows: py311
- linux: py39
- macos: py312
- windows: py312
- linux: py310
- linux: py311
- linux: py312
- linux: py313
coverage: 'codecov'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -38,7 +39,7 @@ jobs:
toxdeps: tox-pypi-filter
envs: |
- linux: build_docs
python-version: '3.11'
python-version: '3.12'
publish:
# Build wheels when pushing to any branch except main
# publish.yml will only publish if tagged ^v.*
Expand All @@ -58,6 +59,6 @@ jobs:
test_extras: 'dev'
test_command: 'pytest -p no:warnings --doctest-rst --pyargs pydrad'
submodules: false
python-version: '3.11'
python-version: '3.12'
secrets:
pypi_token: ${{ secrets.PYPI_TOKEN }}
4 changes: 2 additions & 2 deletions pydrad/configure/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def date(self):
if hasattr(self, '_freeze_date') and self._freeze_date:
return self._date
else:
return datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d_%H.%M.%S UTC')
return datetime.datetime.utcnow().strftime('%Y-%m-%d_%H.%M.%S UTC')

@property
def templates(self,):
Expand Down Expand Up @@ -405,7 +405,7 @@ def minimum_cells(self):
n_min = L / self.config['grid']['maximum_cell_width']
if n_min.decompose().unit != u.dimensionless_unscaled:
raise u.UnitConversionError(f'''Maximum cell width must be able to be converted to {L.unit}''')
return int(np.round(n_min.decompose()))
return int(np.ceil(n_min.decompose()))

@property
def maximum_cells(self):
Expand Down
1 change: 1 addition & 0 deletions pydrad/configure/data/defaults.asdf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ grid:
enforce_conservation: true
initial_refinement_level: 10
linear_restriction: true
maximum_cells: 30000
maximum_cell_width: !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 'Mm', value: 0.5}
maximum_fractional_difference: 0.2
maximum_refinement_level: 12
Expand Down
2 changes: 1 addition & 1 deletion pydrad/configure/templates/initial_conditions.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Initial_Conditions/profiles/initial.amr

{{ general.loop_length | is_required | units_filter('cm') | sci_notation }}
{{ general.loop_length | is_required | units_filter('cm') | sci_notation(sig_figs=4) }}
{{ general.loop_inclination | is_required | units_filter('deg') }}
{{ general.footpoint_height | is_required | units_filter('cm') | sci_notation }}

Expand Down
4 changes: 2 additions & 2 deletions pydrad/configure/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_initial_conditions_config(configuration):
# Isothermal case
config = f"""Initial_Conditions/profiles/initial.amr
9.00000000e+09
9.0000e+09
0.0
5.00000000e+08
Expand All @@ -341,7 +341,7 @@ def test_initial_conditions_config(configuration):
configuration.config['initial_conditions']['heating_range_fine_tuning'] = 10000
config = f"""Initial_Conditions/profiles/initial.amr
9.00000000e+09
9.0000e+09
0.0
5.00000000e+08
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Topic :: Scientific/Engineering :: Astronomy

[options]
zip_safe = False
packages = find:
python_requires = >=3.9
python_requires = >=3.10
setup_requires = setuptools_scm
install_requires =
scipy
Expand Down Expand Up @@ -65,6 +65,7 @@ filterwarnings =
# See https://github.com/numpy/numpy/issues/15748#issuecomment-598584838
ignore:numpy.ndarray size changed:RuntimeWarning
ignore:The unit 'erg' has been deprecated in the VOUnit standard.:astropy.units.core.UnitsWarning
ignore:datetime.datetime.utcnow\(\) is deprecated and scheduled for removal in a future version.:DeprecationWarning

[coverage:run]
omit =
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{39,310,311}
py{310,311,312,313}
build_docs
codestyle
isolated_build = true
Expand Down

0 comments on commit 557e41a

Please sign in to comment.