Download example.py from ray3389/fr-radar-rainfall: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/datasets/ray3389/fr-radar-rainfall/resolve/main/example.py
- Command line
-
hf download hf://datasets/ray3389/fr-radar-rainfall/example.py
-
curl -L -o example.py https://huggingface.co/datasets/ray3389/fr-radar-rainfall/resolve/main/example.py
1.02 kB
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from plots import plot_map_rain, project_to_latlon | |
| # Load the file | |
| data = np.load("2020/202004201700.npz") # Adjust path as needed | |
| rain = data["arr_0"] # The array is stored under 'arr_0' | |
| print("Array shape:", rain.shape) # Shape = (1536, 1536) | |
| # Negative values indicate no data, replace them with NaN: | |
| rain = np.where(rain < 0, np.nan, rain) | |
| # Visualize | |
| print("Making basic plot...") | |
| plt.imshow(rain, cmap="Blues") | |
| plt.colorbar(label="Rainfall (x0.01 mm / 5min)") | |
| plt.title("Rainfall Accumulation – 2020-04-20 17:00 UTC") | |
| plt.savefig("rainfall_20200420_1700_basic.png") | |
| plt.close() | |
| print("Converting and projecting rainfall data...") | |
| rain = rain / 100 # Convert from mm10-2 to mm | |
| rain = rain * 60 / 5 # Convert from mm to mm/h | |
| da_reproj = project_to_latlon(rain) | |
| print(da_reproj) | |
| print("Plotting projected rainfall data...") | |
| plot_map_rain( | |
| data=da_reproj, | |
| title="Rainfall Rate – 2020-04-20 17:00 UTC", | |
| path="rainfall_20200420_1700_map.png", | |
| ) | |