Exawind / amr-wind

AMReX-based structured wind solver
https://exawind.github.io/amr-wind
Other
103 stars 78 forks source link

Unable to see variable in (Netcdf file) #991

Closed AsimUdel closed 3 months ago

AsimUdel commented 4 months ago

Hello, I am having trouble in reading the variables in my output file (.nc) (sampling00000.nc) file when I try to open in Python Jupyter notebook but I am able to read and see in AMR-Wind-Frontend (GUI), could someone please tell me what I should change in my input file so that I could see variables using Python or how to visualize the output file with some other tools? I am attaching my input file here in the attachment. Thank you AMR-Wind_input_file.txt

lawrenceccheung commented 4 months ago

Hi @AsimUdel

There shouldn't be any changes you need to make to the AMR-Wind input file itself. The sampling output files should be viewable in any environment that can load netcdf files, and if you can view them through the amr-wind-frontend GUI, then it ought to be possible to plot them in a jupyter notebook.

One thing that you can try is using a notebook like this one to visualize the sampling00000.nc: https://github.com/lawrenceccheung/ALCC_Frontier_WindFarm/blob/main/precursor/MedWS_LowTI/postprocessing/HubHeight_Viz.ipynb This one might be a little more lightweight notebook, and doesn't require loading the full amr-wind-frontend library in order for it to work.

Let me know if you have any questions about how to use it, or if you run into any issues loading it.

Lawrence

AsimUdel commented 4 months ago

Hi @lawrenceccheung Thank you so much, I have tried opening in Python using Jupyter notebook, I have come up with some error, Let me attach the file containing error, maybe I am doing something w error_while_opening_netcdf_file.txt rong. I would be grateful if you could guide me how to use https://github.com/lawrenceccheung/ALCC_Frontier_WindFarm/blob/main/precursor/MedWS_LowTI/postprocessing/HubHeight_Viz.ipynb this file.

lawrenceccheung commented 3 months ago

Hi @AsimUdel,

In the part of your script where you calculate the horizontal velocity

>>> iplane=1
>>> Uh=np.sqrt(db['velocityx'][0][iplane,:,:]**2)

set iplane=0. You only have one plane defined for xyplane, so that's why this error message appears:

IndexError: index 1 is out of bounds for axis 0 with size 1

Note that you have both the xyplane and yz contained in sampling00000.nc. By default, getPlaneXY() will extract the first plane that it sees (xyplane). To get the other plane, use the groupname option:

db     = ppsamplexr.getPlaneXR(amrdir+ncfile, iters, varnames, groupname='yz', verbose=0)

Lawrence

rybchuk commented 3 months ago

If you're using xarray, you will often have to specify the group variable when running xr.open_dataset. Below I've attached a screenshot of some code where I ran 6 different spinup simulations (I was trying different roughness and surface flux heat values), and you can see how I open the netCDF data of each of those simulations and concatenate them. I end up with two Datasets in the end: one for the profile variables (pstats) and one for the other variables.

image

AsimUdel commented 3 months ago

@lawrenceccheung I have tried as you suggested, I have attached screenshot of the Jupyter notebook and output of sampling00000.nc by GUI (AMR-Wind-Frontend), I don't know how to access the variable using Jupyter notebook my planes input files are yz-2D ,yz-4D, yz_0D, yz_2D, yz_4D, yz_6D, yz_8D xy_hub xy_rotor_top xy_rotor_bottom Kindly suggest me how to see the list of variables and shape so that I can plot them. Output_by_GUI error_python_opening

lawrenceccheung commented 3 months ago

hi @AsimUdel, in your case use

Uh = np.sqrt(db['velocityx'][2][iplane,:,:]**2)

In that last cell.

The dictionary that is returned by ppsamplexr.getPlaneXR() has the following structure:

db[varkey][iterkey][planenum, i, j]

where:

Hope this helps.

Lawrence

AsimUdel commented 3 months ago

@lawrenceccheung Thank you so much for comprehensive guide, right now I have plotted it. new_amr

AsimUdel commented 3 months ago

If you're using xarray, you will often have to specify the group variable when running xr.open_dataset. Below I've attached a screenshot of some code where I ran 6 different spinup simulations (I was trying different roughness and surface flux heat values), and you can see how I open the netCDF data of each of those simulations and concatenate them. I end up with two Datasets in the end: one for the profile variables (pstats) and one for the other variables.

image

@rybchuk Thank you so much, I will definitely look into that as (there must be many output files), I will try and get back to you soon.