-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCryoIO.py
More file actions
executable file
·60 lines (52 loc) · 2.02 KB
/
CryoIO.py
File metadata and controls
executable file
·60 lines (52 loc) · 2.02 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 25 02:51:08 2020
@author: NicoS
"""
import numpy as np
def openfile(filename,fileformat):
'''opens a binary file in desired format and returns it in float'''
with open((filename), 'rb') as fr:
data = np.fromfile(fr, dtype=fileformat)
data = np.array(data, dtype=float)
return data
def savebinaryfile(filename,filedata):
with open(filename,'wb') as writer:
writer.write(filedata)
def savenumpy(filename,nparray):
np.savez_compressed(filename,Map=nparray)
def readnumpy(name):
icemap = np.load(name)
icemap = np.array(icemap['Map'], dtype=float)
return icemap
def csv_columnexport(filename,filedata):
np.savetxt(filename, np.column_stack((filedata)), delimiter=",", fmt='%s')
def csv_rowexport(filename,filedata):
np.savetxt(filename, np.row_stack((filedata)), delimiter=",", fmt='%s')
class CryoDate:
def __init__ (self,year=2000,month=1,day=1):
self.year = year
self.month = month
self.day = day
self.strMonth = str(self.month).zfill(2)
self.strDay = str(self.day).zfill(2)
self.datestring = f'{self.year}{self.strMonth}{self.strDay}'
def datecalc(self):
''' calculates the day-month for a 366 day year'''
self.day += 1
if self.day==32 and (self.month==1 or self.month==3 or self.month==5 or self.month==7 or self.month==8 or self.month==10):
self.day=1
self.month += 1
elif self.day==31 and (self.month==4 or self.month==6 or self.month==9 or self.month==11):
self.day=1
self.month += 1
elif self.day==30 and self.month==2:
self.day=1
self.month += 1
elif self.day==32 and self.month == 12:
self.day = 1
self.month = 1
self.year +=1
self.strMonth = str(self.month).zfill(2)
self.strDay = str(self.day).zfill(2)
self.datestring = f'{self.year}{self.strMonth}{self.strDay}'