Skip to content

Commit 6f71bb8

Browse files
committed
Update calipso_cloudsat artifact with monthly data
1 parent 6d54e4b commit 6f71bb8

File tree

6 files changed

+66
-25
lines changed

6 files changed

+66
-25
lines changed

calipso_cloudsat/Manifest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.11.5"
3+
julia_version = "1.11.8"
44
manifest_format = "2.0"
5-
project_hash = "ba09a07cf72bb92a3c83575effee91f0237dfb76"
5+
project_hash = "7aa728f622ede69eaf4804ee6b6053fc32fb5113"
66

77
[[deps.ArgCheck]]
88
git-tree-sha1 = "f9e9a66c9b7be1ad7372bbd9b062d9230c30c5ce"
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
[calipso_cloudsat]
22
git-tree-sha1 = "dae77bc4ff79194ee6e794c1181bec1bebd67ea9"
33
[calipso_cloudsat_lowres]
4-
git-tree-sha1 = "a76ee4474873a2cf366fb0755f7fbac647987082"
5-
6-
[[calipso_cloudsat_lowres.download]]
7-
sha256 = "deb774f613c4c3668cb1b7b272711dcef699c318ff03f5b8f3ea83d5a3d50926"
8-
url = "https://caltech.box.com/shared/static/ywx8ssv70d7b7t6bdp148su955tbrkoq.gz"
4+
git-tree-sha1 = "c1c0a16127bd547124cdf7288140002d74846efe"

calipso_cloudsat/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
ClimaArtifactsHelper = "6ffa2572-8378-4377-82eb-ea11db28b255"
3+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
34
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
45
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
56
ZipArchives = "49080126-0e18-4c2a-b176-c102e4b3760c"

calipso_cloudsat/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
This artifact repackages data coming from the [3S-GEOPROF-COMB
44
Dataset](https://zenodo.org/records/12768877) and contains seasonal data from
5-
2006 JJA (June, July, August) to 2020 JJA. In particular, the data is from
6-
`radarlidar_seasonal_2.5x2.5.zip` and `radarlidar_seasonal_10x10.zip`.
5+
2006 JJA (June, July, August) to 2020 JJA and monthly data from June 2006 to
6+
August 2020. In particular, the seasonal data is from
7+
`radarlidar_seasonal_2.5x2.5.zip` and `radarlidar_seasonal_10x10.zip` and the
8+
monthly data is from `radarlidar_monthly_2.5x2.5.zip` and
9+
`radarlidar_monthly_10x10.zip`.
710

811
## Data
912

@@ -54,7 +57,7 @@ For more information about the data, refer to the documentation on
5457

5558
1. Julia
5659
2. Python
57-
3. 3.9GiB to download and extract the data from the downloaded zip files.
60+
3. 16GiB to download and extract the data from the downloaded zip files.
5861

5962
## Usage
6063

@@ -74,11 +77,16 @@ while any global attribute that remains the same is included as a single value.
7477

7578
## Files
7679

77-
The files included are `radarlidar_seasonal_2.5x2.5.nc` and
80+
The files included for seasonal data are `radarlidar_seasonal_2.5x2.5.nc` and
7881
`radarlidar_seasonal_10x10.nc`, a lower resolution version of
7982
`radarlidar_seasonal_2.5x2.5.nc`. The size of `radarlidar_seasonal_2.5x2.5.nc`
8083
is 3.1GiB and the size of `radarlidar_seasonal_10x10.nc` is 196MiB.
8184

85+
The files included for monthly data are `radarlidar_monthly_2.5x2.5.nc` and
86+
`radarlidar_monthly_10x10.nc`, a lower resolution version of
87+
`radarlidar_monthly_2.5x2.5.nc`. The size of `radarlidar_monthly_2.5x2.5.nc`
88+
is 9.2GiB and the size of `radarlidar_monthly_10x10.nc` is 588MiB.
89+
8290
## License
8391

8492
Creative Commons Attribution 4.0 International.

calipso_cloudsat/create_artifact.jl

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NCDatasets
22
using DataStructures
33
using ClimaArtifactsHelper
4+
import Dates
45

56
"""
67
parse_year_season(path)
@@ -12,12 +13,25 @@ The seasons MAM, JJA, SON, and DJF map to 1, 2, 3, and 4.
1213
function parse_year_season(path)
1314
# File name should look like "2008-MAM-..."
1415
filename = last(splitpath(path))
15-
s = first(filename, 8)
16+
s = split(filename, "_")[1]
1617
year, season = split(s, "-")
1718
SEASON_ORDER = Dict("MAM" => 1, "JJA" => 2, "SON" => 3, "DJF" => 4)
1819
return (parse(Int, year), SEASON_ORDER[season])
1920
end
2021

22+
"""
23+
parse_year_month(path)
24+
25+
Given a file `path`, return the year and month as integers.
26+
"""
27+
function parse_year_month(path)
28+
# File name should look like "2008-MAM-..."
29+
filename = last(splitpath(path))
30+
s = split(filename, "_")[1]
31+
year, month = split(s, "-")
32+
return parse.(Int, (year, month))
33+
end
34+
2135
"""
2236
get_and_sort_files(dir)
2337
@@ -31,7 +45,13 @@ function get_and_sort_files(dir)
3145
# For each year, the order of the seasons are "MAM", "JJA", "SON", "DJF"
3246
# Note that the first month is used, so 2006-DJF refers to Dec 2006, Jan
3347
# 2007, and Feb 2007
34-
sort!(files, by = parse_year_season)
48+
if occursin("seasonal", dir)
49+
sort!(files, by = parse_year_season)
50+
elseif occursin("monthly", dir)
51+
sort!(files, by = parse_year_month)
52+
else
53+
error("Only support files with monthly or seasonal periods")
54+
end
3555
return files
3656
end
3757

@@ -81,6 +101,16 @@ function stitch_cloud_data(files, output_filepath)
81101
defVar(ds, varname, data, dimnames(mfds[varname]), attrib = mfds[varname].attrib)
82102
end
83103

104+
# Seasonal files have a time dimension, but monthly files doesn't
105+
if occursin("monthly", first(files))
106+
@info "Adding time dimension for monthly dataset"
107+
year_and_month = parse_year_month.(files)
108+
data = [Dates.DateTime(year, month) for (year, month) in year_and_month]
109+
attrib = Dict("units" => "days since 2006-06-01 00:00:00", "calendar" => "proleptic_gregorian")
110+
first(data) == Dates.DateTime(2006, 6) || error("The first date is not 2006-06-01")
111+
defVar(ds, "time", data, ("time", ), attrib = attrib)
112+
end
113+
84114
# Close datasets
85115
close(ds)
86116
close(mfds)
@@ -179,7 +209,7 @@ function make_artifact(filepath_names)
179209
end
180210

181211
for filepath_name in filepath_names
182-
if endswith(filepath_name, "radarlidar_seasonal_2.5x2.5.nc")
212+
if endswith(filepath_name, "_2.5x2.5.nc")
183213
filename = last(splitpath(filepath_name))
184214
mv(filepath_name, joinpath(output_dir, filename), force = true)
185215
end
@@ -196,7 +226,7 @@ function make_artifact(filepath_names)
196226
end
197227

198228
for filepath_name in filepath_names
199-
if endswith(filepath_name, "radarlidar_seasonal_10x10.nc")
229+
if endswith(filepath_name, "_10x10.nc")
200230
filename = last(splitpath(filepath_name))
201231
mv(filepath_name, joinpath(output_dir_lowres, filename), force = true)
202232
end
@@ -208,13 +238,15 @@ function make_artifact(filepath_names)
208238
)
209239
end
210240

211-
radarlidar_dir_2_5 =
212-
joinpath(dirname(@__FILE__), "radarlidar_seasonal_data", "radarlidar_seasonal_2.5x2.5")
213-
radarlidar_dir_10 =
214-
joinpath(dirname(@__FILE__), "radarlidar_seasonal_data", "radarlidar_seasonal_10x10")
241+
radarlidar_dirs = [
242+
joinpath(dirname(@__FILE__), "radarlidar_data", "radarlidar_seasonal_2.5x2.5")
243+
joinpath(dirname(@__FILE__), "radarlidar_data", "radarlidar_seasonal_10x10")
244+
joinpath(dirname(@__FILE__), "radarlidar_data", "radarlidar_monthly_2.5x2.5")
245+
joinpath(dirname(@__FILE__), "radarlidar_data", "radarlidar_monthly_10x10")
246+
]
215247

216248
# Check if the directory exists
217-
for directory in (radarlidar_dir_10, radarlidar_dir_2_5)
249+
for directory in radarlidar_dirs
218250
if !isdir(directory)
219251
error("$directory is not a directory. Check the file path passed in")
220252
end
@@ -223,7 +255,7 @@ end
223255
# Loop over the directories containing the NetCDF files and create a netcdf file
224256
# from them
225257
filepath_names = []
226-
for directory in (radarlidar_dir_10, radarlidar_dir_2_5)
258+
for directory in radarlidar_dirs
227259
files = get_and_sort_files(directory)
228260
filename = last(splitpath(directory)) * ".nc"
229261
filepath_name = joinpath(dirname(directory), filename)

calipso_cloudsat/download_cloudsat.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@ def download_and_unzip_cloudsat():
1313
# Download data
1414
seasonal_10_zip = dir_path.joinpath("radarlidar_seasonal_10x10.zip")
1515
seasonal_2_5_zip = dir_path.joinpath("radarlidar_seasonal_2.5x2.5.zip")
16-
zip_files = [seasonal_10_zip, seasonal_2_5_zip]
16+
monthly_10_zip = dir_path.joinpath("radarlidar_monthly_10x10.zip")
17+
monthly_2_5_zip = dir_path.joinpath("radarlidar_monthly_2.5x2.5.zip")
18+
zip_files = [seasonal_10_zip, seasonal_2_5_zip, monthly_10_zip, monthly_2_5_zip]
1719
download_links = [
1820
"https://zenodo.org/records/12768877/files/radarlidar_seasonal_10x10.zip?download=1",
1921
"https://zenodo.org/records/12768877/files/radarlidar_seasonal_2.5x2.5.zip?download=1",
22+
"https://zenodo.org/records/12768877/files/radarlidar_monthly_10x10.zip?download=1",
23+
"https://zenodo.org/records/12768877/files/radarlidar_monthly_2.5x2.5.zip?download=1",
2024
]
2125
for download_link, zip_file in zip(download_links, zip_files):
2226
with urlopen(download_link) as in_stream, open(zip_file, "wb") as out_file:
2327
copyfileobj(in_stream, out_file)
2428

2529
# Find files and unzip them
26-
unzip_directory = dir_path.joinpath("radarlidar_seasonal_data")
30+
unzip_directory = dir_path.joinpath("radarlidar_data")
2731
if not os.path.isdir(unzip_directory):
2832
os.mkdir(unzip_directory)
29-
for zip_file in [seasonal_10_zip, seasonal_2_5_zip]:
33+
for zip_file in zip_files:
3034
with zipfile.ZipFile(str(zip_file), "r") as zip_ref:
3135
zip_ref.extractall(unzip_directory)
3236
return None
@@ -35,5 +39,5 @@ def download_and_unzip_cloudsat():
3539
if __name__ == "__main__":
3640
download_and_unzip_cloudsat()
3741
print(
38-
"The data should be downloaded and stored in radarlidar_seasonal_data. You can now delete the zip files"
42+
"The data should be downloaded and stored in radarlidar_data. You can now delete the zip files"
3943
)

0 commit comments

Comments
 (0)