#๐Ÿ”’ Help With Making a Cone of Uncertainty (Using it for help)

41 messages ยท Page 1 of 1 (latest)

keen kestrelBOT
#

@split jetty

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

split jetty
#

@crisp crater Basically I'm trying to make a forecast cone

#

That gets larger and larger the further out it is

crisp crater
#

mhmm, so the shapes all overlap and you end up with less transparency than what you want

split jetty
#

Exactly

crisp crater
#

what are you using to render this?

split jetty
#

I don't know how to properly send the syntax in here

crisp crater
#

!code

keen kestrelBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

split jetty
#

I've tried that

#
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from scipy.interpolate import splprep, splev

# Generate data points for the hurricane path
num_points = 9
latitudes = [18.4, 19.1, 19.6, 19.9, 20.4, 21.0, 22.0, 24.5, 27.0]
longitudes = [-46.6, -47.3, -48.3, -49.4, -50.7, -52.4, -54.1, -57.0, -57.0]
forecast_winds = [40, 65, 90, 110, 135, 140, 115, 95, -70]  # In knots, -ve sign means not tropical

# Function to calculate intermediate points along the line
def calculate_line_points(latitudes, longitudes, num_points):
    line_points = []
    for i in range(num_points - 1):
        x0, y0 = longitudes[i], latitudes[i]
        x1, y1 = longitudes[i + 1], latitudes[i + 1]
        distance = np.sqrt((x1 - x0)**2 + (y1 - y0)**2)
        num_intermediate_points = int(distance / 0.2)  # Adjust the step size as needed
        xs = np.linspace(x0, x1, num_intermediate_points)
        ys = np.linspace(y0, y1, num_intermediate_points)
        line_points.extend(list(zip(xs, ys)))
    return line_points

# Calculate intermediate points along the line
line_points = calculate_line_points(latitudes, longitudes, num_points)

# Calculate cone radius based on some function (e.g., linear increase)
cone_radius = np.linspace(0.4, 3.42, len(line_points))  # Adjust according to your radius values

# Create a figure and axis with a specific map projection (PlateCarree)
fig, ax = plt.subplots(subplot_kw={'projection': ccrs.PlateCarree()}, figsize=(12, 10))

# Plot the world map using Cartopy's features
ax.add_feature(cfeature.COASTLINE, linewidth=0.5, zorder=1)
ax.add_feature(cfeature.BORDERS, linewidth=0.5, zorder=1)
ax.add_feature(cfeature.LAND, facecolor='lightgray', zorder=0)
ax.add_feature(cfeature.OCEAN, facecolor='lightblue', zorder=0)

# Add latitude and longitude gridlines
ax.gridlines(draw_labels=True, linewidth=0.5, linestyle='--', color='gray', zorder=2)

# Plot the hurricane path in black
plt.plot(longitudes, latitudes, 'k-', label='TC Path', zorder=3)
# Plot the cone of uncertainty as filled polygons with a single color
for i, (lon, lat) in enumerate(line_points):
    radius = cone_radius[i]
    
    # Generate points for the polygon representing the cone
    angles = np.linspace(0, 2*np.pi, 100)
    polygon_lons = lon + radius * np.sin(angles)
    polygon_lats = lat + radius * np.cos(angles)
    
    # Add the polygon to the plot
    ax.fill(polygon_lons, polygon_lats, color='gray', alpha=0.2, transform=ccrs.PlateCarree(), zorder=2)

# Plot the data points with a thin black outline
category_labels = {
    -2: ('w', '*', 'Not Tropical'),
    5: ('m', 'o', 'Category 5'),
    4: ('r', 'o', 'Category 4'),
    3: ('#ff5908', 'o', 'Category 3'),
    1: ('#ffff00', 'o', 'Category 1'),
    0: ('g', 'o', 'Tropical Storm'),
    -1: ('b', 'o', 'Tropical Depression')
}

for i in range(num_points):
    if forecast_winds[i] < 0:
        category = -2
    elif forecast_winds[i] >= 140:
        category = 5
    elif forecast_winds[i] >= 115:
        category = 4
    elif forecast_winds[i] >= 100:
        category = 3
    elif forecast_winds[i] >= 65:
        category = 1
    elif forecast_winds[i] >= 35:
        category = 0
    else:
        category = -1

    color, marker, label = category_labels[category]
    
    if label not in [line.get_label() for line in ax.lines + ax.collections]:
        plt.scatter(longitudes[i], latitudes[i], color=color, marker=marker, edgecolor='k', linewidth=0.5, label=label, zorder=5)
    else:
        plt.scatter(longitudes[i], latitudes[i], color=color, marker=marker, edgecolor='k', linewidth=0.5, zorder=5)

# Set axis limits
ax.set_xlim(-80, -20)
ax.set_ylim(0, 40)

# Add labels and legend
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Hurricane Forecast Cone Test: AL182023 RINA 03Z September 29', pad=20)  # Add padding to the title
plt.legend()

#

Idk what I'm doing wrong

#

I did the 3 ```

crisp crater
#

you're not adding the py after the 3 `

split jetty
#

oh is it '''

#

oh ok

#

Tysm

#

Don't have room to fit it all

#
# Display the plot
plt.grid(True, zorder=1)
plt.tight_layout()  # Ensures the layout is tight
plt.show()```
#

There

split jetty
#

I've been asking ChatGPT for help, and it's been very successful up until now

split jetty
crisp crater
#

Yeah, let me experiment a bit with this... I don't have any experience with cartopy so I can't promise I'll be able to solve it

#

but I'll try

split jetty
#

Tysm

crisp crater
#

I found some promising things to check out. Give me some more time.

split jetty
#

That sounds good, Ight โœ…

crisp crater
#

let me just try and work this into the existing code

split jetty
crisp crater
#

How's this?

split jetty
#

Omg you actually did it

#

Thank you so so much!

crisp crater
#

No problem!

split jetty
#

Seriously, this really means a lot!

keen kestrelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.