Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# This code is part of the Fatiando a Terra project (https://www.fatiando.org)
#
import datetime
import datetime as dt

import pygmt.sphinx_gallery
import pyvista
Expand All @@ -16,8 +16,7 @@
# -----------------------------------------------------------------------------
project = "Harmonica"
copyright_info = (
f"2018-{datetime.datetime.now(tz=datetime.timezone.utc).year},"
f" The {project} Developers"
f"2018-{dt.datetime.now(tz=dt.timezone.utc).year}, The {project} Developers"
)
if len(harmonica.__version__.split("+")) > 1 or harmonica.__version__ == "unknown":
version = "dev"
Expand Down
2 changes: 1 addition & 1 deletion env/requirements-style.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Requirements for checking code style
ruff==0.16.*
ruff==0.17.*
burocrata==0.2.*
zizmor==1.30.*
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ dependencies:
- gdal
- trame # needed by pyvista
# Code style checks and autoformat
- ruff==0.16.*
- ruff==0.17.*
- burocrata==0.2.*
- zizmor==1.30.*
12 changes: 6 additions & 6 deletions src/harmonica/_spherical_harmonics/igrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Calculation of the IGRF magnetic field.
"""

import datetime
import datetime as dt
import pathlib

import bordado as bd
Expand Down Expand Up @@ -120,17 +120,17 @@ def interpolate_coefficients(date, max_degree, years, g, h, g_sv, h_sv):
raise ValueError(message)
# Find out which epoch is the last compatible one.
index = int((date.year - years[0]) // 5)
start_of_epoch = datetime.datetime(
start_of_epoch = dt.datetime(
year=years[index],
month=1,
day=1,
# Specify start of the year in UTC time if date has timezone information
tzinfo=datetime.timezone.utc if date.tzinfo is not None else None,
tzinfo=dt.timezone.utc if date.tzinfo is not None else None,
)
seconds_since_epoch = (date - start_of_epoch).total_seconds()
epoch = (
datetime.datetime(year=years[index] + 5, month=1, day=1) # ruff: ignore[DTZ001]
- datetime.datetime(year=years[index], month=1, day=1) # ruff: ignore[DTZ001]
dt.datetime(year=years[index] + 5, month=1, day=1)
- dt.datetime(year=years[index], month=1, day=1)
).total_seconds()
year_in_seconds = 365.25 * 24 * 60 * 60
g_date = np.zeros((max_degree + 1, max_degree + 1))
Expand Down Expand Up @@ -291,7 +291,7 @@ def __init__(
ellipsoid=boule.WGS84,
):
if isinstance(date, str):
self.date = datetime.datetime.fromisoformat(date)
self.date = dt.datetime.fromisoformat(date)
else:
self.date = date
self.max_degree = max_degree
Expand Down
28 changes: 14 additions & 14 deletions test/test_igrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
"""Test the IGRF results against the ones calculated by the BGS."""

import datetime
import datetime as dt
import pathlib

import bordado as bd
Expand Down Expand Up @@ -123,7 +123,7 @@
["2021-02-01", 35605.6, 1421.6, 1788.7],
["2026-08-02", 35675.0, 1368.9, 2067.7],
]
UTC = datetime.timezone.utc
UTC = dt.timezone.utc


def test_igrf14__fetch_coefficients():
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_interpolate_coefficients(tzinfo):
years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-02-10")._fetch_coefficient_file())
for i, year in enumerate(years):
g_date, h_date = interpolate_coefficients(
datetime.datetime(
dt.datetime(
year, month=1, day=1, hour=0, minute=1, second=0, tzinfo=tzinfo
),
g.shape[1] - 1,
Expand All @@ -188,7 +188,7 @@ def test_interpolate_coefficients_max_degree(tzinfo):
max_degree = 13
years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-02-10")._fetch_coefficient_file())
g_date, h_date = interpolate_coefficients(
datetime.datetime(
dt.datetime(
year=2023, month=1, day=20, hour=0, minute=1, second=0, tzinfo=tzinfo
),
max_degree,
Expand All @@ -205,10 +205,10 @@ def test_interpolate_coefficients_max_degree(tzinfo):
@pytest.mark.parametrize(
"date",
[
datetime.datetime(1800, month=1, day=1, tzinfo=UTC),
datetime.datetime(2030, month=1, day=1, tzinfo=UTC),
datetime.datetime(1800, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001]
datetime.datetime(2030, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001]
dt.datetime(1800, month=1, day=1, tzinfo=UTC),
dt.datetime(2030, month=1, day=1, tzinfo=UTC),
dt.datetime(1800, month=1, day=1, tzinfo=None),
dt.datetime(2030, month=1, day=1, tzinfo=None),
],
)
def test_interpolate_coefficients_invalid_date(date):
Expand Down Expand Up @@ -254,8 +254,8 @@ def test_igrf_points(data, coordinates):
"date",
[
"2020-04-15",
datetime.datetime(2029, month=1, day=1, tzinfo=UTC),
datetime.datetime(2029, month=1, day=1, tzinfo=None), # ruff: ignore[DTZ001]
dt.datetime(2029, month=1, day=1, tzinfo=UTC),
dt.datetime(2029, month=1, day=1, tzinfo=None),
],
)
def test_igrf_grid(date):
Expand Down Expand Up @@ -291,10 +291,10 @@ def test_interpolate_coefficients_on_dates_with_timezones():
Test if coefficients are the same on equivalent dates on different timezones.
"""
# Define the same date on two different timezones
utc = datetime.timezone.utc
pt = datetime.timezone(-datetime.timedelta(hours=7)) # UTC-7
date_utc = datetime.datetime(year=2020, month=4, day=15, hour=14, tzinfo=utc)
date_pt = datetime.datetime(year=2020, month=4, day=15, hour=14 - 7, tzinfo=pt)
utc = dt.timezone.utc
pt = dt.timezone(-dt.timedelta(hours=7)) # UTC-7
date_utc = dt.datetime(year=2020, month=4, day=15, hour=14, tzinfo=utc)
date_pt = dt.datetime(year=2020, month=4, day=15, hour=14 - 7, tzinfo=pt)

# Compute cofficients for both dates
years, g, h, g_sv, h_sv = load_igrf(IGRF14("2020-04-15")._fetch_coefficient_file())
Expand Down
Loading