fits2tmp 0.1.9__tar.gz → 0.3.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.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.3
2
+ Name: fits2tmp
3
+ Version: 0.3.0
4
+ Summary: A way of loading FITS files into temporary filesystems to make them available in memory.
5
+ License: BSD-3-Clause
6
+ Author: Verity Allan
7
+ Author-email: vla22@cam.ac.uk
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: astropy (>=6.1.4,<7.0.0)
16
+ Requires-Dist: dask[distributed] (>=2025.1.0,<2026.0.0)
17
+ Requires-Dist: h5py (>=3.12.1,<4.0.0)
18
+ Requires-Dist: numpy (>=2.1.2,<3.0.0)
19
+ Requires-Dist: pytest (>=8.3.3,<9.0.0)
20
+ Requires-Dist: zarr (>=2.18.3,<3.0.0)
21
+ Project-URL: Repository, https://gitlab.developers.cam.ac.uk/phy/ra/vla22-phd/fits2tmp
22
+ Description-Content-Type: text/markdown
23
+
24
+ # fits2tmp
25
+
26
+ This project allows you to take a large FITS file and render it as a set of smaller FITS files stored in-memory in a temporary directory, with appropriately updated headers.
27
+ The program returns a list of the location of these files, which can then be processed by a parallel processing framework such as dask.
28
+
29
+ The program also allows you to turn a zarr file containing your FITS data into small FITS files, provided you have extracted the FITS file header to a text file.
30
+ Utilities in the program can be used to write headers out to or read them from a text file.
31
+
32
+ ## TODO:
33
+
34
+ - Add a utility to convert FITS files to zarr, including saving the header out to a text file.
35
+ - Add hdf5 support using a similar strategy to FITS.
36
+ - Add xradio support.
37
+
38
+ ## Installing fits2tmp
39
+
40
+ The program is available from pypi so can be installed with pip: `pip install fits2tmp`.
41
+
42
+ ## Example Usage
43
+
44
+ ```
45
+ import fits2tmp as f2t
46
+
47
+ a = fakefits2tmpfiles("fits", "/path/to/input/data", "/path/to/temporary/filesystem", "path/to/header/", (100, 100, 100), chunks=(20,20,20))
48
+ ```
49
+
50
+
@@ -0,0 +1,26 @@
1
+ # fits2tmp
2
+
3
+ This project allows you to take a large FITS file and render it as a set of smaller FITS files stored in-memory in a temporary directory, with appropriately updated headers.
4
+ The program returns a list of the location of these files, which can then be processed by a parallel processing framework such as dask.
5
+
6
+ The program also allows you to turn a zarr file containing your FITS data into small FITS files, provided you have extracted the FITS file header to a text file.
7
+ Utilities in the program can be used to write headers out to or read them from a text file.
8
+
9
+ ## TODO:
10
+
11
+ - Add a utility to convert FITS files to zarr, including saving the header out to a text file.
12
+ - Add hdf5 support using a similar strategy to FITS.
13
+ - Add xradio support.
14
+
15
+ ## Installing fits2tmp
16
+
17
+ The program is available from pypi so can be installed with pip: `pip install fits2tmp`.
18
+
19
+ ## Example Usage
20
+
21
+ ```
22
+ import fits2tmp as f2t
23
+
24
+ a = fakefits2tmpfiles("fits", "/path/to/input/data", "/path/to/temporary/filesystem", "path/to/header/", (100, 100, 100), chunks=(20,20,20))
25
+ ```
26
+
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fits2tmp"
3
- version = "0.1.9"
3
+ version = "0.3.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,85 @@ def fits2tmpfiles(inputpath, destination, chunks):
79
79
 
80
80
  return filepath
81
81
 
82
- def disk2fakefits(filetype, inputpath, destination, arraysize, chunks=None):
82
+ def disk2dah(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
+ # TODO make this support arrays that have other than 3 dims
86
+ destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
83
87
  match filetype:
84
88
  case "fits":
85
89
  f = fits.open(inputpath)
86
- d = da.from_array(f[0].data, chunks=chunks)
87
- destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
90
+ d = da.from_array(f[0].data[0:arraysize[0], 0:arraysize[1], 0:arraysize[2]], chunks=chunks)
88
91
  n_header = dict2header(header_dict(f[0].header))
89
92
  wcs_obj = wcs.WCS(n_header)
90
93
  case "zarr":
91
- bar
94
+ d = da.from_zarr(inputpath, chunks=chunks)[arraysize]
95
+ n_header = dict2header(file2dict(inputpath, headerloc))
96
+ wcs_obj = wcs.WCS(n_header)
92
97
  case "hdf5":
93
- baz
98
+ f = h5py.File(filepath, "r")
99
+ #note this is hardcoded for the particular hdf5 files tested - needs parameterisation
100
+ d = da.from_array(f["array"][arraysize], chunks=chunks)
101
+ n_header = dict2header(file2dict(inputpath, headerloc))
102
+ wcs_obj = wcs.WCS(n_header)
103
+
94
104
  case "xradio":
95
105
  weeble
96
106
  case _:
97
107
  raise ValueError("The specified file type is not supported by fits2tmp.")
98
- return d, destination, n_header, wcs_obj
108
+ return [d, destination, n_header, wcs_obj]
99
109
 
100
- def fakefits2tmpfiles(filetype, inputpath, destination, arraysize, chunks=None):
101
- darr, tempdest, n_header, wcs_obj = disk2fakefits(filetype, inputpath, destination, arraysize, chunks)
110
+ def fakefits2tmpfiles(filetype, inputpath, destination, arraysize, headerloc=None, chunks=None, overlap=None):
111
+ inputarray = disk2dah(filetype, inputpath, destination, headerloc, arraysize, chunks)
112
+ if overlap == None:
113
+ overlap = [0,0,0]
114
+ darr = inputarray[0]
102
115
  print(darr.shape)
103
- dd = darr.to_delayed()
116
+ print(darr)
117
+ destination = inputarray[1]
118
+ header = inputarray[2]
119
+ print(header)
120
+ wcs_obj = inputarray[3]
121
+ print(len(darr.chunks))
122
+ # why am I pushing this array to delayed? ans: to parallelise construction of the list
123
+ #dd = darr.to_delayed()
104
124
  fpaths = []
105
- for i in range(dd.shape[0]):
106
- x = i * chunks[0]
107
- x_delt = x + chunks[0] - 1
108
- for j in range(dd.shape[1]):
109
- y = j * chunks[1]
110
- y_delt = y + chunks[1] - 1
111
- if len(dd.shape) == 2:
125
+ for i in range(len(darr.chunks[0])):
126
+ x = i * chunks[0] - overlap[0]
127
+ x_delt = (i* chunks[0]) + chunks[0] + overlap[0]
128
+ # range check - when asking for overlap, we curtail at the edges of the array
129
+ if x < 0:
130
+ x = 0
131
+ if x_delt > arraysize[0] -1:
132
+ x_delt = arraysize[0]
133
+ print(x, x_delt)
134
+ for j in range(len(darr.chunks[1])):
135
+ y = j * chunks[1] - overlap[1]
136
+ y_delt = (j * chunks[1]) + chunks[1] + overlap[1]
137
+ if y < 0:
138
+ y = 0
139
+ if y_delt > arraysize[1] -1:
140
+ y_delt = arraysize[1]
141
+ if len(darr.shape) == 2:
112
142
  dest = str(i) + str(j)
113
143
  data = dd[i][j]
114
144
  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]):
117
- data = dd[i][j][k]
118
- z = k * chunks[2]
119
- 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")
145
+ elif len(darr.shape) > 2:
146
+ for k in range(len(darr.chunks[2])):
147
+ z = k * chunks[2] - overlap[2]
148
+ z_delt = (k * chunks[2]) + chunks[2] + overlap[2]
149
+ if z < 0:
150
+ z = 0
151
+ if z_delt > arraysize[2] -1:
152
+ z_delt = arraysize[2]
153
+ data = darr[x:x_delt, y:y_delt, z:z_delt]
154
+ print(data.shape)
155
+ dest = '-' + str(i) +'-' + str(j) + '-' + str(k)
156
+ t = wcs_obj[x:x_delt, y:y_delt, z:z_delt]
157
+ header.update(t.to_header())
158
+ hdu = fits.PrimaryHDU(data=data.compute(), header=header)
159
+ hdu.writeto(destination.name + dest + "fits")
160
+ fpaths.append(destination.name + dest + "fits")
126
161
  return fpaths
127
162
  #def array2disk(array, metadata, outputtype, destination):
128
163
 
fits2tmp-0.1.9/PKG-INFO DELETED
@@ -1,31 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: fits2tmp
3
- Version: 0.1.9
4
- Summary: A way of loading FITS files into temporary filesystems to make them available in memory.
5
- Home-page: https://gitlab.developers.cam.ac.uk/phy/ra/vla22-phd/fits2tmp
6
- License: BSD-3-Clause
7
- Author: Verity Allan
8
- Author-email: vla22@cam.ac.uk
9
- Requires-Python: >=3.10,<4.0
10
- Classifier: License :: OSI Approved :: BSD License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Requires-Dist: astropy (>=6.1.4,<7.0.0)
15
- Requires-Dist: dask[distributed] (>=2025.1.0,<2026.0.0)
16
- Requires-Dist: h5py (>=3.12.1,<4.0.0)
17
- Requires-Dist: numpy (>=2.1.2,<3.0.0)
18
- Requires-Dist: pytest (>=8.3.3,<9.0.0)
19
- Requires-Dist: zarr (>=2.18.3,<3.0.0)
20
- Project-URL: Repository, https://gitlab.developers.cam.ac.uk/phy/ra/vla22-phd/fits2tmp
21
- Description-Content-Type: text/markdown
22
-
23
- # Sample GitLab Project
24
-
25
- This sample project shows how a project in GitLab looks for demonstration purposes. It contains issues, merge requests and Markdown files in many branches,
26
- named and filled with lorem ipsum.
27
-
28
- You can look around to get an idea how to structure your project and, when done, you can safely delete this project.
29
-
30
- [Learn more about creating GitLab projects.](https://docs.gitlab.com/ee/gitlab-basics/create-project.html)
31
-
fits2tmp-0.1.9/README.md DELETED
@@ -1,8 +0,0 @@
1
- # Sample GitLab Project
2
-
3
- This sample project shows how a project in GitLab looks for demonstration purposes. It contains issues, merge requests and Markdown files in many branches,
4
- named and filled with lorem ipsum.
5
-
6
- You can look around to get an idea how to structure your project and, when done, you can safely delete this project.
7
-
8
- [Learn more about creating GitLab projects.](https://docs.gitlab.com/ee/gitlab-basics/create-project.html)
File without changes