• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ouranosinc / miranda / 1809078825

pending completion
1809078825

Pull #24

github

GitHub
Merge 42678580a into 78afbb7fe
Pull Request #24: Add CMIP file structure - WIP

5 of 129 new or added lines in 17 files covered. (3.88%)

5 existing lines in 1 file now uncovered.

428 of 2079 relevant lines covered (20.59%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/miranda/structure/_structure.py
1
import datetime
×
2
import logging
×
3
import os
×
4
import shutil
×
5

6
import netCDF4
×
7

8
logging.basicConfig(
×
9
    filename="{}_cordex-na.log".format(
10
        datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
11
    ),
12
    level=logging.INFO,
13
)
14

15
path_origin = "/path/origin/"
×
16
path_move = "/path/move/"
×
17

18
rcm_institutions = {
×
19
    "CanRCM4": "CCCMA",
20
    "CRCM5": "UQAM",
21
    "CRCM5-UQAM": "UQAM",
22
    "HIRHAM5": "DMI",
23
    "RCA4": "SMHI",
24
    "RegCM4": "ISU",
25
    "WRF": "NCAR",
26
}
27

28
driving_institutions = {
×
29
    "CanESM2": "CCCMA",
30
    "CNRM-CM5": "CNRM-CERFACS",
31
    "CNRM-CM5-2": "CNRM-CERACS",
32
    "EC-EARTH": "ICHEC",
33
    "ERAINT": "ECMWF",
34
    "GEMatm-Can": "UQAM",
35
    "GEMatm-MPI": "UQAM",
36
    "GFDL-ESM2M": "NOAA-GFDL",
37
    "HadGEM2-ES": "MOHC",
38
    "MPI-ESM-LR": "MPI-M",
39
    "MPI-ESM-MR": "MPI-M",
40
}
41

42
for root, dirs, files in os.walk(path_origin):
×
43
    for nc_file in files:
×
44
        decode_name = nc_file.split(".")
×
45
        if decode_name[-1] != "nc":
×
46
            continue
×
47
        var_name = decode_name[0]
×
48
        experiment = decode_name[1]
×
49
        if experiment == "eval":
×
50
            experiment = "evaluation"
×
51
        elif experiment == "hist":
×
52
            experiment = "historical"
×
53
        driving_data = decode_name[2]
×
54
        if driving_data == "ERA-Int":
×
55
            driving_data = "ERAINT"
×
56
        rcm = decode_name[3]
×
57
        time_frequency = decode_name[4]
×
58
        domain = decode_name[5]
×
59
        bias_correction = decode_name[6]
×
60
        experiment_tag = "{}_{}-{}_{}".format(
×
61
            domain, driving_institutions[driving_data], driving_data, experiment
62
        )
63
        nc = netCDF4.Dataset(os.path.join(root, nc_file), "r")
×
64
        try:
×
65
            ensemble_member = nc.driving_model_ensemble_member
×
66
        except AttributeError:
×
67
            ensemble_member = "r1i1p1"
×
NEW
68
            logging.info("Guessing r1i1p1 for {}".format(os.path.join(root, nc_file)))
×
69

70
        nc.close()
×
71
        move_path = os.path.join(
×
72
            path_move,
73
            "CORDEX-NA",
74
            rcm_institutions[rcm],
75
            rcm,
76
            experiment_tag,
77
            time_frequency,
78
            "atmos",
79
            ensemble_member,
80
            bias_correction,
81
            var_name,
82
        )
83
        if not os.path.isdir(move_path):
×
84
            os.makedirs(move_path)
×
85
        shutil.move(os.path.join(root, nc_file), os.path.join(move_path, nc_file))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc