How to save flow lines using the python API?

Hello,

I am currently working on a project where I need to generate flow lines from a dataset and save them as a .txt file. I am using the VAPOR (3.8.1) Python API for this task. Below is the code snippet I am working with:

import example_utils
from vapor import session, renderer, dataset, camera

ses = session.Session()
data = ses.OpenDataset(dataset.VDC, ["mydata.vdc"])
ren.SetSeedGenMode(ren.FlowSeedMode.UNIFORM)

rake = ren.GetRakeRegion()
defaultRakeExtents = rake.GetExtents()
rake.SetExtents((0, 0), (640, 416))
ren.SetGridNumOfSeeds([16, 10, 1])

seeding_grid = ren.GetGridNumOfSeeds()
rake_extents = rake.GetExtents()
print(f"Seeding a {seeding_grid} grid over {rake_extents}")

ren.SetFlowlineOutputFilename("flowlines_output.txt")
ses.Show()
rake.SetExtents(*defaultRakeExtents)

With the above code, I am able to generate the flow lines successfully and visualize them in the Jupyter notebook. However, I am encountering an issue when attempting to save these flow lines to a .txt file using the SetFlowlineOutputFilename method. The expected output file “flowlines_output.txt” is not being created.

Can you please provide some guidance on how this can be done?

Thank you in advance!

Best Regards,
Avijeet

Hello Avijeet,

Could you do me a favor and open the GUI interface of VAPOR and test outputting flow lines using the same data set and configuration? It will help us narrow down where the problem might lies.

Thanks,
Sam

Hi Sam,

Thanks for your reply. I am able to save the flow output from the Vapor GUI without any issues for the same vdc file with similar settings. I am attaching couple of screenshots which show the settings and output for both the GUI and the Jupyter notebook.

Here’s some metadata on the variables

Time Coordinate Variable Name: Nt
Coordinate Variable Names: ['Nt', 'Nx', 'Ny', 'Nz']
Dimensions:
  Nt: 1
  Nx: 640
  Ny: 416
  Nz: 416

Data Variables:

  bx
    Time Varying: True
    Dimensionality: 3
    Coordinates: ['Nx', 'Ny', 'Nz']
     Data Range: [-937.1851196289062, 996.595947265625]

  by
    Time Varying: True
    Dimensionality: 3
    Coordinates: ['Nx', 'Ny', 'Nz']
     Data Range: [-943.1206665039062, 936.4452514648438]

  bz
    Time Varying: True
    Dimensionality: 3
    Coordinates: ['Nx', 'Ny', 'Nz']
     Data Range: [-1589.54736328125, 1943.1552734375]

Here’s the first few lines of the output text file which was correctly generated from the GUI for your reference:

# ID,  X-position,  Y-position,  Z-position,  Formatted-time, Raw-time
0, 326.000000, 124.000000, 5.000000, 2001-01-01_00:00:00, 0.000000
0, 326.315186, 123.630112, 6.155806, 2001-01-01_00:00:00, 0.002551
0, 326.544312, 123.290260, 7.189109, 2001-01-01_00:00:00, 0.005101
0, 326.781738, 122.937164, 8.334703, 2001-01-01_00:00:00, 0.008290
0, 326.990417, 122.545044, 9.690810, 2001-01-01_00:00:00, 0.012275
0, 327.165405, 122.084175, 11.252686, 2001-01-01_00:00:00, 0.017257
0, 327.266846, 121.592369, 13.043659, 2001-01-01_00:00:00, 0.023484
0, 327.283081, 121.156792, 14.653299, 2001-01-01_00:00:00, 0.029711
0, 327.225464, 120.688080, 16.502077, 2001-01-01_00:00:00, 0.037495
0, 327.088043, 120.156128, 18.605148, 2001-01-01_00:00:00, 0.047225
0, 326.851166, 119.570839, 21.042261, 2001-01-01_00:00:00, 0.059388
0, 326.479675, 118.911446, 23.798985, 2001-01-01_00:00:00, 0.074591
0, 325.905060, 118.182518, 26.947809, 2001-01-01_00:00:00, 0.093595

Also, I don’t know if it’s relevant, but in the first line of the python file, during the imports, I get the following warning:

import example_utils
from vapor import session, renderer, dataset, camera

Warning: sysroot "/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" not found (ignoring for now).
Vapor 3.8.3
Python 3.9.17 (/Users/avijeetp/mambaforge/envs/vapor_python)
OpenGL 4.1 INTEL-20.6.4

I am using Xcode 14.3.1 on macOS 13.5 and check that the SDK was correctly installed.

Let me know if you need any other information.

Regards
Avijeet

Hi Avijeet, sorry for the late reply! Our python expert @StasJ thinks that you might missed a command or two in calling the Python API; he’ll provide more detail!

Hi @sam,

Thanks for your reply! Looking forward to suggestions from @StasJ on how to correctly implement the Python API for this issue :slight_smile:

Hi Avijeet,

The flow output is not exposed through the user-friendly Python interface, however, it is still accessible through the lower level interface. Thank you for bringing this to our attention, it has been resolved and will be included in an upcoming release of Vapor. I have included a function below which can be used in the interim.

def SaveFlowAdvection(ses:vapor.session.Session, ren:vapor.renderer.FlowRenderer, path:str="flow_output.csv", varsToSample:list[str]=[]):
    ren.SetFlowlineOutputFilename(path)
    ren._params.SetValueStringVec(ren._params._flowOutputMoreVariablesTag, "", varsToSample)
    ren._params.SetValueLong(ren._params._needFlowlineOutputTag, "", True)
    ses.RenderToImage()

@StasJ This works! Thank you very much :slight_smile: