fits2tmp 0.1.7__tar.gz → 0.1.9__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.7
3
+ Version: 0.1.9
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
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Requires-Dist: astropy (>=6.1.4,<7.0.0)
15
- Requires-Dist: dask[complete] (>=2024.10.0,<2025.0.0)
15
+ Requires-Dist: dask[distributed] (>=2025.1.0,<2026.0.0)
16
16
  Requires-Dist: h5py (>=3.12.1,<4.0.0)
17
17
  Requires-Dist: numpy (>=2.1.2,<3.0.0)
18
18
  Requires-Dist: pytest (>=8.3.3,<9.0.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fits2tmp"
3
- version = "0.1.7"
3
+ version = "0.1.9"
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>"]
@@ -9,7 +9,7 @@ repository = "https://gitlab.developers.cam.ac.uk/phy/ra/vla22-phd/fits2tmp"
9
9
 
10
10
  [tool.poetry.dependencies]
11
11
  python = "^3.10"
12
- dask = {extras = ["complete"], version = "^2024.10.0"}
12
+ dask = {extras = ["distributed"], version = "^2025.1.0"}
13
13
  astropy = "^6.1.4"
14
14
  h5py = "^3.12.1"
15
15
  numpy = "^2.1.2"
@@ -4,6 +4,7 @@ import json
4
4
  from astropy.io import fits
5
5
  from astropy import wcs
6
6
  import dask.array as da
7
+ from dask import delayed
7
8
  from dask.distributed import Lock
8
9
  import numpy as np
9
10
  import os
@@ -78,11 +79,14 @@ def fits2tmpfiles(inputpath, destination, chunks):
78
79
 
79
80
  return filepath
80
81
 
81
-
82
- def disk2darray(filetype, filepath, arraytype, arraysize, chunks=None):
82
+ def disk2fakefits(filetype, inputpath, destination, arraysize, chunks=None):
83
83
  match filetype:
84
84
  case "fits":
85
- foo
85
+ f = fits.open(inputpath)
86
+ d = da.from_array(f[0].data, chunks=chunks)
87
+ destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
88
+ n_header = dict2header(header_dict(f[0].header))
89
+ wcs_obj = wcs.WCS(n_header)
86
90
  case "zarr":
87
91
  bar
88
92
  case "hdf5":
@@ -91,9 +95,35 @@ def disk2darray(filetype, filepath, arraytype, arraysize, chunks=None):
91
95
  weeble
92
96
  case _:
93
97
  raise ValueError("The specified file type is not supported by fits2tmp.")
94
- return array
95
-
96
-
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)
103
+ dd = darr.to_delayed()
104
+ 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:
112
+ dest = str(i) + str(j)
113
+ data = dd[i][j]
114
+ 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")
126
+ return fpaths
97
127
  #def array2disk(array, metadata, outputtype, destination):
98
128
 
99
129
  #def tmpfitsfile2disk(fitsfile, outputtype, destination):
File without changes
File without changes