API reference
Block
Bases: Module
A basic block for ResNet architecture. This block consists of two convolutional layers with batch normalization and ReLU activation. The first layer applies a 3x3 convolution, and the second layer applies another 3x3 convolution. The block also supports downsampling through an optional identity downsample layer. The expansion factor is set to 1, meaning the output channels are the same as the input channels.
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py
Source code in windscangeo\Models.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
Bottleneck
Bases: Module
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py A bottleneck block for ResNet architecture. This block consists of three convolutional layers with batch normalization and ReLU activation. The first layer reduces the number of channels, the second layer applies a 3x3 convolution, and the third layer expands the number of channels back to the original size. The block also supports downsampling through an optional identity downsample layer.
Source code in windscangeo\Models.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
ConventionalCNN
Bases: Module
A simple CNN for image regression tasks. This model consists of a series of convolutional layers followed by fully connected layers. It is designed to process images and output a single regression value (e.g., wind speed).
Source code in windscangeo\Models.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
H5pyDataset
Bases: Dataset
A PyTorch Dataset for loading data from an HDF5 file. This is useful when dealing with large datasets that do not fit into memory. Need to work on Zarr integration for better performance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h5_file_path
|
str
|
Path to the HDF5 file. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Img2Seq
Bases: Module
This layers takes a batch of images as input and returns a batch of sequences
Shape
input: (b, h, w, c) output: (b, s, d)
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
Normalize
Normalize the input tensor by subtracting the mean and dividing by the standard deviation. Done per batch
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
list or ndarray
|
Mean values for normalization. |
required |
std
|
list or ndarray
|
Standard deviation values for normalization. |
required |
Source code in windscangeo\func_ml.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
ResNet
Bases: Module
A ResNet model for image classification or regression tasks.
This model consists of an initial convolutional layer, followed by a series
of residual blocks, and a fully connected layer for classification or regression.
The number of residual blocks in each layer is specified by the layer_list parameter.
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py
Source code in windscangeo\Models.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
ViT
Bases: Module
Vision Transformer (ViT) model for image classification or regression tasks. This model consists of an image-to-sequence layer, a transformer encoder, and a multi-layer perceptron (MLP) head for classification or regression.
Taken from # https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
conventional_dataset
Bases: Dataset
A PyTorch Dataset for loading data using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images. |
required |
targets
|
list or ndarray
|
List or array of targets corresponding to the images. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
conventional_dataset_inference
Bases: Dataset
A PyTorch Dataset for loading data for inference (no lable) using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images to be used for inference. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
buoy_data_extract(folder_path, polar_data, date)
Extracts buoy data from a specified folder and returns arrays of latitude, longitude, time, wind speed, and buoy names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_path
|
str
|
Path to the folder containing buoy data files. |
required |
polar_data
|
Dataset
|
Polar data containing latitude and longitude information. Used to snap buoy data to the nearest polar grid points. |
required |
date
|
str
|
Date for which to extract buoy data, in 'YYYY-MM-DD' format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
buoy_lat |
ndarray
|
Array of buoy latitudes snapped to the nearest polar grid points. |
buoy_lon |
ndarray
|
Array of buoy longitudes snapped to the nearest polar grid points |
buoy_time |
ndarray
|
Array of buoy observation times. |
buoy_wind_speed |
ndarray
|
Array of buoy wind speeds. |
buoy_name |
ndarray
|
Array of buoy names. |
Source code in windscangeo\func_inference.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
calculate_degrees(file_id)
This function calculates the latitude and longitude of the GOES ABI fixed grid projection. This function comes from NOAA/NESDIS/STAR. (2025). Latitude and longitude remapping of GOES-R ABI imagery using Python . Atmospheric Composition Science Team. Retrieved from https://www.star.nesdis.noaa.gov/atmospheric-composition-training/python_abi_lat_lon.php
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
Dataset
|
The xarray dataset containing the GOES ABI fixed grid projection variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
abi_lat |
ndarray
|
The latitude of the GOES ABI fixed grid projection. |
abi_lon |
ndarray
|
The longitude of the GOES ABI fixed grid projection. |
Source code in windscangeo\func.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
create_folder(experiment_name)
Create a folder for saving results based on the experiment name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name
|
str
|
Name of the experiment to create a folder for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the created folder. |
Source code in windscangeo\func.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
early_stopping(valid_losses, patience_epochs, patience_loss)
Early stopping function to determine if training should stop based on validation losses. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid_losses
|
list
|
List of validation losses recorded during training. |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if training should stop, False otherwise. |
Source code in windscangeo\impl.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
error_plot(best_val_outputs, best_val_labels, path_folder=None)
Plot a scatter plot of model outputs vs true labels for the validation dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the plot. If None, the plot will not be saved. |
None
|
Source code in windscangeo\func_ml.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
extract_goes(observation_times, observation_lats, observation_lons, scatterometer_data_path, goes_aws_url_folder, goes_channel='C01', goes_image_size=128, verbose=True)
This function extracts GOES images for the given observation times, latitudes, and longitudes. It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
scatterometer_data_path
|
str
|
The path to the scatterometer data directory. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. |
required |
goes_channel
|
str
|
The channel of interest. Default is "C01". |
'C01'
|
goes_image_size
|
int
|
The size of the output images. Default is 128. |
128
|
verbose
|
bool
|
If True, prints progress information. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array of shape (num_observations, num_channels, goes_image_size, goes_image_size) containing the extracted GOES images. |
Source code in windscangeo\func.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
extract_goes_inference(date_time, parallel_index, channels='C01', goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF')
This function extracts GOES images for a given date_time and parallel_index. (whole GOES slice, used for inference which differs from images used in training that have a matched orbit with scatterometers.) It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size (128x128).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
datetime64
|
The time of the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
channels
|
str or list
|
The channel(s) of interest. Default is "C01". |
'C01'
|
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. Default is 'noaa-goes16/ABI-L2-CMIPF'. |
'noaa-goes16/ABI-L2-CMIPF'
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
list
|
A list of numpy arrays containing the extracted GOES images of shape (128, 128). |
Source code in windscangeo\func.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
extract_goes_production(time_choice, polar_data, parallel_index, channels, goes_aws_url_folder)
Extracts GOES data for a specific time from the polar data and returns the images along with valid latitudes, longitudes, and times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_choice
|
str
|
The time for which to extract GOES data, in 'YYYY-MM-DD HH:MM:SS' format. |
required |
polar_data
|
Dataset
|
Polar data containing latitude and longitude information. Used to create a grid of valid latitudes and longitudes. |
required |
parallel_index
|
int
|
Index for parallel processing, used to identify the specific GOES data to extract, generated by the |
required |
channels
|
list
|
List of GOES channels to extract. |
required |
goes_aws_url_folder
|
str
|
AWS URL folder for the GOES data, default is "noaa-goes16/ABI-L2-CMIPF". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
Array of extracted GOES images for the specified time. |
valid_lats |
ndarray
|
Array of valid latitudes corresponding to the GOES images |
valid_lons |
ndarray
|
Array of valid longitudes corresponding to the GOES images |
valid_times |
ndarray
|
Array of valid times corresponding to the GOES images. |
Source code in windscangeo\func_inference.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
extract_matching_orbits(scatterometer_data_path, date, lat_range=[-90, 90], lon_range=[-180, 180], goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF', goes_channel='C01', goes_image_size=128, verbose=True, save=True)
Extracts matching orbits from scatterometer data (pre-downloaded) and GOES images (automatically extracted) for a given date. The function filters the data to only include daylight observations and returns the images and numerical data in a dictionary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scatterometer_data_path
|
str
|
Path to the pre-downloaded scatterometer data. Data must be in .netCDF format. See tutorial for downloading data. |
required |
date
|
str
|
Date for which to extract the data in 'YYYY-MM-DD' format. |
required |
lat_range
|
tuple
|
Latitude range to filter the data, default is [-90,180] (all latitudes). |
[-90, 90]
|
lon_range
|
tuple
|
Longitude range to filter the data, default is [-180, 180] (all longitudes). |
[-180, 180]
|
goes_aws_url_folder
|
str
|
AWS URL folder for the GOES data, default is "noaa-goes16/ABI-L2-CMIPF". |
'noaa-goes16/ABI-L2-CMIPF'
|
goes_channel
|
str
|
GOES channel to extract, default is "C01" (visible). |
'C01'
|
goes_image_size
|
int
|
Size of the GOES images to extract, default is 128. |
128
|
verbose
|
bool
|
If True, prints additional information during the extraction process, default is True. |
True
|
save
|
bool
|
If True, saves the preloaded data to a compressed .npz file, default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
list
|
List of filtered GOES images. |
numerical_data |
dict
|
Dictionary containing filtered numerical data (latitudes, longitudes, times, wind speeds). |
saved_file_path |
str
|
Path to the saved .npz file if save is True, otherwise None. |
Source code in windscangeo\main_func.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
extract_scatter(polar_data, date, lat_range, lon_range, verbose=True, main_variable='wind_speed')
This function extracts the scatterometer data from the polar_data dataset for the given time range, latitude range and longitude range. The function then saves the data into 4 numpy files : time of observation, latitude, longitude and main variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polar_data
|
Dataset
|
The scatterometer dataset (ASCAT, HYSCAT etc). |
required |
date
|
datetime64
|
The time of the scatterometer data. |
required |
lat_range
|
tuple
|
The latitude range of the scatterometer data. |
required |
lon_range
|
tuple
|
The longitude range of the scatterometer data. |
required |
verbose
|
bool
|
If True, the function will print the progress of the extraction. |
True
|
main_variable
|
str
|
The main variable to be extracted from the scatterometer data. This can be wind speed, wind direction, classification etc. |
'wind_speed'
|
Returns:
| Name | Type | Description |
|---|---|---|
observation_times |
ndarray
|
The time of observation of the scatterometer data. |
observation_lats |
ndarray
|
The latitude of the scatterometer data. |
observation_lons |
ndarray
|
The longitude of the scatterometer data. |
observation_main_parameter |
ndarray
|
main parameter extracted (wind_speed). |
Source code in windscangeo\func.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
extract_scatter_multisat(scatterometer_data_path, date, lat_range, lon_range, verbose=True)
Extracts scatterometer data from multiple files (.nc) in a specified directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scatterometer_data_path
|
str
|
Path to the directory containing scatterometer data files. |
required |
date
|
datetime
|
Date for which to extract data. |
required |
lat_range
|
tuple
|
Latitude range (min, max) for filtering data. |
required |
lon_range
|
tuple
|
Longitude range (min, max) for filtering data. |
required |
verbose
|
bool
|
If True, prints progress information. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing: - list of datetime: observation times - list of float: latitudes - list of float: longitudes - list of float: wind speeds |
Source code in windscangeo\func_inference.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
fill_nans(images)
This function fills NaN values in the images with zeros. (This is simply np.nan_to_num)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array with NaN values replaced by zeros. |
Source code in windscangeo\func.py
808 809 810 811 812 813 814 815 816 817 818 819 820 | |
filter_invalid(images, numerical_data, min_nonzero_pixels=50)
This function filters out invalid images and corresponding numerical data based on two criteria: 1) The sum of pixel values in the image is not zero (i.e., the image is not completely empty). 2) The number of non-zero pixels in the image is greater than or equal to a specified minimum threshold (default is 50).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
numerical_data
|
dict
|
A dictionary containing numerical data associated with the images. The keys should match the dimensions of the images. |
required |
min_nonzero_pixels
|
int
|
The minimum number of non-zero pixels required for an image to be considered valid. Default is 50. |
50
|
Returns:
| Name | Type | Description |
|---|---|---|
filtered_images |
ndarray
|
A 4D numpy array of shape (num_valid_images, num_channels, height, width) containing the filtered GOES images. |
filtered_numerical_data |
dict
|
A dictionary containing the numerical data associated with the valid images. |
Source code in windscangeo\func.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
filter_nighttime(observation_times, observation_lats, observation_lons, observation_wind_speeds, min_hour=10, max_hour=19, verbose=True)
This function filters the scatterometer data to only include observations that were made during daylight hours. The function checks the hour of each observation time and only keeps those that fall within the specified range (default is 10 to 19, which corresponds to 10 AM to 7 PM UTC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
observation_wind_speeds
|
ndarray
|
The wind speeds of the scatterometer data. |
required |
min_hour
|
int
|
The minimum hour of the day to include (default is 10). |
10
|
max_hour
|
int
|
The maximum hour of the day to include (default is 19). |
19
|
verbose
|
bool
|
If True, prints the number of valid scatterometer data points at daylight. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
valid_times |
list
|
A list of valid observation times that fall within the specified hour range. |
valid_lats |
list
|
A list of valid latitudes corresponding to the valid observation times |
valid_lons |
list
|
A list of valid longitudes corresponding to the valid observation times. |
valid_wind_speeds |
list
|
A list of valid wind speeds corresponding to the valid observation times. |
Source code in windscangeo\func.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
form_arrays_buoy(buoy, date_choice)
Form arrays from buoy data for a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buoy
|
Dataset
|
Buoy data containing time, latitude, longitude, and wind speed. |
required |
date_choice
|
str
|
Date for which to extract buoy data, in 'YYYY-MM |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat |
ndarray
|
Array of buoy latitudes. |
lon |
ndarray
|
Array of buoy longitudes. |
time |
ndarray
|
Array of buoy observation times in nanoseconds since epoch. |
wind_speed |
ndarray
|
Array of buoy wind speeds. |
buoy_name |
ndarray
|
Array of buoy names. |
Source code in windscangeo\func_inference.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
get_goes_url(time, goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF', goes_channel='C01')
This function gets the nearest GOES-16 files from the time given. The function returns a list of urls to the files. The function uses the s3fs library to access the AWS GOES-16 data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime[ns]
|
The time of the scatterometer data. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES-16 data is stored. |
'noaa-goes16/ABI-L2-CMIPF'
|
goes_channel
|
list
|
The channel of interest. |
'C01'
|
Returns:
| Name | Type | Description |
|---|---|---|
urls |
list
|
A list of urls to the GOES-16 files. |
Source code in windscangeo\func.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
get_image(ds, parallel_index, lat_grd, lon_grd, lat_search, lon_search, goes_image_size=128)
This function retrieves a trainable GOES image for a given latitude and longitude from a GOES16 .nc file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The xarray dataset containing the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
goes_image_size
|
int
|
The size of the output image. Default is 128. |
128
|
Returns:
| Name | Type | Description |
|---|---|---|
padded_image |
DataArray
|
A padded xarray DataArray containing the GOES image centered around the specified lat/lon. |
Source code in windscangeo\func.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
get_indices(lat_grid, lon_grid, Goeslat, Goeslon, radius=0.125)
Finds the corresponding GOES row and column indices for each scatterometer point using a BallTree for efficiency, and then filtering points to form a square bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_grid
|
ndarray
|
2D array of latitudes from the scatterometer data. |
required |
lon_grid
|
ndarray
|
2D array of longitudes from the scatterometer data. |
required |
Goeslat
|
ndarray
|
2D array of latitudes from the GOES data. |
required |
Goeslon
|
ndarray
|
2D array of longitudes from the GOES data. |
required |
radius
|
float
|
Radius in degrees to define the bounding box around each scatterometer point. |
0.125
|
Returns: indices_array (numpy.ndarray): 2D array of tuples, where each tuple contains the row and column indices of the corresponding GOES pixel for each scatterometer point.
Source code in windscangeo\func.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
get_mlp(in_features, hidden_units, out_features)
Returns a MLP head
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
173 174 175 176 177 178 179 180 181 182 183 184 185 | |
goes_index(parallel_index, lat_grd, lon_grd, lat_search, lon_search)
This function retrieves the indices of the GOES image corresponding to a given latitude and longitude. This is an archived function. Current implementation decides on extent based on chosen image size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
min_row |
int
|
The minimum row index of the GOES image. |
max_row |
int
|
The maximum row index of the GOES image. |
min_col |
int
|
The minimum column index of the GOES image. |
max_col |
int
|
The maximum column index of the GOES image. |
Source code in windscangeo\func.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
index_parallel(ds, ScatterDataset)
Finds the corresponding GOES row and column indices for the entire scatterometer dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterDataset
|
xarray Dataset containing scatterometer data. |
required | |
scatter_name
|
Name for the output file. |
required | |
output_path
|
Path to save the output file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
parallel_indice_values |
2D array of tuples containing GOES row and column indices corresponding to scatterometer data. |
Source code in windscangeo\func.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
inference_full_goes_image(datetime, scatterometer_data_path, result_path_folder, model_parameters, buoy_path, normalization_factors, goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF', goes_channel='C01')
Runs the inference on a full GOES image for a given datetime using the pre-trained model from the function train_test_model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datetime
|
str
|
Date and time in 'YYYY-MM-DD HH:MM:SS' |
required |
scatterometer_data_path
|
str
|
Path to the pre-downloaded scatterometer data. Must be the same used in for extracting the matching orbits. |
required |
result_path_folder
|
str
|
Path to the folder where the results of the model training are |
required |
model_parameters
|
dict
|
Dictionary containing model parameters such as batch size, image size, learning rate, etc. Must be identical as those used in |
required |
buoy_path
|
str
|
Path to the buoy data folder. Must be a folder containing the buoy data in |
required |
normalization_factors
|
dict
|
Dictionary containing normalization factors (mean and std) for the images dataset. |
required |
goes_aws_url_folder
|
str
|
AWS URL folder for the GOES data, default is "noaa-goes16/ABI-L2-CMIPF". Must be the same as used in the matching orbits extraction. |
'noaa-goes16/ABI-L2-CMIPF'
|
goes_channel
|
str
|
GOES channel to extract, default is "C01" (visible). |
'C01'
|
Returns:
| Type | Description |
|---|---|
|
None, but saves the inference results in a folder named |
Source code in windscangeo\main_func.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
inference_model(model, inference_loader, device)
Perform inference on the model using the provided DataLoader and return the outputs. Same as train_model but for a fixed given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be used for inference. |
required |
inference_loader
|
DataLoader
|
DataLoader for the inference dataset. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inference_outputs |
ndarray
|
Outputs from the model on the inference dataset. |
Source code in windscangeo\impl.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
inference_run(images, model_parameters, model_path, normalization_factors)
Runs inference on the provided images using the specified model parameters and normalization factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
Array of images to be used for inference. |
required |
model_parameters
|
dict
|
Dictionary containing model parameters such as batch size, image size, channels |
required |
model_path
|
str
|
Path to the pre-trained model file. |
required |
normalization_factors
|
dict
|
Dictionary containing normalization factors such as mean and standard deviation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inference_output |
ndarray
|
Array of inference outputs (wind speeds). |
Source code in windscangeo\func_inference.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
manage_saved_models(directory)
Manage saved model files in the specified directory by deleting older epoch files. Keeps only the latest epoch file and deletes all others. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
The directory where model files are saved. |
required |
Source code in windscangeo\impl.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
package_data(images, numerical_data, filter=True, solar_conversion=False, verbose=True)
This function packages the images and numerical data into a format that can be used for training a machine learning model. The function will filter out invalid images and fill in any NaN values. (Invalid images = empty images from GOES data) The function will also convert the observation times, latitudes and longitudes to solar angles (sza, saa) if solar_conversion is set to True. The function will return the images and numerical data in a numpy array format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
The GOES images corresponding to the observation data. |
required |
numerical_data
|
dict
|
A dictionary containing the numerical data corresponding to the observation data. The keys should include "observation_lats", "observation_lons", "observation_times" and optionally "wind_speeds". |
required |
filter
|
bool
|
If True, the function will filter out invalid images and fill in Nan values. Default is True. |
True
|
solar_conversion
|
bool
|
If True, the function will convert the observation times, latitudes and longitudes to solar angles (sza, saa). Default is False. (Not used in current implementation, but kept in case of future use) |
False
|
verbose
|
bool
|
If True, the function will print progress information. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
The GOES images corresponding to the observation data. |
numerical_data |
ndarray
|
The numerical data corresponding to the observation data. (sza, saa, main_parameter if solar_conversion is set to True or lat, lon, time, wind_speeds if solar_conversion is set to False) |
Source code in windscangeo\func.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
patchify(batch, patch_size)
Patchify the batch of images
Shape
batch: (b, h, w, c) output: (b, nh, nw, ph, pw, c)
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
plot_cloud_cover(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud cover mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be used for cloud cover calculation. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
plot_cloud_mask(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Cloud mask data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
plot_goes_image(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the GOES image data on a map with buoy locations. Made for 128x128 images where the middpoint is at (64,64). If using other image sizes, the plotting will probably not work as expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
plot_save_loss(best_val_outputs, best_val_labels, train_losses, val_losses, path_folder, saving=False)
Plot and save the training and validation losses, and optionally save the best validation outputs and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
train_losses
|
list
|
List of training losses per epoch. |
required |
val_losses
|
list
|
List of validation losses per epoch. |
required |
path_folder
|
str
|
Path to save the plot and optionally the outputs and labels. |
required |
saving
|
bool
|
If True, save the best validation outputs and labels. Default is False. |
False
|
Source code in windscangeo\func_ml.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
plot_wind_speeds(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the wind speeds on a map with buoy locations. Filter nighttime images and add coastlines, gridlines, and buoy locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Wind speed data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
rmse_per_range(model_output, target, path_folder)
Calculate the RMSE for different ranges of wind speeds and save the results to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
target
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the CSV file. |
required |
Returns: pd.DataFrame: DataFrame containing the RMSE and count for each range.
Source code in windscangeo\func_ml.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
save_overpass_time(time_list, name_scatter)
This function prints the overpass time of the scatterometer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
name_scatter
|
str
|
The name of the scatterometer data source (e.g. ASCAT, HYSCAT etc). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in windscangeo\func.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
savedataseperated(ScatterData, main_parameter, verbose=True)
This function extracts the valid lon / lat / measurement time and the main parameter from ever pixel of the scatterometer data and saves it to a numpy file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterData
|
Dataset
|
The ASCAT dataset containing the scatterometer data. |
required |
main_parameter
|
DataArray
|
The main parameter to be saved. This can be a classification / wind speed / wind direction etc. |
required |
Returns:
lat_list (numpy.ndarray): The latitude values of the scatterometer data.
lon_list (numpy.ndarray): The longitude values of the scatterometer data.
time_list (numpy.ndarray): The measurement time values of the scatterometer data.
main_parameter_list (numpy.ndarray): The main parameter values of the scatterometer data.
this function saves the data locally to a folder called data_processed_scat
Source code in windscangeo\func.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
snap_to_nearest(values, reference_array, cutoff=1.0)
Snap an array of values to the nearest values in a reference array. If the difference is greater than the cutoff, the original value is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Array of values to snap. |
required |
reference_array
|
ndarray
|
Array of reference values. |
required |
cutoff
|
float
|
Maximum allowable difference for snapping. |
1.0
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Snapped values. |
Source code in windscangeo\func_inference.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
sort_by_time(lat_list, lon_list, time_list, wind_speed_list)
This function sorts the output of savedataseperated() by time. This allows for more efficient data processing and allows file caching for times that are represented by the same GOES file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_list
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon_list
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
wind_speed_list
|
ndarray
|
The wind speed values of the scatterometer data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat_list_sorted |
ndarray
|
The sorted latitude values of the scatterometer data. |
lon_list_sorted |
ndarray
|
The sorted longitude values of the scatterometer data. |
time_list_sorted |
ndarray
|
The sorted measurement time values of the scatterometer data. |
wind_speed_list_sorted |
ndarray
|
The sorted wind speed values of the scatterometer data. |
Source code in windscangeo\func.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
test_model(model, test_loader, criterion, device)
Evaluate the model on the test dataset and return the outputs, targets, and average loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be evaluated. |
required |
test_loader
|
DataLoader
|
DataLoader for the test dataset. |
required |
criterion
|
Module
|
Loss function to be used for evaluation. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
test_outputs |
ndarray
|
Outputs from the model on the test dataset. |
test_targets |
ndarray
|
Targets corresponding to the test outputs. |
avg_test_loss |
float
|
Average loss on the test dataset. |
Source code in windscangeo\impl.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
train_model(model, train_loader, val_loader, num_epochs, lr, weight_decay, criterion, device, optimizer_choice, patience_epochs, patience_loss, path_folder)
Train the model with the given parameters dictionary and save the best validation outputs, labels, and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to be trained. |
required |
train_loader
|
DataLoader
|
DataLoader for the training dataset. |
required |
val_loader
|
DataLoader
|
DataLoader for the validation dataset. |
required |
num_epochs
|
int
|
Number of epochs to train the model. |
required |
lr
|
float
|
Learning rate for the optimizer. |
required |
weight_decay
|
float
|
Weight decay for the optimizer. |
required |
criterion
|
Module
|
Loss function to be used. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
optimizer_choice
|
str
|
Choice of optimizer ('Adam', 'SGD', 'RMSprop'). |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement in validation loss. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
path_folder
|
str
|
Path to save the model checkpoints. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
best_val_outputs |
ndarray
|
Best validation outputs from the model. |
best_val_labels |
ndarray
|
Best validation labels corresponding to the outputs. |
best_model |
Module
|
The best model based on validation loss. |
train_losses |
list
|
List of training losses for each epoch. |
val_losses |
list
|
List of validation losses for each epoch. |
Source code in windscangeo\impl.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
train_test_model(saved_file_path, run_name, model_parameters, normalization_factors)
Trains and tests a model using the provided parameters and data from a saved file (from extract_matching_orbits).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saved_file_path
|
str
|
Path to the saved .npz file containing preloaded data. |
required |
run_name
|
str
|
Name of the run, used to create a folder for saving results. |
required |
model_parameters
|
dict
|
Dictionary containing model parameters such as batch size, image size, learning rate, etc (Supports CNN, ResNet, ViT). See tutorial for details. |
required |
normalization_factors
|
dict
|
Dictionary containing normalization factors (mean and std) for the images dataset. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result_path_folder |
str
|
Path to the folder where results are saved. |
model_parameters should contain the following (dictionary, values can be changed as needed):
"batch_size" : 256,
"image_size": 128,
"image_channels" : 1,
"model_choice" : "ResNet", # or "CNN" or"ViT"
"criterion" : nn.MSELoss(), # or any other PyTorch loss function
"optimizer_choice" : "Adam",
"learning_rate" : 0.003305753102490767,
"weight_decay" : 0.00000148842072509874,
"dropout_rate" : 0.2752124679248082,
"num_epochs" : 10,
"patience_epochs" : 20, # early stopping
"patience_loss" : 0.001,
# The following additional parameters are required with the CNN :
"activation_cnn" : nn.ReLU(),
"activation_final" : nn.Identity(),
"kernel_size" : 3,
"features_cnn" : [64,64,64,64],
"stride" : 1,
normalization_factors should contain the following (dictionary, values can be changed as needed): "mean" : 0.0, # mean of the images dataset "std" : 1.0, # std of the images dataset
Source code in windscangeo\main_func.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
vectorized_solar_angles(lat, lon, time_utc)
This function calculates the solar zenith angle (SZA) and solar azimuth angle (SAA) for a given latitude, longitude, and time. This is an archived function. Current implementation does not use solar angles but only image input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_utc
|
ndarray
|
The observation times in UTC. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sza |
ndarray
|
The solar zenith angle in degrees. |
saa |
ndarray
|
The solar azimuth angle in degrees. |
Source code in windscangeo\func_ml.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
calculate_degrees(file_id)
This function calculates the latitude and longitude of the GOES ABI fixed grid projection. This function comes from NOAA/NESDIS/STAR. (2025). Latitude and longitude remapping of GOES-R ABI imagery using Python . Atmospheric Composition Science Team. Retrieved from https://www.star.nesdis.noaa.gov/atmospheric-composition-training/python_abi_lat_lon.php
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
Dataset
|
The xarray dataset containing the GOES ABI fixed grid projection variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
abi_lat |
ndarray
|
The latitude of the GOES ABI fixed grid projection. |
abi_lon |
ndarray
|
The longitude of the GOES ABI fixed grid projection. |
Source code in windscangeo\func.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
create_folder(experiment_name)
Create a folder for saving results based on the experiment name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name
|
str
|
Name of the experiment to create a folder for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the created folder. |
Source code in windscangeo\func.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
extract_goes(observation_times, observation_lats, observation_lons, scatterometer_data_path, goes_aws_url_folder, goes_channel='C01', goes_image_size=128, verbose=True)
This function extracts GOES images for the given observation times, latitudes, and longitudes. It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
scatterometer_data_path
|
str
|
The path to the scatterometer data directory. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. |
required |
goes_channel
|
str
|
The channel of interest. Default is "C01". |
'C01'
|
goes_image_size
|
int
|
The size of the output images. Default is 128. |
128
|
verbose
|
bool
|
If True, prints progress information. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array of shape (num_observations, num_channels, goes_image_size, goes_image_size) containing the extracted GOES images. |
Source code in windscangeo\func.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
extract_goes_inference(date_time, parallel_index, channels='C01', goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF')
This function extracts GOES images for a given date_time and parallel_index. (whole GOES slice, used for inference which differs from images used in training that have a matched orbit with scatterometers.) It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size (128x128).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
datetime64
|
The time of the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
channels
|
str or list
|
The channel(s) of interest. Default is "C01". |
'C01'
|
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. Default is 'noaa-goes16/ABI-L2-CMIPF'. |
'noaa-goes16/ABI-L2-CMIPF'
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
list
|
A list of numpy arrays containing the extracted GOES images of shape (128, 128). |
Source code in windscangeo\func.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
extract_scatter(polar_data, date, lat_range, lon_range, verbose=True, main_variable='wind_speed')
This function extracts the scatterometer data from the polar_data dataset for the given time range, latitude range and longitude range. The function then saves the data into 4 numpy files : time of observation, latitude, longitude and main variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polar_data
|
Dataset
|
The scatterometer dataset (ASCAT, HYSCAT etc). |
required |
date
|
datetime64
|
The time of the scatterometer data. |
required |
lat_range
|
tuple
|
The latitude range of the scatterometer data. |
required |
lon_range
|
tuple
|
The longitude range of the scatterometer data. |
required |
verbose
|
bool
|
If True, the function will print the progress of the extraction. |
True
|
main_variable
|
str
|
The main variable to be extracted from the scatterometer data. This can be wind speed, wind direction, classification etc. |
'wind_speed'
|
Returns:
| Name | Type | Description |
|---|---|---|
observation_times |
ndarray
|
The time of observation of the scatterometer data. |
observation_lats |
ndarray
|
The latitude of the scatterometer data. |
observation_lons |
ndarray
|
The longitude of the scatterometer data. |
observation_main_parameter |
ndarray
|
main parameter extracted (wind_speed). |
Source code in windscangeo\func.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
fill_nans(images)
This function fills NaN values in the images with zeros. (This is simply np.nan_to_num)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array with NaN values replaced by zeros. |
Source code in windscangeo\func.py
808 809 810 811 812 813 814 815 816 817 818 819 820 | |
filter_invalid(images, numerical_data, min_nonzero_pixels=50)
This function filters out invalid images and corresponding numerical data based on two criteria: 1) The sum of pixel values in the image is not zero (i.e., the image is not completely empty). 2) The number of non-zero pixels in the image is greater than or equal to a specified minimum threshold (default is 50).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
numerical_data
|
dict
|
A dictionary containing numerical data associated with the images. The keys should match the dimensions of the images. |
required |
min_nonzero_pixels
|
int
|
The minimum number of non-zero pixels required for an image to be considered valid. Default is 50. |
50
|
Returns:
| Name | Type | Description |
|---|---|---|
filtered_images |
ndarray
|
A 4D numpy array of shape (num_valid_images, num_channels, height, width) containing the filtered GOES images. |
filtered_numerical_data |
dict
|
A dictionary containing the numerical data associated with the valid images. |
Source code in windscangeo\func.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
filter_nighttime(observation_times, observation_lats, observation_lons, observation_wind_speeds, min_hour=10, max_hour=19, verbose=True)
This function filters the scatterometer data to only include observations that were made during daylight hours. The function checks the hour of each observation time and only keeps those that fall within the specified range (default is 10 to 19, which corresponds to 10 AM to 7 PM UTC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
observation_wind_speeds
|
ndarray
|
The wind speeds of the scatterometer data. |
required |
min_hour
|
int
|
The minimum hour of the day to include (default is 10). |
10
|
max_hour
|
int
|
The maximum hour of the day to include (default is 19). |
19
|
verbose
|
bool
|
If True, prints the number of valid scatterometer data points at daylight. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
valid_times |
list
|
A list of valid observation times that fall within the specified hour range. |
valid_lats |
list
|
A list of valid latitudes corresponding to the valid observation times |
valid_lons |
list
|
A list of valid longitudes corresponding to the valid observation times. |
valid_wind_speeds |
list
|
A list of valid wind speeds corresponding to the valid observation times. |
Source code in windscangeo\func.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
get_goes_url(time, goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF', goes_channel='C01')
This function gets the nearest GOES-16 files from the time given. The function returns a list of urls to the files. The function uses the s3fs library to access the AWS GOES-16 data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime[ns]
|
The time of the scatterometer data. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES-16 data is stored. |
'noaa-goes16/ABI-L2-CMIPF'
|
goes_channel
|
list
|
The channel of interest. |
'C01'
|
Returns:
| Name | Type | Description |
|---|---|---|
urls |
list
|
A list of urls to the GOES-16 files. |
Source code in windscangeo\func.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
get_image(ds, parallel_index, lat_grd, lon_grd, lat_search, lon_search, goes_image_size=128)
This function retrieves a trainable GOES image for a given latitude and longitude from a GOES16 .nc file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The xarray dataset containing the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
goes_image_size
|
int
|
The size of the output image. Default is 128. |
128
|
Returns:
| Name | Type | Description |
|---|---|---|
padded_image |
DataArray
|
A padded xarray DataArray containing the GOES image centered around the specified lat/lon. |
Source code in windscangeo\func.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
get_indices(lat_grid, lon_grid, Goeslat, Goeslon, radius=0.125)
Finds the corresponding GOES row and column indices for each scatterometer point using a BallTree for efficiency, and then filtering points to form a square bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_grid
|
ndarray
|
2D array of latitudes from the scatterometer data. |
required |
lon_grid
|
ndarray
|
2D array of longitudes from the scatterometer data. |
required |
Goeslat
|
ndarray
|
2D array of latitudes from the GOES data. |
required |
Goeslon
|
ndarray
|
2D array of longitudes from the GOES data. |
required |
radius
|
float
|
Radius in degrees to define the bounding box around each scatterometer point. |
0.125
|
Returns: indices_array (numpy.ndarray): 2D array of tuples, where each tuple contains the row and column indices of the corresponding GOES pixel for each scatterometer point.
Source code in windscangeo\func.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
goes_index(parallel_index, lat_grd, lon_grd, lat_search, lon_search)
This function retrieves the indices of the GOES image corresponding to a given latitude and longitude. This is an archived function. Current implementation decides on extent based on chosen image size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
min_row |
int
|
The minimum row index of the GOES image. |
max_row |
int
|
The maximum row index of the GOES image. |
min_col |
int
|
The minimum column index of the GOES image. |
max_col |
int
|
The maximum column index of the GOES image. |
Source code in windscangeo\func.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
index_parallel(ds, ScatterDataset)
Finds the corresponding GOES row and column indices for the entire scatterometer dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterDataset
|
xarray Dataset containing scatterometer data. |
required | |
scatter_name
|
Name for the output file. |
required | |
output_path
|
Path to save the output file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
parallel_indice_values |
2D array of tuples containing GOES row and column indices corresponding to scatterometer data. |
Source code in windscangeo\func.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
package_data(images, numerical_data, filter=True, solar_conversion=False, verbose=True)
This function packages the images and numerical data into a format that can be used for training a machine learning model. The function will filter out invalid images and fill in any NaN values. (Invalid images = empty images from GOES data) The function will also convert the observation times, latitudes and longitudes to solar angles (sza, saa) if solar_conversion is set to True. The function will return the images and numerical data in a numpy array format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
The GOES images corresponding to the observation data. |
required |
numerical_data
|
dict
|
A dictionary containing the numerical data corresponding to the observation data. The keys should include "observation_lats", "observation_lons", "observation_times" and optionally "wind_speeds". |
required |
filter
|
bool
|
If True, the function will filter out invalid images and fill in Nan values. Default is True. |
True
|
solar_conversion
|
bool
|
If True, the function will convert the observation times, latitudes and longitudes to solar angles (sza, saa). Default is False. (Not used in current implementation, but kept in case of future use) |
False
|
verbose
|
bool
|
If True, the function will print progress information. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
The GOES images corresponding to the observation data. |
numerical_data |
ndarray
|
The numerical data corresponding to the observation data. (sza, saa, main_parameter if solar_conversion is set to True or lat, lon, time, wind_speeds if solar_conversion is set to False) |
Source code in windscangeo\func.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
save_overpass_time(time_list, name_scatter)
This function prints the overpass time of the scatterometer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
name_scatter
|
str
|
The name of the scatterometer data source (e.g. ASCAT, HYSCAT etc). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in windscangeo\func.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
savedataseperated(ScatterData, main_parameter, verbose=True)
This function extracts the valid lon / lat / measurement time and the main parameter from ever pixel of the scatterometer data and saves it to a numpy file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterData
|
Dataset
|
The ASCAT dataset containing the scatterometer data. |
required |
main_parameter
|
DataArray
|
The main parameter to be saved. This can be a classification / wind speed / wind direction etc. |
required |
Returns:
lat_list (numpy.ndarray): The latitude values of the scatterometer data.
lon_list (numpy.ndarray): The longitude values of the scatterometer data.
time_list (numpy.ndarray): The measurement time values of the scatterometer data.
main_parameter_list (numpy.ndarray): The main parameter values of the scatterometer data.
this function saves the data locally to a folder called data_processed_scat
Source code in windscangeo\func.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
sort_by_time(lat_list, lon_list, time_list, wind_speed_list)
This function sorts the output of savedataseperated() by time. This allows for more efficient data processing and allows file caching for times that are represented by the same GOES file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_list
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon_list
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
wind_speed_list
|
ndarray
|
The wind speed values of the scatterometer data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat_list_sorted |
ndarray
|
The sorted latitude values of the scatterometer data. |
lon_list_sorted |
ndarray
|
The sorted longitude values of the scatterometer data. |
time_list_sorted |
ndarray
|
The sorted measurement time values of the scatterometer data. |
wind_speed_list_sorted |
ndarray
|
The sorted wind speed values of the scatterometer data. |
Source code in windscangeo\func.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
vectorized_solar_angles(lat, lon, time_utc)
This function calculates the solar zenith angle (SZA) and solar azimuth angle (SAA) for a given latitude, longitude, and time. This is an archived function. Current implementation does not use solar angles but only image input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_utc
|
ndarray
|
The observation times in UTC. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sza |
ndarray
|
The solar zenith angle in degrees. |
saa |
ndarray
|
The solar azimuth angle in degrees. |
Source code in windscangeo\func.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
H5pyDataset
Bases: Dataset
A PyTorch Dataset for loading data from an HDF5 file. This is useful when dealing with large datasets that do not fit into memory. Need to work on Zarr integration for better performance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h5_file_path
|
str
|
Path to the HDF5 file. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Normalize
Normalize the input tensor by subtracting the mean and dividing by the standard deviation. Done per batch
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
list or ndarray
|
Mean values for normalization. |
required |
std
|
list or ndarray
|
Standard deviation values for normalization. |
required |
Source code in windscangeo\func_ml.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
conventional_dataset
Bases: Dataset
A PyTorch Dataset for loading data using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images. |
required |
targets
|
list or ndarray
|
List or array of targets corresponding to the images. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
conventional_dataset_inference
Bases: Dataset
A PyTorch Dataset for loading data for inference (no lable) using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images to be used for inference. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
error_plot(best_val_outputs, best_val_labels, path_folder=None)
Plot a scatter plot of model outputs vs true labels for the validation dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the plot. If None, the plot will not be saved. |
None
|
Source code in windscangeo\func_ml.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
plot_cloud_cover(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud cover mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be used for cloud cover calculation. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
plot_cloud_mask(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Cloud mask data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
plot_goes_image(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the GOES image data on a map with buoy locations. Made for 128x128 images where the middpoint is at (64,64). If using other image sizes, the plotting will probably not work as expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
plot_save_loss(best_val_outputs, best_val_labels, train_losses, val_losses, path_folder, saving=False)
Plot and save the training and validation losses, and optionally save the best validation outputs and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
train_losses
|
list
|
List of training losses per epoch. |
required |
val_losses
|
list
|
List of validation losses per epoch. |
required |
path_folder
|
str
|
Path to save the plot and optionally the outputs and labels. |
required |
saving
|
bool
|
If True, save the best validation outputs and labels. Default is False. |
False
|
Source code in windscangeo\func_ml.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
plot_wind_speeds(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the wind speeds on a map with buoy locations. Filter nighttime images and add coastlines, gridlines, and buoy locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Wind speed data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
rmse_per_range(model_output, target, path_folder)
Calculate the RMSE for different ranges of wind speeds and save the results to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
target
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the CSV file. |
required |
Returns: pd.DataFrame: DataFrame containing the RMSE and count for each range.
Source code in windscangeo\func_ml.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
vectorized_solar_angles(lat, lon, time_utc)
This function calculates the solar zenith angle (SZA) and solar azimuth angle (SAA) for a given latitude, longitude, and time. This is an archived function. Current implementation does not use solar angles but only image input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_utc
|
ndarray
|
The observation times in UTC. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sza |
ndarray
|
The solar zenith angle in degrees. |
saa |
ndarray
|
The solar azimuth angle in degrees. |
Source code in windscangeo\func_ml.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Block
Bases: Module
A basic block for ResNet architecture. This block consists of two convolutional layers with batch normalization and ReLU activation. The first layer applies a 3x3 convolution, and the second layer applies another 3x3 convolution. The block also supports downsampling through an optional identity downsample layer. The expansion factor is set to 1, meaning the output channels are the same as the input channels.
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py
Source code in windscangeo\Models.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
Bottleneck
Bases: Module
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py A bottleneck block for ResNet architecture. This block consists of three convolutional layers with batch normalization and ReLU activation. The first layer reduces the number of channels, the second layer applies a 3x3 convolution, and the third layer expands the number of channels back to the original size. The block also supports downsampling through an optional identity downsample layer.
Source code in windscangeo\Models.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
ConventionalCNN
Bases: Module
A simple CNN for image regression tasks. This model consists of a series of convolutional layers followed by fully connected layers. It is designed to process images and output a single regression value (e.g., wind speed).
Source code in windscangeo\Models.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
H5pyDataset
Bases: Dataset
A PyTorch Dataset for loading data from an HDF5 file. This is useful when dealing with large datasets that do not fit into memory. Need to work on Zarr integration for better performance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h5_file_path
|
str
|
Path to the HDF5 file. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Img2Seq
Bases: Module
This layers takes a batch of images as input and returns a batch of sequences
Shape
input: (b, h, w, c) output: (b, s, d)
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
Normalize
Normalize the input tensor by subtracting the mean and dividing by the standard deviation. Done per batch
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
list or ndarray
|
Mean values for normalization. |
required |
std
|
list or ndarray
|
Standard deviation values for normalization. |
required |
Source code in windscangeo\func_ml.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
ResNet
Bases: Module
A ResNet model for image classification or regression tasks.
This model consists of an initial convolutional layer, followed by a series
of residual blocks, and a fully connected layer for classification or regression.
The number of residual blocks in each layer is specified by the layer_list parameter.
taken from https://github.com/JayPatwardhan/ResNet-PyTorch/blob/master/ResNet/ResNet.py
Source code in windscangeo\Models.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
ViT
Bases: Module
Vision Transformer (ViT) model for image classification or regression tasks. This model consists of an image-to-sequence layer, a transformer encoder, and a multi-layer perceptron (MLP) head for classification or regression.
Taken from # https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
conventional_dataset
Bases: Dataset
A PyTorch Dataset for loading data using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images. |
required |
targets
|
list or ndarray
|
List or array of targets corresponding to the images. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
conventional_dataset_inference
Bases: Dataset
A PyTorch Dataset for loading data for inference (no lable) using regular numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list or ndarray
|
List or array of images to be used for inference. |
required |
transform
|
callable
|
A function/transform to apply to the images. |
None
|
Source code in windscangeo\func_ml.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
buoy_data_extract(folder_path, polar_data, date)
Extracts buoy data from a specified folder and returns arrays of latitude, longitude, time, wind speed, and buoy names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_path
|
str
|
Path to the folder containing buoy data files. |
required |
polar_data
|
Dataset
|
Polar data containing latitude and longitude information. Used to snap buoy data to the nearest polar grid points. |
required |
date
|
str
|
Date for which to extract buoy data, in 'YYYY-MM-DD' format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
buoy_lat |
ndarray
|
Array of buoy latitudes snapped to the nearest polar grid points. |
buoy_lon |
ndarray
|
Array of buoy longitudes snapped to the nearest polar grid points |
buoy_time |
ndarray
|
Array of buoy observation times. |
buoy_wind_speed |
ndarray
|
Array of buoy wind speeds. |
buoy_name |
ndarray
|
Array of buoy names. |
Source code in windscangeo\func_inference.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
calculate_degrees(file_id)
This function calculates the latitude and longitude of the GOES ABI fixed grid projection. This function comes from NOAA/NESDIS/STAR. (2025). Latitude and longitude remapping of GOES-R ABI imagery using Python . Atmospheric Composition Science Team. Retrieved from https://www.star.nesdis.noaa.gov/atmospheric-composition-training/python_abi_lat_lon.php
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
Dataset
|
The xarray dataset containing the GOES ABI fixed grid projection variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
abi_lat |
ndarray
|
The latitude of the GOES ABI fixed grid projection. |
abi_lon |
ndarray
|
The longitude of the GOES ABI fixed grid projection. |
Source code in windscangeo\func.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
create_folder(experiment_name)
Create a folder for saving results based on the experiment name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name
|
str
|
Name of the experiment to create a folder for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the created folder. |
Source code in windscangeo\func.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
early_stopping(valid_losses, patience_epochs, patience_loss)
Early stopping function to determine if training should stop based on validation losses. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid_losses
|
list
|
List of validation losses recorded during training. |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if training should stop, False otherwise. |
Source code in windscangeo\impl.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
error_plot(best_val_outputs, best_val_labels, path_folder=None)
Plot a scatter plot of model outputs vs true labels for the validation dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the plot. If None, the plot will not be saved. |
None
|
Source code in windscangeo\func_ml.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
extract_goes(observation_times, observation_lats, observation_lons, scatterometer_data_path, goes_aws_url_folder, goes_channel='C01', goes_image_size=128, verbose=True)
This function extracts GOES images for the given observation times, latitudes, and longitudes. It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
scatterometer_data_path
|
str
|
The path to the scatterometer data directory. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. |
required |
goes_channel
|
str
|
The channel of interest. Default is "C01". |
'C01'
|
goes_image_size
|
int
|
The size of the output images. Default is 128. |
128
|
verbose
|
bool
|
If True, prints progress information. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array of shape (num_observations, num_channels, goes_image_size, goes_image_size) containing the extracted GOES images. |
Source code in windscangeo\func.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
extract_goes_inference(date_time, parallel_index, channels='C01', goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF')
This function extracts GOES images for a given date_time and parallel_index. (whole GOES slice, used for inference which differs from images used in training that have a matched orbit with scatterometers.) It retrieves the GOES data from the specified AWS S3 bucket and processes it to create images of the specified size (128x128).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
datetime64
|
The time of the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
channels
|
str or list
|
The channel(s) of interest. Default is "C01". |
'C01'
|
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES data is stored. Default is 'noaa-goes16/ABI-L2-CMIPF'. |
'noaa-goes16/ABI-L2-CMIPF'
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
list
|
A list of numpy arrays containing the extracted GOES images of shape (128, 128). |
Source code in windscangeo\func.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
extract_goes_production(time_choice, polar_data, parallel_index, channels, goes_aws_url_folder)
Extracts GOES data for a specific time from the polar data and returns the images along with valid latitudes, longitudes, and times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_choice
|
str
|
The time for which to extract GOES data, in 'YYYY-MM-DD HH:MM:SS' format. |
required |
polar_data
|
Dataset
|
Polar data containing latitude and longitude information. Used to create a grid of valid latitudes and longitudes. |
required |
parallel_index
|
int
|
Index for parallel processing, used to identify the specific GOES data to extract, generated by the |
required |
channels
|
list
|
List of GOES channels to extract. |
required |
goes_aws_url_folder
|
str
|
AWS URL folder for the GOES data, default is "noaa-goes16/ABI-L2-CMIPF". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
Array of extracted GOES images for the specified time. |
valid_lats |
ndarray
|
Array of valid latitudes corresponding to the GOES images |
valid_lons |
ndarray
|
Array of valid longitudes corresponding to the GOES images |
valid_times |
ndarray
|
Array of valid times corresponding to the GOES images. |
Source code in windscangeo\func_inference.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
extract_scatter(polar_data, date, lat_range, lon_range, verbose=True, main_variable='wind_speed')
This function extracts the scatterometer data from the polar_data dataset for the given time range, latitude range and longitude range. The function then saves the data into 4 numpy files : time of observation, latitude, longitude and main variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polar_data
|
Dataset
|
The scatterometer dataset (ASCAT, HYSCAT etc). |
required |
date
|
datetime64
|
The time of the scatterometer data. |
required |
lat_range
|
tuple
|
The latitude range of the scatterometer data. |
required |
lon_range
|
tuple
|
The longitude range of the scatterometer data. |
required |
verbose
|
bool
|
If True, the function will print the progress of the extraction. |
True
|
main_variable
|
str
|
The main variable to be extracted from the scatterometer data. This can be wind speed, wind direction, classification etc. |
'wind_speed'
|
Returns:
| Name | Type | Description |
|---|---|---|
observation_times |
ndarray
|
The time of observation of the scatterometer data. |
observation_lats |
ndarray
|
The latitude of the scatterometer data. |
observation_lons |
ndarray
|
The longitude of the scatterometer data. |
observation_main_parameter |
ndarray
|
main parameter extracted (wind_speed). |
Source code in windscangeo\func.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
extract_scatter_multisat(scatterometer_data_path, date, lat_range, lon_range, verbose=True)
Extracts scatterometer data from multiple files (.nc) in a specified directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scatterometer_data_path
|
str
|
Path to the directory containing scatterometer data files. |
required |
date
|
datetime
|
Date for which to extract data. |
required |
lat_range
|
tuple
|
Latitude range (min, max) for filtering data. |
required |
lon_range
|
tuple
|
Longitude range (min, max) for filtering data. |
required |
verbose
|
bool
|
If True, prints progress information. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing: - list of datetime: observation times - list of float: latitudes - list of float: longitudes - list of float: wind speeds |
Source code in windscangeo\func_inference.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
fill_nans(images)
This function fills NaN values in the images with zeros. (This is simply np.nan_to_num)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
A 4D numpy array with NaN values replaced by zeros. |
Source code in windscangeo\func.py
808 809 810 811 812 813 814 815 816 817 818 819 820 | |
filter_invalid(images, numerical_data, min_nonzero_pixels=50)
This function filters out invalid images and corresponding numerical data based on two criteria: 1) The sum of pixel values in the image is not zero (i.e., the image is not completely empty). 2) The number of non-zero pixels in the image is greater than or equal to a specified minimum threshold (default is 50).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
A 4D numpy array of shape (num_images, num_channels, height, width) containing the GOES images. |
required |
numerical_data
|
dict
|
A dictionary containing numerical data associated with the images. The keys should match the dimensions of the images. |
required |
min_nonzero_pixels
|
int
|
The minimum number of non-zero pixels required for an image to be considered valid. Default is 50. |
50
|
Returns:
| Name | Type | Description |
|---|---|---|
filtered_images |
ndarray
|
A 4D numpy array of shape (num_valid_images, num_channels, height, width) containing the filtered GOES images. |
filtered_numerical_data |
dict
|
A dictionary containing the numerical data associated with the valid images. |
Source code in windscangeo\func.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
filter_nighttime(observation_times, observation_lats, observation_lons, observation_wind_speeds, min_hour=10, max_hour=19, verbose=True)
This function filters the scatterometer data to only include observations that were made during daylight hours. The function checks the hour of each observation time and only keeps those that fall within the specified range (default is 10 to 19, which corresponds to 10 AM to 7 PM UTC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_times
|
ndarray
|
The times of observation of the scatterometer data. |
required |
observation_lats
|
ndarray
|
The latitudes of the scatterometer data. |
required |
observation_lons
|
ndarray
|
The longitudes of the scatterometer data. |
required |
observation_wind_speeds
|
ndarray
|
The wind speeds of the scatterometer data. |
required |
min_hour
|
int
|
The minimum hour of the day to include (default is 10). |
10
|
max_hour
|
int
|
The maximum hour of the day to include (default is 19). |
19
|
verbose
|
bool
|
If True, prints the number of valid scatterometer data points at daylight. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
valid_times |
list
|
A list of valid observation times that fall within the specified hour range. |
valid_lats |
list
|
A list of valid latitudes corresponding to the valid observation times |
valid_lons |
list
|
A list of valid longitudes corresponding to the valid observation times. |
valid_wind_speeds |
list
|
A list of valid wind speeds corresponding to the valid observation times. |
Source code in windscangeo\func.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
form_arrays_buoy(buoy, date_choice)
Form arrays from buoy data for a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buoy
|
Dataset
|
Buoy data containing time, latitude, longitude, and wind speed. |
required |
date_choice
|
str
|
Date for which to extract buoy data, in 'YYYY-MM |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat |
ndarray
|
Array of buoy latitudes. |
lon |
ndarray
|
Array of buoy longitudes. |
time |
ndarray
|
Array of buoy observation times in nanoseconds since epoch. |
wind_speed |
ndarray
|
Array of buoy wind speeds. |
buoy_name |
ndarray
|
Array of buoy names. |
Source code in windscangeo\func_inference.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
get_goes_url(time, goes_aws_url_folder='noaa-goes16/ABI-L2-CMIPF', goes_channel='C01')
This function gets the nearest GOES-16 files from the time given. The function returns a list of urls to the files. The function uses the s3fs library to access the AWS GOES-16 data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime[ns]
|
The time of the scatterometer data. |
required |
goes_aws_url_folder
|
str
|
The folder in the AWS S3 bucket where the GOES-16 data is stored. |
'noaa-goes16/ABI-L2-CMIPF'
|
goes_channel
|
list
|
The channel of interest. |
'C01'
|
Returns:
| Name | Type | Description |
|---|---|---|
urls |
list
|
A list of urls to the GOES-16 files. |
Source code in windscangeo\func.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
get_image(ds, parallel_index, lat_grd, lon_grd, lat_search, lon_search, goes_image_size=128)
This function retrieves a trainable GOES image for a given latitude and longitude from a GOES16 .nc file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The xarray dataset containing the GOES data. |
required |
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
goes_image_size
|
int
|
The size of the output image. Default is 128. |
128
|
Returns:
| Name | Type | Description |
|---|---|---|
padded_image |
DataArray
|
A padded xarray DataArray containing the GOES image centered around the specified lat/lon. |
Source code in windscangeo\func.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
get_indices(lat_grid, lon_grid, Goeslat, Goeslon, radius=0.125)
Finds the corresponding GOES row and column indices for each scatterometer point using a BallTree for efficiency, and then filtering points to form a square bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_grid
|
ndarray
|
2D array of latitudes from the scatterometer data. |
required |
lon_grid
|
ndarray
|
2D array of longitudes from the scatterometer data. |
required |
Goeslat
|
ndarray
|
2D array of latitudes from the GOES data. |
required |
Goeslon
|
ndarray
|
2D array of longitudes from the GOES data. |
required |
radius
|
float
|
Radius in degrees to define the bounding box around each scatterometer point. |
0.125
|
Returns: indices_array (numpy.ndarray): 2D array of tuples, where each tuple contains the row and column indices of the corresponding GOES pixel for each scatterometer point.
Source code in windscangeo\func.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
get_mlp(in_features, hidden_units, out_features)
Returns a MLP head
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
173 174 175 176 177 178 179 180 181 182 183 184 185 | |
goes_index(parallel_index, lat_grd, lon_grd, lat_search, lon_search)
This function retrieves the indices of the GOES image corresponding to a given latitude and longitude. This is an archived function. Current implementation decides on extent based on chosen image size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel_index
|
ndarray
|
The precomputed indices for GOES pixels corresponding to scatterometer lat/lon. |
required |
lat_grd
|
ndarray
|
The latitude grid of the scatterometer data. |
required |
lon_grd
|
ndarray
|
The longitude grid of the scatterometer data. |
required |
lat_search
|
float
|
The latitude to search for in the GOES data. |
required |
lon_search
|
float
|
The longitude to search for in the GOES data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
min_row |
int
|
The minimum row index of the GOES image. |
max_row |
int
|
The maximum row index of the GOES image. |
min_col |
int
|
The minimum column index of the GOES image. |
max_col |
int
|
The maximum column index of the GOES image. |
Source code in windscangeo\func.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
index_parallel(ds, ScatterDataset)
Finds the corresponding GOES row and column indices for the entire scatterometer dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterDataset
|
xarray Dataset containing scatterometer data. |
required | |
scatter_name
|
Name for the output file. |
required | |
output_path
|
Path to save the output file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
parallel_indice_values |
2D array of tuples containing GOES row and column indices corresponding to scatterometer data. |
Source code in windscangeo\func.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
inference_model(model, inference_loader, device)
Perform inference on the model using the provided DataLoader and return the outputs. Same as train_model but for a fixed given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be used for inference. |
required |
inference_loader
|
DataLoader
|
DataLoader for the inference dataset. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inference_outputs |
ndarray
|
Outputs from the model on the inference dataset. |
Source code in windscangeo\impl.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
inference_run(images, model_parameters, model_path, normalization_factors)
Runs inference on the provided images using the specified model parameters and normalization factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
Array of images to be used for inference. |
required |
model_parameters
|
dict
|
Dictionary containing model parameters such as batch size, image size, channels |
required |
model_path
|
str
|
Path to the pre-trained model file. |
required |
normalization_factors
|
dict
|
Dictionary containing normalization factors such as mean and standard deviation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inference_output |
ndarray
|
Array of inference outputs (wind speeds). |
Source code in windscangeo\func_inference.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
manage_saved_models(directory)
Manage saved model files in the specified directory by deleting older epoch files. Keeps only the latest epoch file and deletes all others. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
The directory where model files are saved. |
required |
Source code in windscangeo\impl.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
package_data(images, numerical_data, filter=True, solar_conversion=False, verbose=True)
This function packages the images and numerical data into a format that can be used for training a machine learning model. The function will filter out invalid images and fill in any NaN values. (Invalid images = empty images from GOES data) The function will also convert the observation times, latitudes and longitudes to solar angles (sza, saa) if solar_conversion is set to True. The function will return the images and numerical data in a numpy array format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
The GOES images corresponding to the observation data. |
required |
numerical_data
|
dict
|
A dictionary containing the numerical data corresponding to the observation data. The keys should include "observation_lats", "observation_lons", "observation_times" and optionally "wind_speeds". |
required |
filter
|
bool
|
If True, the function will filter out invalid images and fill in Nan values. Default is True. |
True
|
solar_conversion
|
bool
|
If True, the function will convert the observation times, latitudes and longitudes to solar angles (sza, saa). Default is False. (Not used in current implementation, but kept in case of future use) |
False
|
verbose
|
bool
|
If True, the function will print progress information. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
images |
ndarray
|
The GOES images corresponding to the observation data. |
numerical_data |
ndarray
|
The numerical data corresponding to the observation data. (sza, saa, main_parameter if solar_conversion is set to True or lat, lon, time, wind_speeds if solar_conversion is set to False) |
Source code in windscangeo\func.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
patchify(batch, patch_size)
Patchify the batch of images
Shape
batch: (b, h, w, c) output: (b, nh, nw, ph, pw, c)
taken from https://www.kaggle.com/code/umongsain/vision-transformer-from-scratch-pytorch
Source code in windscangeo\Models.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
plot_cloud_cover(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud cover mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be used for cloud cover calculation. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
plot_cloud_mask(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the cloud mask on a map with buoy locations. This works well with 30x30 images but larger images can diluted. Can be adapted to work with larger images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Cloud mask data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
plot_goes_image(lat_inference, lon_inference, images, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the GOES image data on a map with buoy locations. Made for 128x128 images where the middpoint is at (64,64). If using other image sizes, the plotting will probably not work as expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
images
|
ndarray
|
GOES image data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
plot_save_loss(best_val_outputs, best_val_labels, train_losses, val_losses, path_folder, saving=False)
Plot and save the training and validation losses, and optionally save the best validation outputs and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_val_outputs
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
best_val_labels
|
list or ndarray
|
True labels for the validation dataset. |
required |
train_losses
|
list
|
List of training losses per epoch. |
required |
val_losses
|
list
|
List of validation losses per epoch. |
required |
path_folder
|
str
|
Path to save the plot and optionally the outputs and labels. |
required |
saving
|
bool
|
If True, save the best validation outputs and labels. Default is False. |
False
|
Source code in windscangeo\func_ml.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
plot_wind_speeds(lat_inference, lon_inference, wind_speeds_inference, path_folder, buoy_name, buoy_lat, buoy_lon, time_choice)
Plot the wind speeds on a map with buoy locations. Filter nighttime images and add coastlines, gridlines, and buoy locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_inference
|
ndarray
|
Latitude values for the inference grid. |
required |
lon_inference
|
ndarray
|
Longitude values for the inference grid. |
required |
wind_speeds_inference
|
ndarray
|
Wind speed data to be plotted. |
required |
path_folder
|
str
|
Path to save the plot. |
required |
buoy_name
|
list or ndarray
|
Names of the buoys. |
required |
buoy_lat
|
list or ndarray
|
Latitude values of the buoys. |
required |
buoy_lon
|
list or ndarray
|
Longitude values of the buoys. |
required |
time_choice
|
datetime
|
Time of the inference. |
required |
Source code in windscangeo\func_ml.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
rmse_per_range(model_output, target, path_folder)
Calculate the RMSE for different ranges of wind speeds and save the results to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
list or ndarray
|
Model outputs for the validation dataset. |
required |
target
|
list or ndarray
|
True labels for the validation dataset. |
required |
path_folder
|
str
|
Path to save the CSV file. |
required |
Returns: pd.DataFrame: DataFrame containing the RMSE and count for each range.
Source code in windscangeo\func_ml.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
save_overpass_time(time_list, name_scatter)
This function prints the overpass time of the scatterometer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
name_scatter
|
str
|
The name of the scatterometer data source (e.g. ASCAT, HYSCAT etc). |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in windscangeo\func.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
savedataseperated(ScatterData, main_parameter, verbose=True)
This function extracts the valid lon / lat / measurement time and the main parameter from ever pixel of the scatterometer data and saves it to a numpy file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ScatterData
|
Dataset
|
The ASCAT dataset containing the scatterometer data. |
required |
main_parameter
|
DataArray
|
The main parameter to be saved. This can be a classification / wind speed / wind direction etc. |
required |
Returns:
lat_list (numpy.ndarray): The latitude values of the scatterometer data.
lon_list (numpy.ndarray): The longitude values of the scatterometer data.
time_list (numpy.ndarray): The measurement time values of the scatterometer data.
main_parameter_list (numpy.ndarray): The main parameter values of the scatterometer data.
this function saves the data locally to a folder called data_processed_scat
Source code in windscangeo\func.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
snap_to_nearest(values, reference_array, cutoff=1.0)
Snap an array of values to the nearest values in a reference array. If the difference is greater than the cutoff, the original value is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Array of values to snap. |
required |
reference_array
|
ndarray
|
Array of reference values. |
required |
cutoff
|
float
|
Maximum allowable difference for snapping. |
1.0
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Snapped values. |
Source code in windscangeo\func_inference.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
sort_by_time(lat_list, lon_list, time_list, wind_speed_list)
This function sorts the output of savedataseperated() by time. This allows for more efficient data processing and allows file caching for times that are represented by the same GOES file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_list
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon_list
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_list
|
ndarray
|
The measurement time values of the scatterometer data. |
required |
wind_speed_list
|
ndarray
|
The wind speed values of the scatterometer data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat_list_sorted |
ndarray
|
The sorted latitude values of the scatterometer data. |
lon_list_sorted |
ndarray
|
The sorted longitude values of the scatterometer data. |
time_list_sorted |
ndarray
|
The sorted measurement time values of the scatterometer data. |
wind_speed_list_sorted |
ndarray
|
The sorted wind speed values of the scatterometer data. |
Source code in windscangeo\func.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
test_model(model, test_loader, criterion, device)
Evaluate the model on the test dataset and return the outputs, targets, and average loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be evaluated. |
required |
test_loader
|
DataLoader
|
DataLoader for the test dataset. |
required |
criterion
|
Module
|
Loss function to be used for evaluation. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
test_outputs |
ndarray
|
Outputs from the model on the test dataset. |
test_targets |
ndarray
|
Targets corresponding to the test outputs. |
avg_test_loss |
float
|
Average loss on the test dataset. |
Source code in windscangeo\impl.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
train_model(model, train_loader, val_loader, num_epochs, lr, weight_decay, criterion, device, optimizer_choice, patience_epochs, patience_loss, path_folder)
Train the model with the given parameters dictionary and save the best validation outputs, labels, and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to be trained. |
required |
train_loader
|
DataLoader
|
DataLoader for the training dataset. |
required |
val_loader
|
DataLoader
|
DataLoader for the validation dataset. |
required |
num_epochs
|
int
|
Number of epochs to train the model. |
required |
lr
|
float
|
Learning rate for the optimizer. |
required |
weight_decay
|
float
|
Weight decay for the optimizer. |
required |
criterion
|
Module
|
Loss function to be used. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
optimizer_choice
|
str
|
Choice of optimizer ('Adam', 'SGD', 'RMSprop'). |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement in validation loss. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
path_folder
|
str
|
Path to save the model checkpoints. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
best_val_outputs |
ndarray
|
Best validation outputs from the model. |
best_val_labels |
ndarray
|
Best validation labels corresponding to the outputs. |
best_model |
Module
|
The best model based on validation loss. |
train_losses |
list
|
List of training losses for each epoch. |
val_losses |
list
|
List of validation losses for each epoch. |
Source code in windscangeo\impl.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
vectorized_solar_angles(lat, lon, time_utc)
This function calculates the solar zenith angle (SZA) and solar azimuth angle (SAA) for a given latitude, longitude, and time. This is an archived function. Current implementation does not use solar angles but only image input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
ndarray
|
The latitude values of the scatterometer data. |
required |
lon
|
ndarray
|
The longitude values of the scatterometer data. |
required |
time_utc
|
ndarray
|
The observation times in UTC. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sza |
ndarray
|
The solar zenith angle in degrees. |
saa |
ndarray
|
The solar azimuth angle in degrees. |
Source code in windscangeo\func_ml.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
early_stopping(valid_losses, patience_epochs, patience_loss)
Early stopping function to determine if training should stop based on validation losses. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid_losses
|
list
|
List of validation losses recorded during training. |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if training should stop, False otherwise. |
Source code in windscangeo\impl.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
inference_model(model, inference_loader, device)
Perform inference on the model using the provided DataLoader and return the outputs. Same as train_model but for a fixed given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be used for inference. |
required |
inference_loader
|
DataLoader
|
DataLoader for the inference dataset. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inference_outputs |
ndarray
|
Outputs from the model on the inference dataset. |
Source code in windscangeo\impl.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
manage_saved_models(directory)
Manage saved model files in the specified directory by deleting older epoch files. Keeps only the latest epoch file and deletes all others. From @ Jing Sun
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
The directory where model files are saved. |
required |
Source code in windscangeo\impl.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
test_model(model, test_loader, criterion, device)
Evaluate the model on the test dataset and return the outputs, targets, and average loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The trained model to be evaluated. |
required |
test_loader
|
DataLoader
|
DataLoader for the test dataset. |
required |
criterion
|
Module
|
Loss function to be used for evaluation. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
test_outputs |
ndarray
|
Outputs from the model on the test dataset. |
test_targets |
ndarray
|
Targets corresponding to the test outputs. |
avg_test_loss |
float
|
Average loss on the test dataset. |
Source code in windscangeo\impl.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
train_model(model, train_loader, val_loader, num_epochs, lr, weight_decay, criterion, device, optimizer_choice, patience_epochs, patience_loss, path_folder)
Train the model with the given parameters dictionary and save the best validation outputs, labels, and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to be trained. |
required |
train_loader
|
DataLoader
|
DataLoader for the training dataset. |
required |
val_loader
|
DataLoader
|
DataLoader for the validation dataset. |
required |
num_epochs
|
int
|
Number of epochs to train the model. |
required |
lr
|
float
|
Learning rate for the optimizer. |
required |
weight_decay
|
float
|
Weight decay for the optimizer. |
required |
criterion
|
Module
|
Loss function to be used. |
required |
device
|
device
|
Device to run the model on (CPU or GPU). |
required |
optimizer_choice
|
str
|
Choice of optimizer ('Adam', 'SGD', 'RMSprop'). |
required |
patience_epochs
|
int
|
Number of epochs to wait before stopping if no improvement in validation loss. |
required |
patience_loss
|
float
|
Minimum change in validation loss to consider as an improvement. |
required |
path_folder
|
str
|
Path to save the model checkpoints. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
best_val_outputs |
ndarray
|
Best validation outputs from the model. |
best_val_labels |
ndarray
|
Best validation labels corresponding to the outputs. |
best_model |
Module
|
The best model based on validation loss. |
train_losses |
list
|
List of training losses for each epoch. |
val_losses |
list
|
List of validation losses for each epoch. |
Source code in windscangeo\impl.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |