-
Notifications
You must be signed in to change notification settings - Fork 2
/
Extracting_tas_from_NetCDF.py
60 lines (38 loc) · 1.36 KB
/
Extracting_tas_from_NetCDF.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 1 10:16:18 2020
@author: anjakatzenberger
"""
import netCDF4 as nc
import os
###############################################################
# EXTRACTING TAS DATA FROM NETCDF-FILES #
# Anja Katzenberger #
# anja.katzenberger@pik-potsdam.de #
# 18.06.2020 #
###############################################################
# Extracting temperature data (tas) from NETCDF Format to Python
# Directories with files of interest
ssp = 'ssp585'
dir = ""
files = os.listdir(dir)
#### Extracting pr data
tas_c = []
tas_c_model = []
for file in files:
dir_file = os.sep.join((dir, file))
data = nc.Dataset(dir_file)
# combined: 1850-2100
if file.endswith("ymean_fldmean.nc"):
center_model = file.split('_' + ssp)[0][3:]
model = center_model.split('_')[2]
tas = data['tas'][:]
tas_c_i = []
for i in range(len(tas)):
tas_i = tas[i][0][0]
tas_c_i.append(tas_i)
tas_c.append(tas_c_i)
tas_c_model.append(model)
print(tas_c_model)
print(tas_c)