christophschirninger commited on
Commit
2b2b44a
·
1 Parent(s): 7a0dd51

clean up code

Browse files
Files changed (1) hide show
  1. flaring/data/iti_data_processing.py +14 -10
flaring/data/iti_data_processing.py CHANGED
@@ -1,4 +1,8 @@
1
  import collections.abc
 
 
 
 
2
  collections.Iterable = collections.abc.Iterable
3
  collections.Mapping = collections.abc.Mapping
4
  collections.MutableSet = collections.abc.MutableSet
@@ -6,15 +10,11 @@ collections.MutableMapping = collections.abc.MutableMapping
6
  # Now import hyper
7
  import numpy as np
8
  from astropy.visualization import ImageNormalize, AsinhStretch
9
- from itipy.data.dataset import SDODataset, StackDataset, get_intersecting_files, AIADataset
10
- from itipy.data.editor import LoadMapEditor, NormalizeRadiusEditor, MapToDataEditor, AIAPrepEditor, \
11
- BrightestPixelPatchEditor
12
  import os
13
- import glob
14
- from multiprocessing import Pool, cpu_count
15
- import tqdm as tqdm
16
- import multiprocessing as mp
17
- from functools import partial
18
 
19
  # Configuration for all wavelengths to process
20
  wavelengths = [94, 131, 171, 193, 211, 304]
@@ -31,6 +31,7 @@ sdo_norms = {
31
  '304': ImageNormalize(vmin=0, vmax=np.float32(401.82352), stretch=AsinhStretch(0.001), clip=True),
32
  }
33
 
 
34
  class SDODataset_flaring(StackDataset):
35
  """
36
  Dataset for SDO data
@@ -43,19 +44,22 @@ class SDODataset_flaring(StackDataset):
43
  ext (str): File extension
44
  **kwargs: Additional arguments
45
  """
 
46
  def __init__(self, data, patch_shape=None, wavelengths=None, resolution=2048, ext='.fits', **kwargs):
47
  wavelengths = [171, 193, 211, 304, 6173, ] if wavelengths is None else wavelengths
48
  if isinstance(data, list):
49
  paths = data
50
  else:
51
  paths = get_intersecting_files(data, wavelengths, ext=ext, **kwargs)
52
- ds_mapping = {94:AIADataset, 131: AIADataset, 171: AIADataset, 193: AIADataset, 211: AIADataset, 304: AIADataset}
 
53
  data_sets = [ds_mapping[wl_id](files, wavelength=wl_id, resolution=resolution, ext=ext)
54
  for wl_id, files in zip(wavelengths, paths)]
55
  super().__init__(data_sets, **kwargs)
56
  if patch_shape is not None:
57
  self.addEditor(BrightestPixelPatchEditor(patch_shape))
58
 
 
59
  aia_dataset = SDODataset_flaring(data=base_input_folder, wavelengths=wavelengths, resolution=512)
60
 
61
  def save_sample(i):
@@ -66,4 +70,4 @@ def save_sample(i):
66
  np.save(file_path, data)
67
 
68
  with Pool(processes=90) as pool:
69
- list(tqdm.tqdm(pool.imap(save_sample, range(len(aia_dataset))), total=len(aia_dataset)))
 
1
  import collections.abc
2
+ import shutil
3
+
4
+ import pandas as pd
5
+
6
  collections.Iterable = collections.abc.Iterable
7
  collections.Mapping = collections.abc.Mapping
8
  collections.MutableSet = collections.abc.MutableSet
 
10
  # Now import hyper
11
  import numpy as np
12
  from astropy.visualization import ImageNormalize, AsinhStretch
13
+ from itipy.data.dataset import StackDataset, get_intersecting_files, AIADataset
14
+ from itipy.data.editor import LoadMapEditor, NormalizeRadiusEditor, MapToDataEditor, BrightestPixelPatchEditor
 
15
  import os
16
+ from multiprocessing import Pool
17
+ from tqdm import tqdm
 
 
 
18
 
19
  # Configuration for all wavelengths to process
20
  wavelengths = [94, 131, 171, 193, 211, 304]
 
31
  '304': ImageNormalize(vmin=0, vmax=np.float32(401.82352), stretch=AsinhStretch(0.001), clip=True),
32
  }
33
 
34
+
35
  class SDODataset_flaring(StackDataset):
36
  """
37
  Dataset for SDO data
 
44
  ext (str): File extension
45
  **kwargs: Additional arguments
46
  """
47
+
48
  def __init__(self, data, patch_shape=None, wavelengths=None, resolution=2048, ext='.fits', **kwargs):
49
  wavelengths = [171, 193, 211, 304, 6173, ] if wavelengths is None else wavelengths
50
  if isinstance(data, list):
51
  paths = data
52
  else:
53
  paths = get_intersecting_files(data, wavelengths, ext=ext, **kwargs)
54
+ ds_mapping = {94: AIADataset, 131: AIADataset, 171: AIADataset, 193: AIADataset, 211: AIADataset,
55
+ 304: AIADataset}
56
  data_sets = [ds_mapping[wl_id](files, wavelength=wl_id, resolution=resolution, ext=ext)
57
  for wl_id, files in zip(wavelengths, paths)]
58
  super().__init__(data_sets, **kwargs)
59
  if patch_shape is not None:
60
  self.addEditor(BrightestPixelPatchEditor(patch_shape))
61
 
62
+
63
  aia_dataset = SDODataset_flaring(data=base_input_folder, wavelengths=wavelengths, resolution=512)
64
 
65
  def save_sample(i):
 
70
  np.save(file_path, data)
71
 
72
  with Pool(processes=90) as pool:
73
+ list(tqdm(pool.imap(save_sample, range(len(aia_dataset))), total=len(aia_dataset)))