Example IMD Radar Data#
import os
import glob
import pyart
import requests
import subprocess
import pyscancf as pcf
## You are using the Python ARM Radar Toolkit (Py-ART), an open source
## library for working with weather radar data. Py-ART is partly
## supported by the U.S. Department of Energy as part of the Atmospheric
## Radiation Measurement (ARM) Climate Research Facility, an Office of
## Science user facility.
##
## If you use this software to prepare a publication, please cite:
##
## JJ Helmus and SM Collis, JORS 2016, doi: 10.5334/jors.119
## Cite PyScanCf:
## Syed, H. A., Sayyed, I., Kalapureddy, M. C. R., & Grandhi, K. K. (2021).
## PyScanCf – The library for individual sweep datasets of IMD weather radars.
## Zenodo. https://doi.org/10.5281/zenodo.5574160
# GitHub raw content base URL (for downloading)
base_url = (
"https://raw.githubusercontent.com/syedhamidali/pyscancf_examples/main/data/goa16/"
)
api_url = (
"https://api.github.com/repos/syedhamidali/pyscancf_examples/contents/data/goa16"
)
response = requests.get(api_url)
files = [item["name"] for item in response.json()]
print(files)
['GOA210516024101-IMD-B.nc', 'GOA210516024101-IMD-B.nc.1', 'GOA210516024101-IMD-B.nc.2', 'GOA210516024101-IMD-B.nc.3', 'GOA210516024101-IMD-B.nc.4', 'GOA210516024101-IMD-B.nc.5', 'GOA210516024101-IMD-B.nc.6', 'GOA210516024101-IMD-B.nc.7', 'GOA210516024101-IMD-B.nc.8', 'GOA210516024101-IMD-B.nc.9']
# Target directory to save downloaded files
target_dir = os.path.join(os.getenv("GITHUB_WORKSPACE", "."), "goa_data")
os.makedirs(target_dir, exist_ok=True)
# Function to download files using curl
def download_with_curl(file_name):
file_url = base_url + file_name
file_path = os.path.join(target_dir, file_name)
if not os.path.exists(file_path):
print(f"Downloading {file_name}...")
subprocess.run(["curl", "-o", file_path, file_url], check=True)
print(f"Downloaded {file_name}")
else:
print(f"{file_name} already exists.")
return file_path
# Download the files
downloaded_files = []
for file_name in files:
file_path = download_with_curl(file_name)
downloaded_files.append(file_path)
Downloading GOA210516024101-IMD-B.nc...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1413k 100 1413k 0 0 5627k 0 --:--:-- --:--:-- --:--:-- 5630k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc
Downloading GOA210516024101-IMD-B.nc.1...
0 1413k 0 8259 0 0 20414 0 0:01:10 --:--:-- 0:01:10 20392
100 1413k 100 1413k 0 0 3175k 0 --:--:-- --:--:-- --:--:-- 3176k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.1
Downloading GOA210516024101-IMD-B.nc.2...
100 1413k 100 1413k 0 0 5339k 0 --:--:-- --:--:-- --:--:-- 5353k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1413k 100 1413k 0 0 8866k 0 --:--:-- --:--:-- --:--:-- 8888k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.2
Downloading GOA210516024101-IMD-B.nc.3...
Downloaded GOA210516024101-IMD-B.nc.3
Downloading GOA210516024101-IMD-B.nc.4...
100 1413k 100 1413k 0 0 6872k 0 --:--:-- --:--:-- --:--:-- 6894k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.4
Downloading GOA210516024101-IMD-B.nc.5...
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1413k 100 1413k 0 0 3868k 0 --:--:-- --:--:-- --:--:-- 3861k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.5
Downloading GOA210516024101-IMD-B.nc.6...
100 1413k 100 1413k 0 0 4452k 0 --:--:-- --:--:-- --:--:-- 4458k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.6
Downloading GOA210516024101-IMD-B.nc.7...
100 1413k 100 1413k 0 0 4645k 0 --:--:-- --:--:-- --:--:-- 4649k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.7
Downloading GOA210516024101-IMD-B.nc.8...
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1413k 100 1413k 0 0 5130k 0 --:--:-- --:--:-- --:--:-- 5120k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Downloaded GOA210516024101-IMD-B.nc.8
Downloading GOA210516024101-IMD-B.nc.9...
Downloaded GOA210516024101-IMD-B.nc.9
100 1413k 100 1413k 0 0 3974k 0 --:--:-- --:--:-- --:--:-- 3981k
input_dir = target_dir
out_dir = "outdir"
pcf.cfrad(
input_dir,
out_dir,
)
2025-04-19 06:27:27,296 - INFO - Packing 10 sweeps into 1 volumes
2025-04-19 06:27:27,297 - INFO - Processing volume 1
2025-04-19 06:27:28,103 - INFO - Saved cfrad_GOA210516024101-IMD-B.nc
2025-04-19 06:27:28,104 - INFO - Data merging done
Time Taken: 0:00:03.938182
files = sorted(glob.glob(out_dir + "/*.nc"))
files
['outdir/cfrad_GOA210516024101-IMD-B.nc']
for file in files:
radar = pyart.io.read(file)
grid = pcf.get_grid(radar, grid_shape=(20, 401, 401), height=10, length=250)
grid.fields["REF"] = grid.fields.pop("Z")
pcf.plot_cappi(grid, "REF")
...............................
Plotting Max-REF 20210516024104
...............................