# How to save flow lines using the python API?

**URL:** <https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320>\
**Category:** Uncategorized\
**Created:** [August 21, 2023, 3:40pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320 "2023-08-21T15:40:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![avijeet](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@avijeet](https://vapor.discourse.group/u/avijeet)\
**Post date:** [August 21, 2023, 3:40pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/1 "2023-08-21T15:40:20Z")

</div>

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:

```python
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

---

<div class="post-metadata">

**Author:** ![sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sam](https://vapor.discourse.group/u/sam)\
**Post date:** [August 22, 2023, 4:03pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/2 "2023-08-22T16:03:38Z")

</div>

> [@avijeet](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![avijeet](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@avijeet](https://vapor.discourse.group/u/avijeet)\
**Post date:** [August 23, 2023, 9:03am UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/3 "2023-08-23T09:03:27Z")

</div>

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.

## ![Screenshot 2023-08-23 at 10.55.50](https://global.discourse-cdn.com/free1/uploads/vapor/original/1X/f66d8f90f1b7a6577af52a9e4e542621d433508c.jpeg)

 ![Screenshot 2023-08-23 at 10.56.21](https://global.discourse-cdn.com/free1/uploads/vapor/original/1X/32494d22fcfe0b4748af0d08a861bee2299699a0.jpeg)

Here’s some metadata on the variables

```auto
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:

```auto
# 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:

```python
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

---

<div class="post-metadata">

**Author:** ![sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@sam](https://vapor.discourse.group/u/sam)\
**Post date:** [August 29, 2023, 8:27pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/4 "2023-08-29T20:27:28Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![avijeet](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@avijeet](https://vapor.discourse.group/u/avijeet)\
**Post date:** [August 30, 2023, 8:50am UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/5 "2023-08-30T08:50:45Z")

</div>

Hi @sam,

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

---

<div class="post-metadata">

**Author:** ![StasJ](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@StasJ](https://vapor.discourse.group/u/StasJ)\
**Post date:** [September 1, 2023, 1:42pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/6 "2023-09-01T13:42:18Z")

</div>

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.

```auto
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()

```

---

<div class="post-metadata">

**Author:** ![avijeet](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@avijeet](https://vapor.discourse.group/u/avijeet)\
**Post date:** [September 1, 2023, 2:21pm UTC](https://vapor.discourse.group/t/how-to-save-flow-lines-using-the-python-api/320/7 "2023-09-01T14:21:42Z")

</div>

> [@StasJ](#):
>
> ```auto
> 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 🙂
