@@ -76,7 +76,7 @@ def load_igrf(path):
7676 return years , coeffs ["g" ], coeffs ["h" ], coeffs ["g_sv" ], coeffs ["h_sv" ]
7777
7878
79- def interpolate_coefficients (date , years , g , h , g_sv , h_sv ):
79+ def interpolate_coefficients (date , max_degree , years , g , h , g_sv , h_sv ):
8080 """
8181 Interpolate the Gauss coefficients to the given date.
8282
@@ -87,6 +87,8 @@ def interpolate_coefficients(date, years, g, h, g_sv, h_sv):
8787 ----------
8888 date : :class:`datetime.datetime`
8989 The date and time at which to interpolate the coefficients.
90+ max_degree : int
91+ The maximum degree that will be interpolated.
9092 years : 1d-array
9193 The years for the knot points (epochs) of the time interpolation.
9294 g, h : 3d-arrays
@@ -106,7 +108,8 @@ def interpolate_coefficients(date, years, g, h, g_sv, h_sv):
106108 g_date, h_date : 2d-arrays
107109 The interpolated Gauss coefficients. The first dimension is the degree
108110 n and the second is the order m. At m > n, the coefficients are
109- assigned zero. Units are nT.
111+ assigned zero. The shape of the arrays will be ``(max_degree + 1,
112+ max_degree + 1)``. Units are nT.
110113 """
111114 if date .year < years [0 ] or date .year >= years [- 1 ] + 5 :
112115 message = (
@@ -124,9 +127,9 @@ def interpolate_coefficients(date, years, g, h, g_sv, h_sv):
124127 - datetime .datetime (year = years [index ], month = 1 , day = 1 )
125128 ).total_seconds ()
126129 year_in_seconds = 365.25 * 24 * 60 * 60
127- g_date = np .zeros (g . shape [ 1 :] )
128- h_date = np .zeros (h . shape [ 1 :] )
129- for n in range (1 , g . shape [ 1 ] ):
130+ g_date = np .zeros (( max_degree + 1 , max_degree + 1 ) )
131+ h_date = np .zeros (( max_degree + 1 , max_degree + 1 ) )
132+ for n in range (1 , max_degree + 1 ):
130133 for m in range (n + 1 ):
131134 if index >= years .size - 1 :
132135 variation_g = g_sv [n , m ] / year_in_seconds
@@ -294,7 +297,7 @@ def __init__(
294297 def coefficients (self ):
295298 if self ._coefficients is None :
296299 self ._coefficients = interpolate_coefficients (
297- self .date , * load_igrf (self ._fetch_coefficient_file ())
300+ self .date , self . max_degree , * load_igrf (self ._fetch_coefficient_file ())
298301 )
299302 return self ._coefficients
300303
0 commit comments