fits2tmp 0.1.6__tar.gz → 0.1.8__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.6
3
+ Version: 0.1.8
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.6"
3
+ version = "0.1.8"
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,8 @@ 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
8
+ from dask.distributed import Lock
7
9
  import numpy as np
8
10
  import os
9
11
  import dask
@@ -61,7 +63,9 @@ def fun(darr, destination, header, block_info=None):
61
63
  out = fits.PrimaryHDU(data=darr, header=n_header)
62
64
  outpath = destination.name + '/' + block_id + ".fits"
63
65
  out.writeto(outpath)
64
- filepath.append(outpath)
66
+ lock = Lock()
67
+ with lock:
68
+ filepath.append(outpath)
65
69
  return darr
66
70
 
67
71
  def fits2tmpfiles(inputpath, destination, chunks):
@@ -75,11 +79,38 @@ def fits2tmpfiles(inputpath, destination, chunks):
75
79
 
76
80
  return filepath
77
81
 
78
-
79
- def disk2darray(filetype, filepath, arraytype, arraysize, chunks=None):
82
+ @delayed
83
+ def disk2tmpfiles(filetype, inputpath, destination, arraytype, arraysize, chunks=None):
84
+ fpath = []
80
85
  match filetype:
81
86
  case "fits":
82
- foo
87
+ f = fits.open(inputpath)
88
+ d = da.from_array(f[0].data, chunks=chunks)
89
+ destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
90
+ n_header = dict2header(header_dict(f[0].header))
91
+ wcs_obj = wcs.WCS(n_header)
92
+ print(d.shape)
93
+ for i in range(d.blocks.shape[0]):
94
+ x = i * chunks[0]
95
+ x_delt = x + chunks[0] - 1
96
+ for j in range(d.blocks.shape[1]):
97
+ data = d.blocks[i][j]
98
+ y = j * chunks[1]
99
+ y_delt = y + chunks[1] - 1
100
+ if len(d.blocks.shape) == 2:
101
+ dest = str(i) + str(j)
102
+ wcs_coords = wcs_obj.slice((slice(x,x_delt), slice(y,y_delt)))
103
+ elif len(d.blocks.shape) > 2:
104
+ for k in range(d.blocks.shape[2]):
105
+ data = d.blocks[i][j][k]
106
+ z = k * chunks[2]
107
+ z_delt = z + chunks[2] - 1
108
+ dest = str(i) + str(j) + str(k)
109
+ t =wcs_obj[x:x_delt, y:y_delt, z:z_delt]
110
+ n_header.update(t.to_header())
111
+ hdu = fits.PrimaryHDU(data=data, header=n_header)
112
+ hdu.writeto(destination.name + dest + "fits")
113
+ fpath.append(destination.name + dest + "fits")
83
114
  case "zarr":
84
115
  bar
85
116
  case "hdf5":
@@ -88,8 +119,7 @@ def disk2darray(filetype, filepath, arraytype, arraysize, chunks=None):
88
119
  weeble
89
120
  case _:
90
121
  raise ValueError("The specified file type is not supported by fits2tmp.")
91
- return array
92
-
122
+ return fpath
93
123
 
94
124
  #def array2disk(array, metadata, outputtype, destination):
95
125
 
File without changes
File without changes