Skip to content

Commit

Permalink
Reordering of methods in population.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan Forgan committed Dec 11, 2018
1 parent 9d03d81 commit e47168c
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions taktent/populations/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,7 @@ def calculate_means(self):



def record_detections(self):
"""
For each Observer, write a file containing all detected Transmitters
"""

for a in self.agents:
if a.type=="Observer":

outputfile = "Observer_"+a.ID+"_time_00"+str(round(self.time,2))+".detections"

f_obj = open(outputfile, 'w')

f_obj.write("# Type ID x y z nx ny nz nu bandwidth power openingangle pulseduration pulseinterval\n")

for key in a.detect.keys():
transmitter = self.find_agent(key)

f_obj.write(transmitter.write_to_file())

f_obj.close()



Expand Down Expand Up @@ -312,8 +293,6 @@ def generate_identical_transmitters(self, N_transmitters, strategy,semimajoraxis

self.add_agent(agent)



def generate_observer(self, observe_direction, openangle, strategy, spatial_distribution="random_sphere"):
"""Place a single observer object according to a spatial distribution"""

Expand All @@ -338,7 +317,6 @@ def generate_observer_at_origin(self,observe_direction,openangle,strategy):

return self.agents[-1].ID


def define_agent_strategies(self,strategy,agentType):
"""Define strategies of agents in the population (where they are type agentType)"""
for agent in self.agents:
Expand All @@ -352,10 +330,19 @@ def define_transmitter_strategies(self,strategy):
def define_observation_strategies(self,strategy):
"""Define strategies of observers"""
self.define_agent_strategies(self,strategy,"Observer")


def run_simulation(self, write_detections=False, make_plots=False, fullskymap=False):

"""
Run Population detection simulation from beginning to end
Keyword Arguments:
------------------
write_detections - record individual detections to file?
make_plots - Plot xy position and skymaps for all Observers?
fullskymap - Plot all sky maps for each Observer?
"""

self.initialise()
for i in range(self.nsteps):

Expand All @@ -365,7 +352,12 @@ def run_simulation(self, write_detections=False, make_plots=False, fullskymap=Fa

self.write_means_to_file()


def initialise(self):
"""
Set time to zero, and ensure all Agents in population are correctly up to date
"""
self.time = 0.0
self.update_agents()


def update(self, write_detections=False, make_plots=False, fullskymap=False):
Expand Down Expand Up @@ -411,10 +403,6 @@ def update_agents(self):
self.ymin = agent.position.y


def initialise(self):
"""Set time to zero, and ensure all Agents in population are correctly up to date"""
self.time = 0.0
self.update_agents()


def generate_skymaps(self,fullmap=False):
Expand Down Expand Up @@ -488,8 +476,30 @@ def plot(self,filename=None):

plt.close()


def record_detections(self):
"""
For each Observer, write a file containing all detected Transmitters
"""

for a in self.agents:
if a.type=="Observer":

outputfile = "Observer_"+a.ID+"_time_00"+str(round(self.time,2))+".detections"

f_obj = open(outputfile, 'w')

f_obj.write("# Type ID x y z nx ny nz nu bandwidth power openingangle pulseduration pulseinterval\n")

for key in a.detect.keys():
transmitter = self.find_agent(key)

f_obj.write(transmitter.write_to_file())

f_obj.close()

def write_means_to_file(self):
"""Write mean dictionary to file"""
"""Write mean population data to file"""

outputfile = "Population_"+self.ID.zfill(3)+"_meandata.dat"

Expand Down

0 comments on commit e47168c

Please sign in to comment.