-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgtfy.txt
92 lines (71 loc) · 3.95 KB
/
gtfy.txt
1
2
3
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#creating data directory folders for the elevation downloaded data using os and pathlib
#make elevation data folder
os.makedirs("C:/Users/arago/Documents/GitHub/habitatmodel-main/studyarea_data/elevation", exist_ok=True)
#create variable with the path
os.path.join("C:/Users/arago/Documents/GitHub/habitatmodel-main/studyarea_data/elevation")
import earthaccess
elevation_tif_data = r"C:/Users/arago/Documents/GitHub/habitatmodel-main/studyarea_data/elevation"
#https://github.com/nsidc/earthaccess/
#my profile site: https://urs.earthdata.nasa.gov/
#DEM site search data: https://search.earthdata.nasa.gov/search
# 1. Login
earthaccess.login()
# 2. Search
results = earthaccess.search_data(
short_name='CIESIN_SEDAC_DEDC_ACE_V2', # ATLAS/ICESat-2 L3A Land Ice Height
bounding_box=(pawnee_grasslands_bounds), # Only include files in area of interest...
temporal=("1999-02", "2019-03"), # ...and time period of interest.
count=10
)
# 3. Access
files = earthaccess.download(results, elevation_tif_data)
print(f"Downloaded: {elevation_tif_data}")
datasets = earthaccess.search_datasets(keyword='ACE2')
for dataset in datasets:
print(dataset['umm']['ShortName'], dataset['umm']['EntryTitle'])
#copied from chatgpt because code was not working
# Setting variables and identifying directories
elev3sec_data = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev5min_data = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev9sec_data = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev30sec_data = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev3sec_file_name = "dedc-ace-v2_30N105W_3sec.zip"
elev5min_file_name = "dedc-ace-v2_30N105W_5min.zip"
elev9sec_file_name = "dedc-ace-v2_30N105W_9sec.zip"
elev30sec_file_name = "dedc-ace-v2_30N105W_30sec.zip"
# Defining extraction directories
elev3sec_data_extract = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev5min_data_extract = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev9sec_data_extract = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
elev30sec_data_extract = r"C:\Users\arago\Documents\GitHub\habitatmodel-main\studyarea_data\elevation"
# Defining the full file paths
elev3sec_zip_path = os.path.join(elev3sec_data, elev3sec_file_name)
elev5min_zip_path = os.path.join(elev5min_data, elev5min_file_name)
elev9sec_zip_path = os.path.join(elev9sec_data, elev9sec_file_name)
elev30sec_zip_path = os.path.join(elev30sec_data, elev30sec_file_name)
# Defining extraction directories without the '.zip' extension
elev3sec_path = os.path.join(elev3sec_data_extract, elev3sec_file_name.replace(".zip", ""))
elev5min_path = os.path.join(elev5min_data_extract, elev5min_file_name.replace(".zip", ""))
elev9sec_path = os.path.join(elev9sec_data_extract, elev9sec_file_name.replace(".zip", ""))
elev30sec_path = os.path.join(elev30sec_data_extract, elev30sec_file_name.replace(".zip", ""))
# Function to extract ZIP file
def extract_zip(zip_file_path, extract_to):
try:
print(f"Extracting {zip_file_path}...")
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
print(f"Contents extracted to: {extract_to}")
except zipfile.BadZipFile as e:
print(f"Error: The file is not a valid ZIP archive: {e}")
# Step 2: Extract the ZIP files as a list
for zip_path, extract_path in [
(elev3sec_zip_path, elev3sec_path),
(elev5min_zip_path, elev5min_path),
(elev9sec_zip_path, elev9sec_path),
(elev30sec_zip_path, elev30sec_path)
]:
if not os.path.exists(extract_path): # Check if the extraction directory already exists
os.makedirs(extract_path, exist_ok=True) # Create extraction directory if it doesn't exist
extract_zip(zip_path, extract_path)
else:
print(f"Extracted directory already exists at: {extract_path}")