質問編集履歴
1
npyを作成したコードを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -47,4 +47,40 @@
|
|
47
47
|
773 return array
|
48
48
|
|
49
49
|
ValueError: cannot reshape array of size 743050334 into shape (2768,512,1024)
|
50
|
+
```
|
51
|
+
|
52
|
+
以下追記したソースコードですが、ここでは読み込んだ画像をndarrayに変換した後、512*1024のサイズになるようpadding(画像によって元々のサイズが違うため)した後、追加した軸に沿って画像2,768枚をstackしています。
|
53
|
+
```python
|
54
|
+
import glob
|
55
|
+
import sunpy.map
|
56
|
+
import numpy as np
|
57
|
+
import matplotlib.pyplot as plt
|
58
|
+
import cv2
|
59
|
+
import math
|
60
|
+
from google.colab import drive
|
61
|
+
drive.mount('/content/drive', force_remount=True)
|
62
|
+
|
63
|
+
f_list = sorted(glob.glob('drive/My Drive/study/201005/*.magnetogram.fits'))
|
64
|
+
x_pad = 512
|
65
|
+
y_pad = 1024
|
66
|
+
|
67
|
+
input_data = np.array(sunpy.map.Map(f_list[0]).data)
|
68
|
+
pad_top = int((y_pad / 2) - math.floor(input_data.shape[1] / 2))
|
69
|
+
pad_bottom = int((y_pad / 2) - math.ceil(input_data.shape[1] / 2))
|
70
|
+
pad_left = int((x_pad / 2) - math.floor(input_data.shape[0] / 2))
|
71
|
+
pad_right = int((x_pad / 2) - math.ceil(input_data.shape[0] / 2))
|
72
|
+
|
73
|
+
input_data = np.pad(input_data, [(pad_left, pad_right), (pad_top, pad_bottom)], 'constant')
|
74
|
+
input_data = input_data[np.newaxis, :, :]
|
75
|
+
print(input_data.shape)
|
76
|
+
for i in range(len(f_list)-1):
|
77
|
+
tmp = np.array((sunpy.map.Map(f_list[i+1])).data)
|
78
|
+
pad_top = int((y_pad / 2) - math.floor(tmp.shape[1] / 2))
|
79
|
+
pad_bottom = int((y_pad / 2) - math.ceil(tmp.shape[1] / 2))
|
80
|
+
pad_left = int((x_pad / 2) - math.floor(tmp.shape[0] / 2))
|
81
|
+
pad_right = int((x_pad / 2) - math.ceil(tmp.shape[0] / 2))
|
82
|
+
tmp = np.pad(tmp, [(pad_left, pad_right), (pad_top, pad_bottom)], 'constant')
|
83
|
+
input_data = np.vstack([input_data, tmp[np.newaxis, :, :]])
|
84
|
+
print(input_data.shape)
|
85
|
+
np.save('drive/My Drive/study/temp_201005_All', input_data)
|
50
86
|
```
|