Code Duplication    Length = 21-41 lines in 2 locations

src/apexpy/apex.py 2 locations

@@ 354-394 (lines=41) @@
351
        # if array is returned, dtype is object, so convert to float
352
        return np.float64(glat), np.float64(glon), np.float64(error)
353
354
    def _apex2qd_nonvectorized(self, alat, alon, height):
355
        """Convert from apex to quasi-dipole (not-vectorised)
356
357
        Parameters
358
        -----------
359
        alat : (float)
360
            Apex latitude in degrees
361
        alon : (float)
362
            Apex longitude in degrees
363
        height : (float)
364
            Height in km
365
366
        Returns
367
        ---------
368
        qlat : (float)
369
            Quasi-dipole latitude in degrees
370
        qlon : (float)
371
            Quasi-diplole longitude in degrees
372
        """
373
374
        alat = helpers.checklat(alat, name='alat')
375
376
        # convert modified apex to quasi-dipole:
377
        qlon = alon
378
379
        # apex height
380
        hA = self.get_apex(alat)
381
382
        if hA < height:
383
            if np.isclose(hA, height, rtol=0, atol=1e-5):
384
                # allow for values that are close
385
                hA = height
386
            else:
387
                estr = 'height {:.3g} is > apex height '.format(np.max(height))
388
                estr += '{:.3g} for alat {:.3g}'.format(hA, alat)
389
                raise ApexHeightError(estr)
390
391
        qlat = np.sign(alat) * np.degrees(np.arccos(np.sqrt((self.RE + height) /
392
                                                            (self.RE + hA))))
393
394
        return qlat, qlon
395
396
    def apex2qd(self, alat, alon, height):
397
        """Converts modified apex to quasi-dipole coordinates.
@@ 427-447 (lines=21) @@
424
        # if array is returned, the dtype is object, so convert to float
425
        return np.float64(qlat), np.float64(qlon)
426
427
    def _qd2apex_nonvectorized(self, qlat, qlon, height):
428
429
        qlat = helpers.checklat(qlat, name='qlat')
430
431
        alon = qlon
432
        hA = self.get_apex(qlat, height)  # apex height
433
434
        if hA < self.refh:
435
            if np.isclose(hA, self.refh, rtol=0, atol=1e-5):
436
                # allow for values that are close
437
                hA = self.refh
438
            else:
439
                estr = 'apex height ({:.3g}) is < reference height '.format(hA)
440
                estr += '({:.3g}) for qlat {:.3g}'.format(self.refh, qlat)
441
                raise ApexHeightError(estr)
442
443
        alat = np.sign(qlat) * np.degrees(np.arccos(np.sqrt((self.RE +
444
                                                             self.refh) /
445
                                                            (self.RE + hA))))
446
447
        return alat, alon
448
449
    def qd2apex(self, qlat, qlon, height):
450
        """Converts quasi-dipole to modified apex coordinates.