Skip to content

Commit

Permalink
Set accumulated values to zero for first time step (#47)
Browse files Browse the repository at this point in the history
* Set accumulated values to zero for first time step

* Bump python version since 3.8 is EOL

* Bump python version since 3.8 is EOL

* Black
  • Loading branch information
trygveasp authored Jan 9, 2025
1 parent 5a26332 commit f04872d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: setup-python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'

#----------------------------------------------
# --- configure poetry & install project ----
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
os: [ "ubuntu-latest" ]
env: [ "pytest" ]
python-version: [ "3.8" ]
python-version: [ "3.9" ]

name: "${{ matrix.os }}, python=${{ matrix.python-version }}"
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
poetry run pytest
- name: Coveralls
if: ${{ matrix.python-version == 3.8 }}
if: ${{ matrix.python-version == 3.9 }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand All @@ -79,13 +79,13 @@ jobs:
poetry run coveralls
- name: Create documentation
if: ${{ matrix.python-version == 3.8 }}
if: ${{ matrix.python-version == 3.9 }}
run: |
cd docs
poetry run python auto_sphinx.py
make html
- name: Commit documentation changes
if: ${{ matrix.python-version == 3.8 }}
if: ${{ matrix.python-version == 3.9 }}
run: |
git clone https://github.com/metno/pysurfex.git --branch gh-pages --single-branch gh-pages
cp -r docs/build/html/* gh-pages/
Expand All @@ -97,7 +97,7 @@ jobs:
# The above command will fail if no changes were present, so we ignore
# the return code.
- name: Push changes
if: ${{ matrix.python-version == 3.8 && github.event_name != 'pull_request' }}
if: ${{ matrix.python-version == 3.9 && github.event_name != 'pull_request' }}
uses: ad-m/github-push-action@master
with:
branch: gh-pages
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
requires = ["poetry-core > 1.2.0"]

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
dateutils = "^0.6.12"
f90nml = "^1.4.3"
humanize = ">=3.14.0"
Expand Down
17 changes: 15 additions & 2 deletions pysurfex/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def read_variable(self, geo, validtime, cache=None):
"""
# Set variable info
previous_field = None
first_time = False
if self.accumulated:
# Re-read field
previoustime = validtime - as_timedelta(seconds=self.interval)
Expand All @@ -408,14 +409,26 @@ def read_variable(self, geo, validtime, cache=None):
cache=cache,
)
else:
first_time = True
previous_field = np.zeros([geo.npoints])
elif self.instant > 0:
previous_field = np.zeros([geo.npoints])

field = self.read_var_points(self.file_var, geo, validtime=validtime, cache=cache)
deaccumulate = False
if self.accumulated or self.instant > 0:
deaccumulate = True

# Always set accumulated values to zero the first time
if first_time:
deaccumulate = False
field = np.zeros([geo.npoints])
else:
field = self.read_var_points(
self.file_var, geo, validtime=validtime, cache=cache
)

# Deaccumulate if either two files are read or if instant is > 0.
if self.accumulated or self.instant > 0:
if deaccumulate:
field = self.deaccumulate(field, previous_field, self.instant)
if any(field[field < 0.0]):
raise RuntimeError(
Expand Down

0 comments on commit f04872d

Please sign in to comment.