fits2tmp 0.1.0__py3-none-any.whl
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.
- fits2tmp-0.1.0.dist-info/LICENSE +28 -0
- fits2tmp-0.1.0.dist-info/METADATA +31 -0
- fits2tmp-0.1.0.dist-info/RECORD +11 -0
- fits2tmp-0.1.0.dist-info/WHEEL +4 -0
- src/fits2tmp/__init__.py +0 -0
- src/fits2tmp/fits2tmp.py +105 -0
- src/fits2tmp/sdc2_100.fits +2845 -9
- src/fits2tmp/sofiatestrewrite1002_cat.txt +31 -0
- src/fits2tmp/sofiatestrewrite1002_cat.xml +612 -0
- src/fits2tmp/sofiatestrewrite100_cat.txt +31 -0
- src/fits2tmp/sofiatestrewrite100_cat.xml +612 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Verity Allan
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fits2tmp
|
|
3
|
+
Version: 0.1.0
|
|
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[complete] (>=2024.10.0,<2025.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
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
src/fits2tmp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
src/fits2tmp/fits2tmp.py,sha256=v3vg7XXHLFFCSyHMu6dDa72lZqPn74tkk_nYXhYM6no,3363
|
|
3
|
+
src/fits2tmp/sdc2_100.fits,sha256=-1154P1-muCt9x1iycnbZd8yLqtlFrOSbJ1HXeatbHk,855360
|
|
4
|
+
src/fits2tmp/sofiatestrewrite1002_cat.txt,sha256=ksqBuW2MIUmMRGPMabHxoiA24vuknfHyfSccZF6nhjA,8624
|
|
5
|
+
src/fits2tmp/sofiatestrewrite1002_cat.xml,sha256=k2nJbCAzJ8UttI9iufQnSN8leEzsM7D85ZfwOcMFpjs,27739
|
|
6
|
+
src/fits2tmp/sofiatestrewrite100_cat.txt,sha256=k5bjtLfU_8VaHg5My1-VzS4QLpIHz4VAX-CQk0In8B4,8624
|
|
7
|
+
src/fits2tmp/sofiatestrewrite100_cat.xml,sha256=vlEDIiNls4xSPWbd93trR7grAWUWkjTg5OPqEfJ05Bw,27738
|
|
8
|
+
fits2tmp-0.1.0.dist-info/LICENSE,sha256=Ok-auf5W6wYUmfqD3NURQIvpq09FNV_fU39rYwCq8_4,1499
|
|
9
|
+
fits2tmp-0.1.0.dist-info/METADATA,sha256=cIsOcE5SutbiXZjIOIiXLzOXt5qS3R2GqAZHz8iVtpo,1344
|
|
10
|
+
fits2tmp-0.1.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
11
|
+
fits2tmp-0.1.0.dist-info/RECORD,,
|
src/fits2tmp/__init__.py
ADDED
|
File without changes
|
src/fits2tmp/fits2tmp.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import h5py
|
|
2
|
+
import zarr
|
|
3
|
+
import json
|
|
4
|
+
from astropy.io import fits
|
|
5
|
+
from astropy import wcs
|
|
6
|
+
import dask.array as da
|
|
7
|
+
import numpy as np
|
|
8
|
+
import os
|
|
9
|
+
import dask
|
|
10
|
+
import tempfile
|
|
11
|
+
|
|
12
|
+
def arr_size_check(source_arr, desired_arr: tuple) -> bool:
|
|
13
|
+
if len(source_arr.shape) < len(desired_arr):
|
|
14
|
+
raise ValueError("You've asked for an array with more dimensions than the array stored")
|
|
15
|
+
else:
|
|
16
|
+
for i in range(min(len(source_arr.shape), len(desired_arr))):
|
|
17
|
+
# using min here allows us to avoid an IndexError when we have more dimensions in the source array
|
|
18
|
+
j = source_arr.shape[i] - desired_arr[i]
|
|
19
|
+
if j < 0:
|
|
20
|
+
raise IndexError("Desired array size is larger than the stored array in at least position %s: source array has dimensions %s, and you have requested $s", i, source_arr.shape, desired_arr)
|
|
21
|
+
return True
|
|
22
|
+
|
|
23
|
+
#def fits_add_header(orig_header, sliced_data) -> fits.Header:
|
|
24
|
+
# coords = wcs.WCS(orig_header)
|
|
25
|
+
# new_header = orig_header
|
|
26
|
+
# new_header.update(coords[data_sli].to_header())
|
|
27
|
+
# return new_header
|
|
28
|
+
|
|
29
|
+
def header_dict(header) -> dict:
|
|
30
|
+
d = {}
|
|
31
|
+
for i in header.cards:
|
|
32
|
+
d[i.keyword] = i.value
|
|
33
|
+
return d
|
|
34
|
+
|
|
35
|
+
def dict2header(input_dict: dict) -> fits.Header:
|
|
36
|
+
nh = fits.Header(cards=input_dict)
|
|
37
|
+
return nh
|
|
38
|
+
|
|
39
|
+
def dict2file(input_dict: dict, filepath):
|
|
40
|
+
with open(filepath, 'w') as f:
|
|
41
|
+
f.write(json.dumps(input_dict))
|
|
42
|
+
|
|
43
|
+
def file2dict(input_file, filepath) -> dict:
|
|
44
|
+
with open(filepath, 'r') as j:
|
|
45
|
+
contents = json.loads(j.read())
|
|
46
|
+
return contents
|
|
47
|
+
filepath = []
|
|
48
|
+
|
|
49
|
+
def fun(darr, destination, header, block_info=None):
|
|
50
|
+
arr_loc = block_info[None]['array-location']
|
|
51
|
+
print(arr_loc)
|
|
52
|
+
ch_size = block_info[None]['chunk-shape']
|
|
53
|
+
chunk_loc = block_info[None]['chunk-location']
|
|
54
|
+
coords = []
|
|
55
|
+
for i in range(len(arr_loc)):
|
|
56
|
+
coords.append(slice(arr_loc[i][0],arr_loc[i][1]))
|
|
57
|
+
block_id = str(chunk_loc).replace(',', '-').replace('(', '-').replace(')', '').replace(' ', '')
|
|
58
|
+
n_header = dict2header(header_dict(header))
|
|
59
|
+
wcs_obj = wcs.WCS(n_header)
|
|
60
|
+
n_header.update(wcs_obj[coords].to_header())
|
|
61
|
+
out = fits.PrimaryHDU(data=darr, header=n_header)
|
|
62
|
+
outpath = destination.name + '/' + block_id + ".fits"
|
|
63
|
+
out.writeto(outpath)
|
|
64
|
+
filepath.append(outpath)
|
|
65
|
+
return darr
|
|
66
|
+
|
|
67
|
+
def fits2tmpfiles(inputpath, destination, chunks):
|
|
68
|
+
f = fits.open(inputpath)
|
|
69
|
+
destination = tempfile.TemporaryDirectory(dir=destination, delete=False)
|
|
70
|
+
d = da.from_array(f[0].data, chunks=chunks)
|
|
71
|
+
# TODO overlap
|
|
72
|
+
de = da.overlap.overlap(d, depth=None, boundary=None)
|
|
73
|
+
da.map_blocks(fun, d, destination, f[0].header, dtype=float).compute()
|
|
74
|
+
|
|
75
|
+
return filepath
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def disk2darray(filetype, filepath, arraytype, arraysize, chunks=None):
|
|
79
|
+
match filetype:
|
|
80
|
+
case "fits":
|
|
81
|
+
foo
|
|
82
|
+
case "zarr":
|
|
83
|
+
bar
|
|
84
|
+
case "hdf5":
|
|
85
|
+
baz
|
|
86
|
+
case "xradio":
|
|
87
|
+
weeble
|
|
88
|
+
case _:
|
|
89
|
+
raise ValueError("The specified file type is not supported by fits2tmp.")
|
|
90
|
+
return array
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
#def array2disk(array, metadata, outputtype, destination):
|
|
94
|
+
|
|
95
|
+
#def tmpfitsfile2disk(fitsfile, outputtype, destination):
|
|
96
|
+
|
|
97
|
+
#def tmpfitsfile2array(fitsfile, arraytype, arraysize, chunks=None):
|
|
98
|
+
|
|
99
|
+
#def makezarrmetadata(fitsheader):
|
|
100
|
+
|
|
101
|
+
#def makefitsmetadata(fitsheader, location):
|
|
102
|
+
|
|
103
|
+
#makehdf5metadata
|
|
104
|
+
|
|
105
|
+
#makexradiometadata
|