-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added correct cumulative mass balance and mass balance rates, along with their uncertainties.
- Loading branch information
1 parent
3714c01
commit a230fef
Showing
6 changed files
with
160 additions
and
161 deletions.
There are no files selected for viewing
This file contains 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 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 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,75 @@ | ||
# Copyright (C) 2023 Andy Aschwanden | ||
# | ||
# This file is part of pism-ragis. | ||
# | ||
# PISM-RAGIS is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# PISM-RAGIS is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PISM; if not, write to the Free Software | ||
|
||
# pylint: disable=too-many-positional-arguments | ||
|
||
""" | ||
Module for date processing | ||
""" | ||
|
||
import datetime | ||
from calendar import isleap | ||
|
||
|
||
def decimal_year_to_datetime(decimal_year: float) -> datetime.datetime: | ||
""" | ||
Convert a decimal year to a datetime object. | ||
Parameters | ||
---------- | ||
decimal_year : float | ||
The decimal year to be converted. | ||
Returns | ||
------- | ||
datetime.datetime | ||
The corresponding datetime object. | ||
Notes | ||
----- | ||
The function calculates the date by determining the start of the year and adding | ||
the fractional part of the year as days. If the resulting date has an hour value | ||
of 12 or more, it rounds up to the next day and sets the time to midnight. | ||
""" | ||
year = int(decimal_year) | ||
remainder = decimal_year - year | ||
start_of_year = datetime.datetime(year, 1, 1) | ||
days_in_year = (datetime.datetime(year + 1, 1, 1) - start_of_year).days | ||
date = start_of_year + datetime.timedelta(days=remainder * days_in_year) | ||
if date.hour >= 12: | ||
date = date + datetime.timedelta(days=1) | ||
return date.replace(hour=0, minute=0, second=0, microsecond=0) | ||
|
||
|
||
def days_in_year(year: int) -> int: | ||
""" | ||
Calculate the number of days in a given year. | ||
Parameters | ||
---------- | ||
year : int | ||
The year for which to calculate the number of days. | ||
Returns | ||
------- | ||
int | ||
The number of days in the specified year. Returns 366 if the year is a leap year, otherwise returns 365. | ||
""" | ||
if isleap(year): | ||
return 366 | ||
else: | ||
return 365 |
This file contains 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 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,57 @@ | ||
# Copyright (C) 2023-24 Andy Aschwanden | ||
# | ||
# This file is part of pism-ragis. | ||
# | ||
# PISM-RAGIS is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# PISM-RAGIS is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PISM; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
""" | ||
Tests for date tools module. | ||
""" | ||
|
||
|
||
from pism_ragis.datetools import days_in_year | ||
|
||
|
||
def test_days_in_year(): | ||
""" | ||
Test the days_in_year function. | ||
This function tests the days_in_year function for various types of years: | ||
- Common year | ||
- Leap year | ||
- Century year that is not a leap year | ||
- Century year that is a leap year | ||
The days_in_year function is expected to return: | ||
- 365 days for a common year | ||
- 366 days for a leap year | ||
- 365 days for a century year that is not a leap year | ||
- 366 days for a century year that is a leap year | ||
Examples | ||
-------- | ||
>>> test_days_in_year() | ||
""" | ||
# Test for a common year | ||
assert days_in_year(2021) == 365 | ||
|
||
# Test for a leap year | ||
assert days_in_year(2020) == 366 | ||
|
||
# Test for a century year that is not a leap year | ||
assert days_in_year(1900) == 365 | ||
|
||
# Test for a century year that is a leap year | ||
assert days_in_year(2000) == 366 |
Oops, something went wrong.