fits2tmp 0.1.9__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fits2tmp
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: A way of loading FITS files into temporary filesystems to make them available in memory.
5
5
  Home-page: https://gitlab.developers.cam.ac.uk/phy/ra/vla22-phd/fits2tmp
6
6
  License: BSD-3-Clause
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fits2tmp"
3
- version = "0.1.9"
3
+ version = "0.2.0"
4
4
  description = "A way of loading FITS files into temporary filesystems to make them available in memory."
5
5
  license = "BSD-3-Clause"
6
6
  authors = ["Verity Allan <vla22@cam.ac.uk>"]
File without changes
@@ -79,50 +79,64 @@ def fits2tmpfiles(inputpath, destination, chunks):
79
79
 
80
80
  return filepath
81
81
 
82
- def disk2fakefits(filetype, inputpath, destination, arraysize, chunks=None):
82
+ def disk2fakefits(filetype, inputpath, destination, headerloc, arraysize, chunks=None):
83
+ # TODO: ADD code to handle arraysize differing from size of array in file
84
+ # maybe extend arr_size_check()?
85
+ destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
83
86
  match filetype:
84
87
  case "fits":
85
88
  f = fits.open(inputpath)
86
- d = da.from_array(f[0].data, chunks=chunks)
87
- destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
89
+ d = da.from_array(f[0].data[arraysize], chunks=chunks)
88
90
  n_header = dict2header(header_dict(f[0].header))
89
91
  wcs_obj = wcs.WCS(n_header)
90
92
  case "zarr":
91
- bar
93
+ d = da.from_zarr(inputpath, chunks=chunks)[arraysize]
94
+ n_header = dict2header(file2dict(inputpath, headerloc))
95
+ wcs_obj = wcs.WCS(n_header)
92
96
  case "hdf5":
93
- baz
97
+ f = h5py.File(filepath, "r")
98
+ #note this is hardcoded for the particular hdf5 files tested - needs parameterisation
99
+ d = da.from_array(f["array"][arraysize], chunks=chunks)
100
+ n_header = dict2header(file2dict(inputpath, headerloc))
101
+ wcs_obj = wcs.WCS(n_header)
102
+
94
103
  case "xradio":
95
104
  weeble
96
105
  case _:
97
106
  raise ValueError("The specified file type is not supported by fits2tmp.")
98
- return d, destination, n_header, wcs_obj
99
-
100
- def fakefits2tmpfiles(filetype, inputpath, destination, arraysize, chunks=None):
101
- darr, tempdest, n_header, wcs_obj = disk2fakefits(filetype, inputpath, destination, arraysize, chunks)
102
- print(darr.shape)
107
+ return [d, destination, n_header, wcs_obj]
108
+
109
+ def fakefits2tmpfiles(filetype, inputpath, destination, headerloc, arraysize, chunks=None):
110
+ inputarray = disk2fakefits(filetype, inputpath, destination, headerloc, arraysize, chunks)
111
+ darr = inputarray[0]
112
+ destination = inputarray[1]
113
+ header = inputarray[2]
114
+ wcs_obj = inputarray[3]
103
115
  dd = darr.to_delayed()
104
116
  fpaths = []
105
- for i in range(dd.shape[0]):
117
+ for i in range(len(darr.chunks[0])):
106
118
  x = i * chunks[0]
107
119
  x_delt = x + chunks[0] - 1
108
- for j in range(dd.shape[1]):
120
+ for j in range(len(darr.chunks[1])):
121
+ print(i,j)
109
122
  y = j * chunks[1]
110
123
  y_delt = y + chunks[1] - 1
111
- if len(dd.shape) == 2:
124
+ if len(darr.shape) == 2:
112
125
  dest = str(i) + str(j)
113
126
  data = dd[i][j]
114
127
  wcs_coords = wcs_obj.slice((slice(x,x_delt), slice(y,y_delt)))
115
- elif len(dd.shape) > 2:
116
- for k in range(dd.shape[2]):
128
+ elif len(darr.shape) > 2:
129
+ for k in range(len(darr.chunks[2])):
130
+ print(k)
117
131
  data = dd[i][j][k]
118
132
  z = k * chunks[2]
119
133
  z_delt = z + chunks[2] - 1
120
- dest = str(i) + str(j) + str(k)
121
- t =wcs_obj[x:x_delt, y:y_delt, z:z_delt]
122
- n_header.update(t.to_header())
123
- hdu = fits.PrimaryHDU(data=data.compute(), header=n_header)
124
- hdu.writeto(tempdest.name + dest + "fits")
125
- fpaths.append(tempdest.name + dest + "fits")
134
+ dest = '-' + str(i) +'-' + str(j) + '-' + str(k)
135
+ t = wcs_obj[x:x_delt, y:y_delt, z:z_delt]
136
+ header.update(t.to_header())
137
+ hdu = fits.PrimaryHDU(data=data.compute(), header=header)
138
+ hdu.writeto(destination.name + dest + "fits")
139
+ fpaths.append(destination.name + dest + "fits")
126
140
  return fpaths
127
141
  #def array2disk(array, metadata, outputtype, destination):
128
142
 
File without changes
File without changes