RatInABox-Lab / RatInABox

A python package for modelling locomotion in complex environments and spatially/velocity selective cell activity.
MIT License
172 stars 31 forks source link

Restructure FOV #69

Closed mehulrastogi closed 12 months ago

mehulrastogi commented 1 year ago

Solves #56

I did try to make this backward compatible but that might actually result in circular callbacks to the __init__ functions. There might be a way around that but in general will involve adopting bad practices and will not be maintainable in the long run, which is what we are trying to achieve here.

Current

FoVs_OVC = FieldOfViewNeurons(Ag,params={'cell_type':'OVC'})
FoVs_BVC = FieldOfViewNeurons(Ag,params={'cell_type':'BVC'})
FoVs_WC = FieldOfViewNeuronsAg,params={'cell_type':'BVC',"FoV_angles":[75,105],"FoV_distance":[0.1,0.2],"spatial_resolution":0.02})

Post the change

FoVs_OVC = FieldOfViewNeurons.get_instance(Ag,params={'cell_type':'OVC'})
FoVs_BVC = FieldOfViewNeurons.get_instance(Ag,params={'cell_type':'BVC'})
FoVs_WC = FieldOfViewNeurons.get_instance(Ag,params={'cell_type':'BVC',"FoV_angles":[75,105],"FoV_distance":[0.1,0.2],"spatial_resolution":0.02})

I tried to implement the factory method. This in my opinion is a small change in the API considering it rid of the super object in the FOV class. What do you think?

mehulrastogi commented 1 year ago

Also just a side note: This kind of change will definitely break any pipelines that dependent on actually using the 'dirty' super object

mehulrastogi commented 1 year ago

Some resource on the Python Multiple Inheritance

Basically according to this to not break anything while doing multiple inheritance we should :-

#!/usr/bin/env python2

class First(object):
  def __init__(self):
    print "First(): entering"
    super(First, self).__init__()
    print "First(): exiting"

class Second(object):
  def __init__(self):
    print "Second(): entering"
    super(Second, self).__init__()
    print "Second(): exiting"

class Third(First, Second):
  def __init__(self):
    print "Third(): entering"
    super(Third, self).__init__()
    print "Third(): exiting"
Third --> First --> Second --> object

From https://stackoverflow.com/a/30187306

TomGeorge1234 commented 12 months ago

Plan is to make all these changes to a new neurons class in the core Neurons.py file and leave the contribs FoV neurons unchanged (but add a deprecation warning). Closing this for now, follow on issue #71