Source code for irfpy.earth.bowshock

import os,sys
import math
import logging

import numpy as np

[docs]class BsModelFairfield(): ''' Bow shock model proposed by Fairfield et al., 1971 ''' def __init__(self): self.a = 0.0296 self.b = -0.0381 self.c = -1.280 self.d = 45.644 self.e = -652.10 self._re = 6378.
[docs] def isInside(self, x, y, z): ''' Return true if the position (x,y,z)[Rm] is in or on the bow shock. ''' r = math.sqrt(y*y+z*z) f = r**2 + self.a*x*r + self.b * (x**2) + self.c * r + self.d * x + self.e return f<0
[docs] def isInsideKm(self, x, y, z): ''' Return true if the position (x,y,z)[Km] is in or on the bow shock. ''' rx = x/self._re ry = y/self._re rz = z/self._re return self.isInside(rx,ry,rz)
[docs] def getBounds2D(self): ### x range is x < 14.46 a,b,c,d,e = self.a,self.b,self.c,self.d,self.e arr=[] def _solve(x): DD = (c+a*x)**2 - 4 * (b*x*x+d*x+e) DD = math.sqrt(DD) y= (DD - c - a*x)/2 return y for x in range(-1000,144): x=x/10. y=_solve(x) arr.append([x,y]) for x in range(1440,1447): x=x/100. y=_solve(x) arr.append([x,y]) return arr
[docs]def getboundary(): ''' Return the boundary in Rm. ''' model = BsModelFairfield() return model.getBounds2D()
import unittest import doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__ == '__main__': unittest.main(defaultTest='doctests')