Code Duplication    Length = 45-48 lines in 2 locations

apexpy/apex.py 2 locations

@@ 269-316 (lines=48) @@
266
267
        return qlat, qlon
268
269
    def _qd2apex_nonvectorized(self, qlat, qlon, height):
270
        """Converts quasi-dipole to modified apex coordinates.
271
272
        Parameters
273
        ----------
274
        qlat : float
275
            Quasi-dipole latitude
276
        qlon : float
277
            Quasi-dipole longitude
278
        height : float
279
            Altitude in km
280
281
        Returns
282
        -------
283
        alat : float
284
            Modified apex latitude
285
        alon : float
286
            Modified apex longitude
287
288
        Raises
289
        ------
290
        ApexHeightError
291
            if apex height < reference height
292
293
        """
294
        # Evaluate the latitude
295
        qlat = helpers.checklat(qlat, name='qlat')
296
297
        # Get the longitude and apex height
298
        alon = qlon
299
        h_apex = self.get_apex(qlat, height)
300
301
        if h_apex < self.refh:
302
            if np.isclose(h_apex, self.refh, rtol=0, atol=1e-5):
303
                # Allow for values that are close
304
                h_apex = self.refh
305
            else:
306
                estr = ''.join(['apex height ({:.3g}) is < '.format(h_apex),
307
                                'reference height ({:.3g})'.format(self.refh),
308
                                ' for qlat {:.3g}'.format(qlat)])
309
                raise ApexHeightError(estr)
310
311
        # Convert the latitude
312
        sqlat = np.sign(qlat) if qlat != 0 else 1
313
        alat = sqlat * np.degrees(np.arccos(np.sqrt((self.RE + self.refh)
314
                                                    / (self.RE + h_apex))))
315
316
        return alat, alon
317
318
    def _map_EV_to_height(self, alat, alon, height, newheight, data, ev_flag):
319
        """Maps electric field related values to a desired height
@@ 223-267 (lines=45) @@
220
    # -------------------------
221
    # Define the hidden methods
222
223
    def _apex2qd_nonvectorized(self, alat, alon, height):
224
        """Convert from apex to quasi-dipole (not-vectorised)
225
226
        Parameters
227
        -----------
228
        alat : (float)
229
            Apex latitude in degrees
230
        alon : (float)
231
            Apex longitude in degrees
232
        height : (float)
233
            Height in km
234
235
        Returns
236
        ---------
237
        qlat : (float)
238
            Quasi-dipole latitude in degrees
239
        qlon : (float)
240
            Quasi-diplole longitude in degrees
241
242
        """
243
        # Evaluate the latitude
244
        alat = helpers.checklat(alat, name='alat')
245
246
        # Convert modified apex to quasi-dipole, longitude is the same
247
        qlon = alon
248
249
        # Get the apex height
250
        h_apex = self.get_apex(alat)
251
252
        if h_apex < height:
253
            if np.isclose(h_apex, height, rtol=0, atol=1e-5):
254
                # Allow for values that are close
255
                h_apex = height
256
            else:
257
                estr = ''.join(['height {:.3g} is > '.format(np.max(height)),
258
                                'apex height {:.3g} for alat {:.3g}'.format(
259
                                    h_apex, alat)])
260
                raise ApexHeightError(estr)
261
262
        # Convert the latitude
263
        salat = np.sign(alat) if alat != 0 else 1
264
        qlat = salat * np.degrees(np.arccos(np.sqrt((self.RE + height)
265
                                                    / (self.RE + h_apex))))
266
267
        return qlat, qlon
268
269
    def _qd2apex_nonvectorized(self, qlat, qlon, height):
270
        """Converts quasi-dipole to modified apex coordinates.