-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrite_metadata.py
70 lines (59 loc) · 1.53 KB
/
write_metadata.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
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 12 08:02:07 2024
@author: Anne Hids (RIVM)
"""
import os
# Set working directory to where the scripts are located
os.chdir("N:/Documents/MyFolder")
import config
import datetime
#%% Write a metadatafile
# Delete the file if it already exists
if config.OS_env == 'win':
mdfilename = "output\\metadata.txt"
else:
mdfilename = "/output/metadata.txt"
# Ensure the output directory exists
os.makedirs(os.path.dirname(mdfilename), exist_ok=True)
# Delete the file if it already exists
if os.path.isfile(mdfilename):
try:
os.remove(mdfilename)
except OSError as e:
print(f"Error: {e.strerror} - {e.filename}")
# Create a new file
f = open(mdfilename, "x")
# Get the date and time
d = datetime.datetime.now()
dt = d.strftime('%d-%m-%Y %H:%M:%S')
# Write the file
f.write("Metadatafile for the DPMFA model")
f.write("\n")
f.write("\n")
f.write("Start date and time: ")
f.write(dt)
f.write("\n")
f.write("\n")
f.write("Configurations:")
f.write("\n")
f.write("\n")
f.write("Region: " + config.reg)
f.write("\n")
f.write("Startyear: " + str(config.startyear))
f.write("\n")
f.write("Endyear: " + str(config.endyear))
f.write("\n")
f.write("Runs: " + str(config.RUNS))
f.write("\n")
f.write("Model type: " + str(config.model_type))
f.write("\n")
f.write("Seed: " + str(config.seed))
f.write("\n")
f.write("Maininputfile version: " + str(config.inputfile))
f.write("\n")
f.write("NL_nested: " + str(config.NL_nested))
f.write("\n")
f.write("\n")
f.write("End")
f.close()