Current speed and direction vectot plot of DFSU #717
Unanswered
pradhancda
asked this question in
Q&A
Replies: 2 comments
-
Hi - Have you looked at the example notebook https://github.com/DHI/mikeio/blob/main/notebooks/Dfsu%20-%20Speed%20and%20direction.ipynb ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you Sir,
I will visit this link and try to solve the issue.
With best regards,Dr. Subhasis Pradhan, Ph.D.
Project Scientist,Chilika Development Authority, OdishaE-mail - ***@***.******@***.*** ***@***.*** - +91- 8249458380/ 9437735333
On Wednesday 21 August, 2024 at 11:51:43 am IST, Jesper Sandvig Mariegaard ***@***.***> wrote:
Hi - Have you looked at the example notebook https://github.com/DHI/mikeio/blob/main/notebooks/Dfsu%20-%20Speed%20and%20direction.ipynb ?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here is the tets code ;
Please guide, how to get the current speed and direction vector plot for monthly mean?
import mikeio
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import pandas as pd
Read the DFSU file
file_path = r"D:\MIKE_Zero_Projects\Akash\1999\1999+HD+PT+TM+WITH_VEG_JAN.m21fm - Result Files\HD_1999_Jan_veg.dfsu"
ds = mikeio.read(file_path)
ds
Extract time and coordinates
time = ds.time
Extract coordinates
nc = ds.geometry.node_coordinates
ec = ds.geometry.element_coordinates
xn = nc[:, 0]
yn = nc[:, 1]
zn = nc[:, 2]
xe = ec[:, 0]
ye = ec[:, 1]
ze = ec[:, 2]
Extract U velocity and V velocity
u10 = ds['U velocity'].values
v10 = ds['V velocity'].values
Check dimensions
print(f'u10 shape: {u10.shape}')
print(f'v10 shape: {v10.shape}')
print(f'xe length: {len(xe)}')
print(f'ye length: {len(ye)}')
Reshape coordinates if necessary
Assume xe and ye should be reshaped to match u10 and v10 dimensions
Example: if xe and ye are flattened, they need to be reshaped into 2D arrays
Here, we'll assume xe and ye are 1D arrays that should be reshaped
We need to confirm the grid resolution and dimensions
grid_x = np.linspace(np.min(xn), np.max(xn), u10.shape[1])
grid_y = np.linspace(np.min(yn), np.max(yn), u10.shape[0])
x_grid, y_grid = np.meshgrid(grid_x, grid_y)
Verify dimensions match
if x_grid.shape != u10.shape or y_grid.shape != v10.shape:
raise ValueError("Coordinate grid dimensions do not match velocity dimensions.")
Create a mask to exclude NaN values
valid_mask = ~np.isnan(u10) & ~np.isnan(v10)
Apply the mask to velocities
u10_valid = u10[valid_mask]
v10_valid = v10[valid_mask]
Plot quiver
plt.figure(figsize=(12, 8))
plt.quiver(x_grid[::density, ::density], y_grid[::density, ::density],
u10[::density, ::density] * arrow_length_scale,
v10[::density, ::density] * arrow_length_scale,
color='k', scale=1, scale_units='inches', angles='xy')
Customize plot
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Wind Speed and Direction')
Adjust the plot settings
plt.axis('equal')
plt.xlim([np.min(x_grid), np.max(x_grid)])
plt.ylim([np.min(y_grid), np.max(y_grid)])
Display date for the chosen time index
time_idx = 0 # Modify as needed
date_str = pd.to_datetime(ds.time[time_idx], unit='days', origin='unix').strftime('%Y-%m-%d')
print(f'Date for time index {time_idx}: {date_str}')
Save the figure
output_filename = f'{date_str}.jpg'
plt.savefig(output_filename, dpi=300)
plt.show()
Beta Was this translation helpful? Give feedback.
All reactions