localdevices / pyorc

Surface velocity, object tracking, and river flow measurements in an open-source API
GNU Affero General Public License v3.0
129 stars 31 forks source link

Getting Values from Plots #157

Closed tristanfivaz closed 4 months ago

tristanfivaz commented 4 months ago

Hi All!

I was hoping someone could solve the following query of mine:

I am currently using PyOpenRiverCam with Jupyter Notebook and following all the guides as is. I wanted to know if there was a way to extract the individual velocity plot values on the output images so that a variable could be assigned to them - for the purpose of generating the average surface velocity. Is there a way this can be done?

I'm a huge fan of your team's work and have exciting applications I would love to follow through with.

Thankyou so much!

Tristan

hcwinsemius commented 4 months ago

Hi Tristan,

Great that you are working on the examples. Did you know you can also run things in a command line interface by the way? This will make running many videos more practical. Setting up of the camera configuration also has a number of visual click options to select the ground control points and area of interest.

Your question: of course you can access the variables. Say that you have a file called piv_results.nc then you can open this with nornal xarray functionalities and extract, reduce, transform, plot with all xarray functionalities. Each file contains variables v_x and v_y. Pseudo code like below should give more or less what you need:

# open dataset and estimate scalar velocities
ds = xr.open_dataset("piv_results.nc")
v_scalar = (ds["v_x"]**2 + ds["v_y"]**2)**0.5

# average velocity in time
v_mean = v_scalar.mean(dim="time")

# average over entire grid
v_reduced = v_mean.mean(dim="x").mean(dim="y")

Kindly let us know if this answers your question.

tristanfivaz commented 4 months ago

That works perfectly!! Thankyou so much, you're incredible :))

hcwinsemius commented 4 months ago

Please check out the xarray docs for further information on how to manipulate your results.