Giter Site home page Giter Site logo

Directional data about trex HOT 4 CLOSED

mooch443 avatar mooch443 commented on May 28, 2024
Directional data

from trex.

Comments (4)

MarkJThomas avatar MarkJThomas commented on May 28, 2024

Hi @mooch443
Hope you are well. I appreciate that you are doing this off your own back, and the system is revolutionary for the work I am doing.
I just wondered if you had seen/can respond to the above question?
All the best,
Mark

from trex.

mooch443 avatar mooch443 commented on May 28, 2024

Hey, yes, you're right - this is basically on my free time right now, but I want to help whenever I can.
So if you're trying to see the speed in x-direction (the velocity), you can use VX from the npz file, which is exactly that. You can of course try to fix the posture data so far that you can use it. Not sure how well it performs on those - I suspect you would have to increase the track_posture_threshold quite a bit for it to work. Pro-Tip: You can always check using track_threshold to see if a certain threshold value works as intended (cuts off enough of the animals, like the legs and antennae) and then set this value for track_posture_threshold - and reset track_threshold to what you had before. I'll make this easier in 2.0, so stay tuned I guess!

The question would be whether VX is already enough (or you could calculate VX yourself by using the X-positions), or if you need posture to work reliably. I think VX should suffice in your case, though, unless you say otherwise.

If you want to calculate distance covered, you could do sum(SPEED * time') for a certain range of frames, no? You just have to modify it somehow so that you have one value per fix sequence length or something. If that's what you need :D

-Tristan

from trex.

MarkJThomas avatar MarkJThomas commented on May 28, 2024

Perfect, thank you so much!
If I wanted to see how far they move up or down from the midline I can use the Y.wcentroid?
And is there a way to have rolling IDs, so never repeat an ID when that ID is lost? So for example, we have ant 1 that moves from left to right in the box, he goes out of the video and a new ant appears, rather than assigning it with the same number (if the programme believes it's the same ant) it always rolls over to a new ID.
TIA

from trex.

mooch443 avatar mooch443 commented on May 28, 2024

Hey! There is no way to do this, no. However, there is a way in Python that I can share if you are interested. Instead of assigning the same number, you would get a dataframe with IDs per segment (so as you suggested).

(its not pretty code and might not work out of the box, but I think it helps to illustrate)

##### CONFIG
columns = [
    ("x", "X#wcentroid"),
    ("y", "Y#wcentroid"),
    ('num_pixels', 'num_pixels'),
    ('time', 'time'),
    ('angle', 'ANGLE#wcentroid'),
    ('vx', 'VX#wcentroid'),
    ('vy', 'VY#wcentroid'),
    ("speed", 'SPEED#wcentroid')
]

video = "video_name"
base_path = "/root/path"

##########
segID = 0
DF = None

output = output_dir+os.sep+video+".pkl"
files = glob.glob(base_path+os.sep+"data"+os.sep+video+"_fish*.npz")
if len(files) == 0:
    raise Exception("No data for video",video)
    
print("\tFound",len(files),"files.")

j = 0
for path in sorted(files):
    index = path.split(os.sep)
    index = int(index[-1].split('_fish')[-1].split('.')[0])

    j = j + 1
    if j%100 == 0:
        print(j,"/",len(files),path,"individual",index)

    with np.load(path) as npz:
        frame_segments = npz["frame_segments"]
        frame = npz["frame"].astype(int)
        m = {
            "id": np.repeat(index, len(frame)),
            "frame": frame
        }
        
        for c, k in columns:
            m[c] = npz[k]
            m[c][np.isinf(m[c])] = np.nan
            #print(m[c].shape)


        segIDs = np.full(len(frame), -1, dtype=int)

        for start, end in frame_segments:
            if end - start >= segment_threshold:
                segIDs[np.logical_and(frame >= start, frame <= end)] = segID
                segID += 1

        m["segID"] = segIDs

        df = pd.DataFrame(m)
        if type(DF) == type(None):
            DF = df
        else:
            DF = pd.concat((DF, df), ignore_index = True)

DF # your dataframe

from trex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.