Skip to content

Commit 361d1b4

Browse files
author
asteiker
committed
Merge remote-tracking branch 'origin/cryo2ice' into is2-cryo2
2 parents 0865e87 + 30d7698 commit 361d1b4

11 files changed

+5700
-6
lines changed

notebooks/ICESat-2_Cloud_Access/ATL06-direct-access.ipynb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "c91169d7",
5+
"id": "97c67e4f-43c4-4a69-9e9b-c45c7c882830",
66
"metadata": {
77
"tags": []
88
},
@@ -52,10 +52,8 @@
5252
"\n",
5353
"### **Example of end product** \n",
5454
"At the end of this tutorial, the following figure will be generated:\n",
55-
"<center>\n",
56-
"<img src='./img/atl06_example_end_product.png'/>\n",
57-
"</center>\n",
58-
"\n",
55+
" \n",
56+
"![ATL06 land ice heights](./img/atl06_example_end_product.png)\n",
5957
"### **Time requirement**\n",
6058
"\n",
6159
"Allow approximately 20 minutes to complete this tutorial."
@@ -397,7 +395,7 @@
397395
"name": "python",
398396
"nbconvert_exporter": "python",
399397
"pygments_lexer": "ipython3",
400-
"version": "3.9.15"
398+
"version": "3.10.14"
401399
}
402400
},
403401
"nbformat": 4,

notebooks/ICESat-2_Cloud_Access/ICESat2-CryoSat2.ipynb

Lines changed: 2402 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import platform
3+
from ftplib import FTP
4+
import sys
5+
6+
7+
download_file_obj = None
8+
read_byte_count = None
9+
total_byte_count = None
10+
11+
12+
def get_padded_count(count, max_count):
13+
return str(count).zfill(len(str(max_count)))
14+
15+
16+
def file_byte_handler(data):
17+
global download_file_obj, read_byte_count, total_byte_count
18+
download_file_obj.write(data)
19+
read_byte_count = read_byte_count + len(data)
20+
progress_bar(read_byte_count, total_byte_count)
21+
22+
23+
def progress_bar(progress, total, prefix="", size=60, file=sys.stdout):
24+
if total != 0:
25+
x = int(size * progress / total)
26+
x_percent = int(100 * progress / total)
27+
file.write(f" {prefix} [{'='*x}{' '*(size-x)}] {x_percent} % \r")
28+
file.flush()
29+
30+
31+
def download_files(user_email, esa_files):
32+
global download_file_obj, read_byte_count, total_byte_count
33+
print("About to connect to ESA science server")
34+
with FTP("science-pds.cryosat.esa.int") as ftp:
35+
try:
36+
ftp.login("anonymous", user_email)
37+
print("Downloading {} files".format(len(esa_files)))
38+
39+
for i, filename in enumerate(esa_files):
40+
padded_count = get_padded_count(i + 1, len(esa_files))
41+
print("{}/{}. Downloading file {}".format(padded_count, len(esa_files), os.path.basename(filename)))
42+
43+
with open(os.path.basename(filename), 'wb') as download_file:
44+
download_file_obj = download_file
45+
total_byte_count = ftp.size(filename)
46+
read_byte_count = 0
47+
ftp.retrbinary('RETR ' + filename, file_byte_handler, 1024)
48+
print("\n")
49+
finally:
50+
print("Exiting FTP.")
51+
ftp.quit()
52+
53+
54+
if __name__ == '__main__':
55+
56+
esa_files = ['SIR_SAR_L2/2019/12/CS_LTA__SIR_SAR_2__20191227T110305_20191227T111751_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200329T163208_20200329T164044_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200114T203033_20200114T204440_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191103T134759_20191103T135125_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200204T191657_20200204T192558_E001.nc', 'SIR_SAR_L2/2019/12/CS_LTA__SIR_SAR_2__20191216T215645_20191216T220909_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200315T065755_20200315T071241_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191030T135252_20191030T135600_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200219T081800_20200219T083303_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200110T203717_20200110T204612_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200409T053748_20200409T054151_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200413T053254_20200413T053659_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200208T191154_20200208T192117_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200319T065300_20200319T070802_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200304T175209_20200304T180102_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191128T122800_20191128T123212_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191009T150801_20191009T151142_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191121T231659_20191121T232817_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200215T082253_20200215T083741_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200121T094259_20200121T095800_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191005T151255_20191005T151621_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200427T150701_20200427T151544_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191024T004201_20191024T005059_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200308T174708_20200308T175621_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200402T162707_20200402T163602_E001.nc']
57+
58+
if int(platform.python_version_tuple()[0]) < 3:
59+
exit("Your Python version is {}. Please use version 3.0 or higher.".format(platform.python_version()))
60+
61+
email = input("Please enter your e-mail: ")
62+
63+
download_files(email, esa_files)
Binary file not shown.
322 KB
Loading
223 KB
Loading
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import platform
3+
from ftplib import FTP
4+
import sys
5+
6+
7+
download_file_obj = None
8+
read_byte_count = None
9+
total_byte_count = None
10+
11+
12+
def get_padded_count(count, max_count):
13+
return str(count).zfill(len(str(max_count)))
14+
15+
16+
def file_byte_handler(data):
17+
global download_file_obj, read_byte_count, total_byte_count
18+
download_file_obj.write(data)
19+
read_byte_count = read_byte_count + len(data)
20+
progress_bar(read_byte_count, total_byte_count)
21+
22+
23+
def progress_bar(progress, total, prefix="", size=60, file=sys.stdout):
24+
if total != 0:
25+
x = int(size * progress / total)
26+
x_percent = int(100 * progress / total)
27+
file.write(f" {prefix} [{'='*x}{' '*(size-x)}] {x_percent} % \r")
28+
file.flush()
29+
30+
31+
def download_files(user_email, esa_files):
32+
global download_file_obj, read_byte_count, total_byte_count
33+
print("About to connect to ESA science server")
34+
with FTP("science-pds.cryosat.esa.int") as ftp:
35+
try:
36+
ftp.login("anonymous", user_email)
37+
print("Downloading {} files".format(len(esa_files)))
38+
39+
for i, filename in enumerate(esa_files):
40+
padded_count = get_padded_count(i + 1, len(esa_files))
41+
print("{}/{}. Downloading file {}".format(padded_count, len(esa_files), os.path.basename(filename)))
42+
43+
with open(os.path.basename(filename), 'wb') as download_file:
44+
download_file_obj = download_file
45+
total_byte_count = ftp.size(filename)
46+
read_byte_count = 0
47+
ftp.retrbinary('RETR ' + filename, file_byte_handler, 1024)
48+
print("\n")
49+
finally:
50+
print("Exiting FTP.")
51+
ftp.quit()
52+
53+
54+
if __name__ == '__main__':
55+
56+
esa_files = ['SIR_SAR_L2/2019/12/CS_LTA__SIR_SAR_2__20191227T110305_20191227T111751_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200329T163208_20200329T164044_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200114T203033_20200114T204440_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191103T134759_20191103T135125_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200204T191657_20200204T192558_E001.nc', 'SIR_SAR_L2/2019/12/CS_LTA__SIR_SAR_2__20191216T215645_20191216T220909_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200315T065755_20200315T071241_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191030T135252_20191030T135600_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200219T081800_20200219T083303_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200110T203717_20200110T204612_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200409T053748_20200409T054151_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200413T053254_20200413T053659_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200208T191154_20200208T192117_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200319T065300_20200319T070802_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200304T175209_20200304T180102_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191128T122800_20191128T123212_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191009T150801_20191009T151142_E001.nc', 'SIR_SAR_L2/2019/11/CS_LTA__SIR_SAR_2__20191121T231659_20191121T232817_E001.nc', 'SIR_SAR_L2/2020/02/CS_LTA__SIR_SAR_2__20200215T082253_20200215T083741_E001.nc', 'SIR_SAR_L2/2020/01/CS_LTA__SIR_SAR_2__20200121T094259_20200121T095800_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191005T151255_20191005T151621_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200427T150701_20200427T151544_E001.nc', 'SIR_SAR_L2/2019/10/CS_LTA__SIR_SAR_2__20191024T004201_20191024T005059_E001.nc', 'SIR_SAR_L2/2020/03/CS_LTA__SIR_SAR_2__20200308T174708_20200308T175621_E001.nc', 'SIR_SAR_L2/2020/04/CS_LTA__SIR_SAR_2__20200402T162707_20200402T163602_E001.nc']
57+
58+
if int(platform.python_version_tuple()[0]) < 3:
59+
exit("Your Python version is {}. Please use version 3.0 or higher.".format(platform.python_version()))
60+
61+
email = input("Please enter your e-mail: ")
62+
63+
download_files(email, esa_files)

notebooks/cryo2ice/cartopy_practice.ipynb

Lines changed: 1737 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""Utility routines to download CryoSat-2 files"""
2+
3+
import os
4+
import platform
5+
from ftplib import FTP
6+
import sys
7+
from typing import Union, List
8+
9+
from pathlib import Path
10+
11+
12+
def get_padded_count(count, max_count):
13+
return str(count).zfill(len(str(max_count)))
14+
15+
16+
def file_byte_handler(data):
17+
global download_file_obj, read_byte_count, total_byte_count
18+
download_file_obj.write(data)
19+
read_byte_count = read_byte_count + len(data)
20+
progress_bar(read_byte_count, total_byte_count)
21+
22+
23+
def progress_bar(progress, total, prefix="", size=60, file=sys.stdout):
24+
if total != 0:
25+
x = int(size * progress / total)
26+
x_percent = int(100 * progress / total)
27+
file.write(f" {prefix} [{'='*x}{' '*(size-x)}] {x_percent} % \r")
28+
file.flush()
29+
30+
31+
def download_files(user_email: str, esa_files: List[str], dir: Union[str,Path]="."):
32+
"""Downloads CryoSat-2 Files from ESA ftp
33+
34+
Arguments
35+
---------
36+
user_email : email to use for anonymous ftp login
37+
esa_files : list of paths to cryosat-2 files
38+
dir : output directory path. Default is current working directory.
39+
If dir does not exist it is created.
40+
41+
Returns
42+
-------
43+
list of paths to downloaded files
44+
"""
45+
global download_file_obj, read_byte_count, total_byte_count
46+
47+
if not isinstance(dir, Path):
48+
dir = Path(dir)
49+
50+
if not dir.exists():
51+
if not dir.exists():
52+
print("Download path dir does not exist. Creating dir")
53+
dir.mkdir(parents=True, exist_ok=True)
54+
55+
print("About to connect to ESA science server")
56+
with FTP("science-pds.cryosat.esa.int") as ftp:
57+
try:
58+
ftp.login("anonymous", user_email)
59+
print("Downloading {} files".format(len(esa_files)))
60+
61+
download_path_list = []
62+
for i, filename in enumerate(esa_files):
63+
padded_count = get_padded_count(i + 1, len(esa_files))
64+
print("{}/{}. Downloading file {}".format(padded_count, len(esa_files),
65+
os.path.basename(filename)))
66+
67+
download_path = dir / os.path.basename(filename)
68+
with open(download_path, 'wb') as download_file:
69+
download_file_obj = download_file
70+
total_byte_count = ftp.size(filename)
71+
read_byte_count = 0
72+
ftp.retrbinary('RETR ' + filename, file_byte_handler, 1024)
73+
download_path_list.append(download_path)
74+
print("\n")
75+
finally:
76+
print("Exiting FTP.")
77+
ftp.quit()
78+
79+
return download_path_list

0 commit comments

Comments
 (0)