Code Duplication    Length = 21-42 lines in 2 locations

src/apexpy/apex.py 2 locations

@@ 363-404 (lines=42) @@
360
        # if array is returned, dtype is object, so convert to float
361
        return np.float64(glat), np.float64(glon), np.float64(error)
362
363
    def _apex2qd_nonvectorized(self, alat, alon, height):
364
        """Convert from apex to quasi-dipole (not-vectorised)
365
366
        Parameters
367
        -----------
368
        alat : (float)
369
            Apex latitude in degrees
370
        alon : (float)
371
            Apex longitude in degrees
372
        height : (float)
373
            Height in km
374
375
        Returns
376
        ---------
377
        qlat : (float)
378
            Quasi-dipole latitude in degrees
379
        qlon : (float)
380
            Quasi-diplole longitude in degrees
381
        """
382
383
        alat = helpers.checklat(alat, name='alat')
384
385
        # convert modified apex to quasi-dipole:
386
        qlon = alon
387
388
        # apex height
389
        hA = self.get_apex(alat)
390
391
        if hA < height:
392
            if np.isclose(hA, height, rtol=0, atol=1e-5):
393
                # allow for values that are close
394
                hA = height
395
            else:
396
                estr = 'height {:.3g} is > apex height'.format(np.max(height))\
397
                       + ' {:.3g} for alat {:.3g}'.format(hA, alat)
398
                raise ApexHeightError(estr)
399
400
        salat = np.sign(alat) if alat != 0 else 1
401
        qlat = salat * np.degrees(np.arccos(np.sqrt((self.RE + height) /
402
                                                    (self.RE + hA))))
403
404
        return qlat, qlon
405
406
    def apex2qd(self, alat, alon, height):
407
        """Converts modified apex to quasi-dipole coordinates.
@@ 437-457 (lines=21) @@
434
        # if array is returned, the dtype is object, so convert to float
435
        return np.float64(qlat), np.float64(qlon)
436
437
    def _qd2apex_nonvectorized(self, qlat, qlon, height):
438
439
        qlat = helpers.checklat(qlat, name='qlat')
440
441
        alon = qlon
442
        hA = self.get_apex(qlat, height)  # apex height
443
444
        if hA < self.refh:
445
            if np.isclose(hA, self.refh, rtol=0, atol=1e-5):
446
                # allow for values that are close
447
                hA = self.refh
448
            else:
449
                estr = 'apex height ({:.3g}) is < reference height '.format(hA)
450
                estr += '({:.3g}) for qlat {:.3g}'.format(self.refh, qlat)
451
                raise ApexHeightError(estr)
452
453
        sqlat = np.sign(qlat) if qlat != 0 else 1
454
        alat = sqlat * np.degrees(np.arccos(np.sqrt((self.RE + self.refh) /
455
                                                    (self.RE + hA))))
456
457
        return alat, alon
458
459
    def qd2apex(self, qlat, qlon, height):
460
        """Converts quasi-dipole to modified apex coordinates.