I have a custom detector that extends PythonAbstractDetector:
class RangeDetector(PythonAbstractDetector):
def __init__(self,topo: TopocentricFrame, maxCheck: float=PythonAbstractDetector.DEFAULT_MAXCHECK, threshold: float=PythonAbstractDetector.DEFAULT_THRESHOLD,
maxIter: int=PythonAbstractDetector.DEFAULT_MAX_ITER, handler: PythonEventHandler=StopOnDecreasing(),
minRange: float=0.0,
refractionModel: AtmosphericRefractionModel=None):
"""
Creates an instance of Range detector based on passed in topocentric frame
and overrides of default maximal checking interval and convergence threshold values.
"""
self._MAXRANGE = minRange
self._REFRACTIONMODEL = refractionModel
self._TOPO = topo
super(RangeDetector,self).__init__(maxCheck,threshold,maxIter,handler)
def create(self,newMaxCheck: float, newThreshold: float,
newMaxIter: int, newHandler: PythonEventHandler):
RangeDetector(self._TOPO,maxCheck=newMaxCheck,threshold=newThreshold,maxIter=newMaxIter,handler=newHandler,
minRange=self._MAXRANGE,refractionModel=self._REFRACTIONMODEL)
def getMinRange(self) -> float:
return self._MAXRANGE
def getRefractionmodel(self) -> float:
return self._REFRACTIONMODEL
def getTopocentricFrame(self) -> float:
return self._TOPO
def g(self,s: SpacecraftState) -> float:
TRUERANGE = self._TOPO.getRange(s.getPVCoordinates().getPosition(),
s.getFrame(), s.getDate())
CALCULATEDRANGE = 0.0
if self._REFRACTIONMODEL != None:
CALCULATEDRANGE = TRUERANGE + self._REFRACTIONMODEL.getRefraction(TRUERANGE)
else:
CALCULATEDRANGE = TRUERANGE
return CALCULATEDRANGE - self._MAXRANGE
def withConstantRange(self, newMaxRange: float):
return RangeDetector(self._TOPO,maxCheck=self.getMaxCheckInterval(),threshold=self.getThreshold(),
maxIter=self.getMaxIterationCount(),handler=self.getHandler(),
minRange=newMaxRange,refractionModel=self._REFRACTIONMODEL)
def withRefraction(self, newRefractionModel: AtmosphericRefractionModel):
return RangeDetector(self._TOPO,maxCheck=self.getMaxCheckInterval(),threshold=self.getThreshold(),
maxIter=self.getMaxIterationCount(),handler=self.getHandler(),
minRange=self._MAXRANGE,refractionModel=newRefractionModel)
I am instatiating it using:
tempHandler2 = RangeVisibilityHandler(index)
station1RangeVisible = RangeDetector(station._topocentricFrame,Common.maxStep,ElevationDetector.DEFAULT_THRESHOLD,handler=tempHandler2)\
.withConstantRange(station._maxRange)\
.withHandler(tempHandler2) # Range restrictions
And the RangeVisibilityHandler is:
class RangeVisibilityHandler(PythonEventHandler):
"""
Handler for range visibility event. Implements PythonEventHandler<RangeDetector>.
"""
index = 0
def __init__(self, index):
self.index = index
super(RangeVisibilityHandler, self).__init__()
def init(self, initialState, target, detector):
print(initialState,target,detector)
def eventOccurred(self, state: SpacecraftState, detector: RangeDetector, increasing: bool) -> Action:
if increasing:
SimulateObservation.endRangeObserveDate[self.index] = state.getDate()
print(f" Range visibility on station {self.index} {detector.getTopocentricFrame().getName()} end at {state.getDate()}")
else:
SimulateObservation.startRangeObserveDate[self.index] = state.getDate()
SimulateObservation.endRangeObserveDate[self.index] = SimulateObservation.finalDate
print(f" Range visibility on station {self.index} {detector.getTopocentricFrame().getName()} begins at {state.getDate()}")
return Action.CONTINUE
def finish(self, spacecraftState: SpacecraftState, eventDetector: EventDetector) -> None:
pass
def resetState(self, eventDetector: EventDetector, oldState: SpacecraftState) -> SpacecraftState:
return oldState
When I use .withHandler(tempHandler2)
it returns station1RangeVisible as None. I commented out .withHandler(tempHandler2)
and called station1RangeVisible.getHandler()
and it shows <EventHandler: org.orekit.propagation.events.handlers.PythonEventHandler@bfc14b9>
which is not the handler that I input and I do not have access to the custom methods I put into the RangeVisibilityHandler class.
I believe I did the subclassing correctly, implementing all the methods that I saw, and I do not know what is causing it to seemingly ignore the custom handler.
All help is very much appreciated.
Thank you!