Skip to main content

MothPy allows simulation moth-like navigators in dynamic 2D odour concentration fields spread in turbulent flows

Project description

DOI Binder

MothPy

The mothpy package is a NumPy based implementation of moth-inspired navigation strategies that uses pompy library to create the puff, wind and concentration models. See pompy/Readme.md for details

What is this repository for?

This Python package allows simulation moth-like navigators in dynamic 2D odour concentration fields spread in turbulent flows

Liberzon, Harrington, Daniel, Gurka, Harari and Zilman "Moth-inspired navigation algorithm in a turbulent odor plume from a pulsating source" proposed a novel navigator principle using properties of a turbulent patchy plume, https://journals.plos.org/plosone/article/comments?id=10.1371/journal.pone.0198422

In order to compare this moth-inspired navigator with other navigator types available in the literature, e.g. by Carde and co-workers, we use pompy https://github.com/InsectRobotics/pompy and add these moth-inspiried navigators to its simulation fields. We try to create mean wind with meandering and turbulence and vary odor release parameters to test various navigators' statistics, e.g. success rate, flight time, etc.

Installation and requirements

Python 2.7
Numpy
Scipy
Matplotlib
pompy*

Note: we use an older version of pompy, included in the repository. In the future, we would be able to update to a newer version of pompy and implement it as a submodule.

Example usage

python compare_navigators_in_different_wind_conditions.py

Demo flight

How to create figures from the paper

Set up the navigators (optional)

The file Casting_competition initiates the navigators to compete in the simulation. Four loops initiate four equal sized groups of navigators, their properties can be changed within these loops - navigation and casting strategies, location, and so on. For more information about navigators check out the models file.

Set up the wind and plume conditions (optional)

The file Compare_navigtors... initiates the main loop. For each iteration a new plume and wind model are initiated for the simulation to occur in. The function generate_job dictates the terms of the simulation in terms of wind and plume partameteres. In order to set the simulation enter the required parameters as input for generate_job. For example:

for i in range(4):
    job_file_name = 'job'+ str(i)+ '.json'
    data_file_name = 'data'+ str(i)+ '.json'
    generate_job(char_time = 3.5, amplitude =0.1, job_file = job_file_name,
                    t_max =15, puff_release_rate = 100,
                    puff_spread_rate = 0.0001*(1+i),
                    dt = 0.01, num_it = 1)

The only value that changes is the puff spread rate, varying from 0.0001 to 0.0004. Make sure that only one variable of the simulation changes with each iteration. Multivaribale changes will create problems later on.

Run comapare_navigators.py

When the file is run the wind and plume paramters that have been set are saved into "job" files, one JSON file for each iteration (job0.JSON, job1.JSON...).

The trajectories of the navigators are saved as "data" files, (data0.JSON, data1.JSON), on which the later analyses will be made. Notice the following line

 save_plot(job_file_name, data_file_name, title, navigator_titles)

Would save an image per each navigation attempt in the default settings, and that means 800 images. Better if you comment it out #. That could supply useful input in some cases.

Run line_graphs.py

The file line_graphs plots bar graphs of the four different simulations. It read from the Data and Job files, so those could be replaced and There is no need to set up anything for this file, just run it. The output should look like this:

Success Percentage vs Puff Spread Rate Average Navigation Time vs Puff Spread Rate

How to manage and design navigators

initiating a navigator

Let us look at this example from the casting_competition file:

 navigator1 = models.moth_modular(sim_region, cd['x_start'], cd['y_start'], cd['nav_type'] , cd['cast_type'], cd['wait_type'])

The navigator is initiated with it is initial x and y coordinates and the modes of navigating, casting and waiting.

Wait, cast and navigation types

A navigator is an object of the moth_modular class. It has an attribute to define each movement type, wait_type, cast_type, nav_type.

The attribute itself can be an integer or a string, it doesn't matter, but it should correlate to a signifier inside of the corresponding function. For example, let's look at the casting function

def cast(self,wind_vel_at_pos):
        if self.state != 'cast' :
            #if this is the beginging of a new casting phase
            self.change_direction()
        if self.cast_type == 0:
            self.u=0
            self.v=0
        if self.cast_type == 1:
            self.calculate_wind_angle(wind_vel_at_pos)
            self.u = -self.speed*np.cos(self.gamma+self.wind_angle)
            self.v = self.speed*np.sin(self.gamma+self.wind_angle)
        if self.cast_type == 2:
            #define different betas for different casting patterns
            self.cast2(wind_vel_at_pos)

The function, like all movement functions, takes as input the parameters of the navigator and the wind velocity at the position (as calculated by the wind model). The first conditional changes the direction of casting from the previous direction. This has nothing to with the cast type. The second, third and fourth conditionals are dependent on the cast type, and use it as an indicator as to how to move. Note that the function can call upon other functions. The stracture of the wait and navigate are very similar - The function sets the velocity (u,v) of the navigator. The actual time step is performed in the update function.

Defining new movement types

In order to create a new waiting, casting or navigation, first enter the models file. For example, let's say we would like to design a new waiting mode. First, we sould define a condition within the waiting function.

def wait(self, wind_vel_at_pos):
    if wait_type == 'example wait type':

Now, if the navigator was initiated to so its wait type attribute is 'example wait type' the wait function will be directed into the actions we define under that conditional. Secondly, define the changes in you would like to be made to the velocity of the navigator:

def wait(self, wind_vel_at_pos):
    if wait_type == 'example wait type':
        u *= 1.1
        v *= 1.1

The same approach should be applied to any of the movement functions. After we defined the new condition, we can use it when initiating a new navigator:

 navigator1 = models.moth_modular(sim_region, cd['x_start'], cd['y_start'], cd['nav_type'], cd['cast_type'], 'example wait type')

How to cite this work

Please use the DOI in the suggested form:

Benneli, N. and Liberzon, A. "MothPy - a moth-inspired navigator flying in a plume-odor simulation fields" DOI

Run the Getting Starting test online:

Binder

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mothpy-0.0.1.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

mothpy-0.0.1-py2-none-any.whl (49.7 kB view details)

Uploaded Python 2

File details

Details for the file mothpy-0.0.1.tar.gz.

File metadata

  • Download URL: mothpy-0.0.1.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for mothpy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3cf71e75842b1b2b1d8422c894e395ac4638a73291b9e2520ead7ffa5425a4fc
MD5 c16c8e4e4c487552686e92a3ba0b1d0f
BLAKE2b-256 f3b7f783a64f5dd6e03454738b80b172ea50e1067773aceac1d9256efa8e4c60

See more details on using hashes here.

File details

Details for the file mothpy-0.0.1-py2-none-any.whl.

File metadata

  • Download URL: mothpy-0.0.1-py2-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for mothpy-0.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 dadbe8df18cb16c4ae9d892835183697d8ce3cb0746f1f16b4b88bac6b44a748
MD5 f491677d23141b767426abc19ef6a481
BLAKE2b-256 0badd5af77a786b65ff91f3936b560247459337247ceb6b3ddc067fec1c1e944

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page