mwdust 1.6__cp314-cp314-macosx_10_13_x86_64.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.
Potentially problematic release.
This version of mwdust might be problematic. Click here for more details.
- healpix_c.cpython-314-darwin.so +0 -0
- mwdust/Combined15.py +61 -0
- mwdust/Combined19.py +62 -0
- mwdust/Drimmel03.py +293 -0
- mwdust/DustMap3D.py +99 -0
- mwdust/Green15.py +83 -0
- mwdust/Green17.py +85 -0
- mwdust/Green19.py +84 -0
- mwdust/HierarchicalHealpixMap.py +224 -0
- mwdust/Marshall06.py +265 -0
- mwdust/SFD.py +72 -0
- mwdust/Sale14.py +217 -0
- mwdust/Zero.py +63 -0
- mwdust/Zucker25.py +107 -0
- mwdust/__init__.py +27 -0
- mwdust/util/__init__.py +0 -0
- mwdust/util/combine_dustmaps19.py +202 -0
- mwdust/util/download.py +32 -0
- mwdust/util/extCurves/apj398709t6_ascii.txt +51 -0
- mwdust/util/extCurves/extinction.tbl +44 -0
- mwdust/util/extCurves.py +65 -0
- mwdust/util/fortranfile.py +260 -0
- mwdust/util/healpix.py +440 -0
- mwdust/util/read_Drimmel.py +55 -0
- mwdust/util/read_SFD.py +129 -0
- mwdust/util/tools.py +31 -0
- mwdust-1.6.dist-info/METADATA +265 -0
- mwdust-1.6.dist-info/RECORD +33 -0
- mwdust-1.6.dist-info/WHEEL +6 -0
- mwdust-1.6.dist-info/licenses/AUTHORS.txt +8 -0
- mwdust-1.6.dist-info/licenses/LICENSE +27 -0
- mwdust-1.6.dist-info/top_level.txt +4 -0
- sfd_c.cpython-314-darwin.so +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Table 6
|
|
2
|
+
F99 Reddening in Different Bandpasses
|
|
3
|
+
|
|
4
|
+
Bandpass lambda_eff R_V Bandpass lambda_eff R_V
|
|
5
|
+
2.1 3.1 4.1 5.1 2.1 3.1 4.1 5.1
|
|
6
|
+
Landolt U 3508.2 5.614 4.334 3.773 3.460 WFPC2 F300W 3087.6 6.777 4.902 4.127 3.710
|
|
7
|
+
Landolt B 4329.0 4.355 3.626 3.290 3.096 WFPC2 F450W 4587.0 4.014 3.410 3.132 2.971
|
|
8
|
+
Landolt V 5421.7 2.953 2.742 2.645 2.589 WFPC2 F555W 5439.4 2.976 2.755 2.653 2.594
|
|
9
|
+
Landolt R 6427.8 2.124 2.169 2.189 2.201 WFPC2 F606W 5984.8 2.469 2.415 2.389 2.375
|
|
10
|
+
Landolt I 8048.4 1.410 1.505 1.548 1.573 WFPC2 F702W 6887.9 1.850 1.948 1.994 2.020
|
|
11
|
+
CTIO U 3733.9 5.170 4.107 3.628 3.355 WFPC2 F814W 7940.0 1.452 1.549 1.594 1.620
|
|
12
|
+
CTIO B 4308.9 4.382 3.641 3.300 3.104 WFC3 F105W 10438.9 0.981 0.969 0.964 0.961
|
|
13
|
+
CTIO V 5516.6 2.857 2.682 2.600 2.553 WFC3 F110W 11169.7 0.907 0.881 0.870 0.863
|
|
14
|
+
CTIO R 6520.2 2.055 2.119 2.149 2.166 WFC3 F125W 12335.5 0.778 0.726 0.701 0.687
|
|
15
|
+
CTIO I 8006.9 1.420 1.516 1.561 1.587 WFC3 F140W 13692.3 0.672 0.613 0.586 0.570
|
|
16
|
+
UKIRT J 12482.9 0.764 0.709 0.684 0.669 WFC3 F160W 15258.3 0.570 0.512 0.485 0.469
|
|
17
|
+
UKIRT H 16588.4 0.502 0.449 0.425 0.411 WFC3 F200LP 5515.2 3.457 2.958 2.743 2.625
|
|
18
|
+
UKIRT K 21897.7 0.331 0.302 0.288 0.280 WFC3 F218W 2248.3 12.405 7.760 5.956 5.027
|
|
19
|
+
UKIRT L" 37772.5 0.159 0.153 0.150 0.148 WFC3 F225W 2394.0 10.907 6.989 5.458 4.666
|
|
20
|
+
Gunn g 5200.0 3.225 2.914 2.770 2.687 WFC3 F275W 2742.5 7.986 5.487 4.488 3.963
|
|
21
|
+
Gunn r 6628.5 1.959 2.055 2.099 2.125 WFC3 F300X 2934.5 7.437 5.228 4.331 3.854
|
|
22
|
+
Gunn i 7898.6 1.454 1.555 1.601 1.628 WFC3 F336W 3366.4 5.835 4.453 3.853 3.519
|
|
23
|
+
Gunn z 9050.1 1.188 1.234 1.255 1.267 WFC3 F350LP 5877.1 2.876 2.624 2.509 2.443
|
|
24
|
+
Spinrad R_S 6927.3 1.810 1.921 1.972 2.002 WFC3 F390W 3994.8 4.803 3.896 3.481 3.244
|
|
25
|
+
Stromgren u 3510.0 5.539 4.305 3.759 3.452 WFC3 F438W 4335.3 4.347 3.623 3.288 3.095
|
|
26
|
+
Stromgren b 4670.5 3.916 3.350 3.089 2.938 WFC3 F475W 4785.0 3.755 3.248 3.013 2.878
|
|
27
|
+
Stromgren v 4119.2 4.619 3.793 3.411 3.191 WFC3 F475X 4969.7 3.548 3.116 2.917 2.803
|
|
28
|
+
Stromgren beta 4861.3 3.655 3.183 2.966 2.840 WFC3 F555W 5302.8 3.135 2.855 2.726 2.652
|
|
29
|
+
Stromgren y 5478.9 2.862 2.686 2.605 2.557 WFC3 F600LP 7362.3 1.688 1.781 1.824 1.849
|
|
30
|
+
SDSS u 3586.8 5.419 4.239 3.715 3.419 WFC3 F606W 5868.5 2.581 2.488 2.445 2.421
|
|
31
|
+
SDSS g 4716.7 3.843 3.303 3.054 2.910 WFC3 F625W 6225.8 2.230 2.259 2.273 2.281
|
|
32
|
+
SDSS r 6165.1 2.255 2.285 2.300 2.308 WFC3 F775W 7630.9 1.533 1.643 1.694 1.724
|
|
33
|
+
SDSS i 7475.9 1.583 1.698 1.751 1.782 WFC3 F814W 7983.1 1.441 1.536 1.580 1.605
|
|
34
|
+
SDSS z 8922.9 1.211 1.263 1.286 1.300 WFC3 F850LP 9149.7 1.168 1.208 1.226 1.237
|
|
35
|
+
DSS-II g 4620.6 3.970 3.381 3.110 2.954 ACS clear 6211.1 2.612 2.436 2.356 2.309
|
|
36
|
+
DSS-II r 6545.5 1.991 2.088 2.133 2.159 ACS F435W 4348.3 4.330 3.610 3.278 3.087
|
|
37
|
+
DSS-II i 8111.0 1.396 1.487 1.530 1.554 ACS F475W 4760.3 3.787 3.268 3.028 2.890
|
|
38
|
+
PS1 g 4876.7 3.634 3.172 2.958 2.835 ACS F550M 5581.0 2.754 2.620 2.558 2.522
|
|
39
|
+
PS1 r 6200.1 2.241 2.271 2.284 2.292 ACS F555W 5361.3 3.031 2.792 2.682 2.618
|
|
40
|
+
PS1 i 7520.8 1.568 1.682 1.734 1.765 ACS F606W 5901.0 2.555 2.471 2.431 2.409
|
|
41
|
+
PS1 z 8665.3 1.258 1.322 1.352 1.369 ACS F625W 6298.1 2.171 2.219 2.241 2.254
|
|
42
|
+
PS1 y 9706.3 1.074 1.087 1.094 1.097 ACS F775W 7673.5 1.520 1.629 1.679 1.708
|
|
43
|
+
PS1 w 6240.8 2.425 2.341 2.302 2.280 ACS F814W 8012.4 1.432 1.526 1.569 1.594
|
|
44
|
+
LSST u 3693.2 5.243 4.145 3.652 3.373 ACS F850LP 9007.5 1.196 1.243 1.265 1.277
|
|
45
|
+
LSST g 4797.3 3.739 3.237 3.006 2.872 DES g 4796.6 3.739 3.237 3.006 2.872
|
|
46
|
+
LSST r 6195.8 2.245 2.273 2.286 2.294 DES r 6382.6 2.113 2.176 2.205 2.221
|
|
47
|
+
LSST i 7515.3 1.571 1.684 1.737 1.767 DES i 7769.0 1.490 1.595 1.644 1.672
|
|
48
|
+
LSST z 8664.4 1.259 1.323 1.353 1.370 DES z 9108.2 1.175 1.217 1.236 1.247
|
|
49
|
+
LSST y 9710.3 1.075 1.088 1.094 1.098 DES Y 9850.4 1.051 1.058 1.061 1.063
|
|
50
|
+
|
|
51
|
+
Notes. Ab/E(B - V)SFD in different bandpasses b, evaluated according to an F99 reddening law with normalization N = 0.78 and RV = 2.1, 3.1, 4.1, and 5.1, using a 7000 K source spectrum. The column lambdaeff gives the throughput-weighted mean wavelength in the bandpass. When used with RV = 3.1, these give the coefficients to use with E(B - V)SFD to get reddenings consistent with the results of this work and Schlafly et al. (2010). The values for other RV are provided only for convenience.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
\Coordinates = 180. 0. gal ( 86.404890000 28.936160000 equ J2000)
|
|
2
|
+
\E(B-V)_SFD_1998 = 1.418 (mag)
|
|
3
|
+
\SandF: Schlafly and Finkbeiner 2011 (ApJ 737, 103)
|
|
4
|
+
\SFD: Schlegel et al. 1998 (ApJ 500, 525)
|
|
5
|
+
\ Filter_name
|
|
6
|
+
\ ___ Name of filter
|
|
7
|
+
\ LamEff
|
|
8
|
+
\ ___ Effective wavelength of filter (in microns) as defined in SandF
|
|
9
|
+
\ A_over_E_B_V_SandF
|
|
10
|
+
\ ___ Ratio of SandF band extinction to SandF E(B-V)
|
|
11
|
+
\ A_SandF
|
|
12
|
+
\ ___ Band extinction (mags) for SandF
|
|
13
|
+
\ A_over_E_B_V_SFD
|
|
14
|
+
\ ___ Ratio of SFD band extinction to SandF E(B-V)
|
|
15
|
+
\ A_SFD
|
|
16
|
+
\ ___ Band extinction (mags) for SFD
|
|
17
|
+
|Filter_name |LamEff |A_over_E_B_V_SandF |A_SandF |A_over_E_B_V_SFD |A_SFD |
|
|
18
|
+
|char |float |float |float |float |float |
|
|
19
|
+
| |microns | |mags | |mags |
|
|
20
|
+
CTIO U 0.3734 4.107 5.824 4.968 7.045
|
|
21
|
+
CTIO B 0.4309 3.641 5.164 4.325 6.134
|
|
22
|
+
CTIO V 0.5517 2.682 3.804 3.240 4.595
|
|
23
|
+
CTIO R 0.6520 2.119 3.005 2.634 3.735
|
|
24
|
+
CTIO I 0.8007 1.516 2.150 1.962 2.782
|
|
25
|
+
DSS-II g 0.4621 3.381 4.795 3.907 5.541
|
|
26
|
+
DSS-II r 0.6546 2.088 2.961 2.649 3.757
|
|
27
|
+
DSS-II i 0.8111 1.487 2.109 1.893 2.685
|
|
28
|
+
SDSS u 0.3587 4.239 6.012 5.155 7.311
|
|
29
|
+
SDSS g 0.4717 3.303 4.684 3.793 5.379
|
|
30
|
+
SDSS r 0.6165 2.285 3.241 2.751 3.901
|
|
31
|
+
SDSS i 0.7476 1.698 2.408 2.086 2.958
|
|
32
|
+
SDSS z 0.8923 1.263 1.791 1.479 2.097
|
|
33
|
+
UKIRT J 1.248 0.709 1.005 0.902 1.279
|
|
34
|
+
UKIRT H 1.659 0.449 0.637 0.576 0.817
|
|
35
|
+
UKIRT K 2.190 0.302 0.428 0.367 0.520
|
|
36
|
+
2MASS J 1.23 0.723 1.025 0.937 1.329
|
|
37
|
+
2MASS H 1.64 0.460 0.652 0.591 0.838
|
|
38
|
+
2MASS Ks 2.16 0.310 0.440 0.382 0.542
|
|
39
|
+
IRAC-1 3.52 0.178 0.252 0.220 0.312
|
|
40
|
+
IRAC-2 4.46 0.148 0.210 0.183 0.260
|
|
41
|
+
IRAC-3 5.66 0.130 0.184 0.162 0.230
|
|
42
|
+
IRAC-4 7.68 0.122 0.173 0.151 0.214
|
|
43
|
+
WISE-1 3.32 0.189 0.268 0.234 0.332
|
|
44
|
+
WISE-2 4.57 0.146 0.207 0.180 0.255
|
mwdust/util/extCurves.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import os, os.path
|
|
3
|
+
import numpy
|
|
4
|
+
|
|
5
|
+
#A / E(B-v)
|
|
6
|
+
avebv= {}
|
|
7
|
+
avebvsf= {}
|
|
8
|
+
def _read_extCurves():
|
|
9
|
+
"""Read the extinction curves files in extCurves"""
|
|
10
|
+
extFile= open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
11
|
+
'extCurves','extinction.tbl'),'r')
|
|
12
|
+
global avebv
|
|
13
|
+
global avebvsf
|
|
14
|
+
for line in extFile:
|
|
15
|
+
if line[0] == '\\': continue
|
|
16
|
+
if line[0] == '|': continue
|
|
17
|
+
vals= re.split('\s\s+',line)
|
|
18
|
+
avebv[vals[0].strip()]= float(vals[4])
|
|
19
|
+
avebvsf[vals[0].strip()]= float(vals[2])
|
|
20
|
+
# Add filters from Schlafly & Finkbeiner
|
|
21
|
+
extFile= open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
22
|
+
'extCurves','apj398709t6_ascii.txt'),'r')
|
|
23
|
+
cnt= 0
|
|
24
|
+
for line in extFile:
|
|
25
|
+
cnt+= 1
|
|
26
|
+
if cnt < 6: continue
|
|
27
|
+
if cnt > 49: break
|
|
28
|
+
vals= line.split()
|
|
29
|
+
# Each line has 2 filters
|
|
30
|
+
filter1= '%s %s' % (vals[0],vals[1])
|
|
31
|
+
if not filter1 in avebv:
|
|
32
|
+
avebv[filter1]= numpy.nan
|
|
33
|
+
avebvsf[filter1]= float(vals[4])
|
|
34
|
+
filter2= '%s %s' % (vals[7],vals[8])
|
|
35
|
+
if not filter2 in avebv:
|
|
36
|
+
avebv[filter2]= numpy.nan
|
|
37
|
+
avebvsf[filter2]= float(vals[11])
|
|
38
|
+
|
|
39
|
+
_read_extCurves()
|
|
40
|
+
|
|
41
|
+
def aebv(filter,sf10=True):
|
|
42
|
+
"""
|
|
43
|
+
NAME:
|
|
44
|
+
aebv
|
|
45
|
+
PURPOSE:
|
|
46
|
+
return A_filter / E(B-V), necessary to turn SFD E(B-V) into total extinctions
|
|
47
|
+
INPUT:
|
|
48
|
+
filter - filter to use (e.g., '2MASS Ks')
|
|
49
|
+
sf10= (True) if True, use the values from Schlafly & Finkbeiner 2010, which use an updated extinction law, source spectrum, and recalibrated SFD map
|
|
50
|
+
OUTPUT:
|
|
51
|
+
A_filter / E(B-V)
|
|
52
|
+
HISTORY:
|
|
53
|
+
2013-11-24 - Written - Bovy (IAS)
|
|
54
|
+
"""
|
|
55
|
+
if filter.lower() == 'e(b-v)':
|
|
56
|
+
return 0.884
|
|
57
|
+
if sf10:
|
|
58
|
+
if not filter in avebvsf:
|
|
59
|
+
raise ValueError("Requested filter is not supported")
|
|
60
|
+
else:
|
|
61
|
+
return avebvsf[filter]
|
|
62
|
+
else:
|
|
63
|
+
if not filter in avebv:
|
|
64
|
+
raise ValueError("Requested filter is not supported")
|
|
65
|
+
return avebv[filter]
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Copyright 2008-2010 Neil Martinsen-Burrell
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
# Copyright 2018 Jo Bovy
|
|
22
|
+
#
|
|
23
|
+
# Made small changes to allow this module to be used in Python 3, but only
|
|
24
|
+
# to be able to read the files used in the mwdust package. Keep the same
|
|
25
|
+
# license as above
|
|
26
|
+
"""Defines a file-derived class to read/write Fortran unformatted files.
|
|
27
|
+
|
|
28
|
+
The assumption is that a Fortran unformatted file is being written by
|
|
29
|
+
the Fortran runtime as a sequence of records. Each record consists of
|
|
30
|
+
an integer (of the default size [usually 32 or 64 bits]) giving the
|
|
31
|
+
length of the following data in bytes, then the data itself, then the
|
|
32
|
+
same integer as before.
|
|
33
|
+
|
|
34
|
+
Examples
|
|
35
|
+
--------
|
|
36
|
+
|
|
37
|
+
To use the default endian and precision settings, one can just do::
|
|
38
|
+
>>> f = FortranFile('filename')
|
|
39
|
+
>>> x = f.readReals()
|
|
40
|
+
|
|
41
|
+
One can read arrays with varying precisions::
|
|
42
|
+
>>> f = FortranFile('filename')
|
|
43
|
+
>>> x = f.readInts('h')
|
|
44
|
+
>>> y = f.readInts('q')
|
|
45
|
+
>>> z = f.readReals('f')
|
|
46
|
+
Where the format codes are those used by Python's struct module.
|
|
47
|
+
|
|
48
|
+
One can change the default endian-ness and header precision::
|
|
49
|
+
>>> f = FortranFile('filename', endian='>', header_prec='l')
|
|
50
|
+
for a file with little-endian data whose record headers are long
|
|
51
|
+
integers.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
__docformat__ = "restructuredtext en"
|
|
55
|
+
import sys
|
|
56
|
+
_PY3= sys.version > '3'
|
|
57
|
+
if _PY3:
|
|
58
|
+
from io import FileIO
|
|
59
|
+
file= FileIO
|
|
60
|
+
import numpy
|
|
61
|
+
|
|
62
|
+
class FortranFile(file):
|
|
63
|
+
|
|
64
|
+
"""File with methods for dealing with fortran unformatted data files"""
|
|
65
|
+
|
|
66
|
+
def _get_header_length(self):
|
|
67
|
+
return numpy.dtype(self._header_prec).itemsize
|
|
68
|
+
_header_length = property(fget=_get_header_length)
|
|
69
|
+
|
|
70
|
+
def _set_endian(self,c):
|
|
71
|
+
"""Set endian to big (c='>') or little (c='<') or native (c='=')
|
|
72
|
+
|
|
73
|
+
:Parameters:
|
|
74
|
+
`c` : string
|
|
75
|
+
The endian-ness to use when reading from this file.
|
|
76
|
+
"""
|
|
77
|
+
if c in '<>@=':
|
|
78
|
+
if c == '@':
|
|
79
|
+
c = '='
|
|
80
|
+
self._endian = c
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError('Cannot set endian-ness')
|
|
83
|
+
def _get_endian(self):
|
|
84
|
+
return self._endian
|
|
85
|
+
ENDIAN = property(fset=_set_endian,
|
|
86
|
+
fget=_get_endian,
|
|
87
|
+
doc="Possible endian values are '<', '>', '@', '='"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def _set_header_prec(self, prec):
|
|
91
|
+
if prec in 'hilq':
|
|
92
|
+
self._header_prec = prec
|
|
93
|
+
else:
|
|
94
|
+
raise ValueError('Cannot set header precision')
|
|
95
|
+
def _get_header_prec(self):
|
|
96
|
+
return self._header_prec
|
|
97
|
+
HEADER_PREC = property(fset=_set_header_prec,
|
|
98
|
+
fget=_get_header_prec,
|
|
99
|
+
doc="Possible header precisions are 'h', 'i', 'l', 'q'"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def __init__(self, fname, endian='@', header_prec='i', *args, **kwargs):
|
|
103
|
+
"""Open a Fortran unformatted file for writing.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
endian : character, optional
|
|
108
|
+
Specify the endian-ness of the file. Possible values are
|
|
109
|
+
'>', '<', '@' and '='. See the documentation of Python's
|
|
110
|
+
struct module for their meanings. The deafult is '>' (native
|
|
111
|
+
byte order)
|
|
112
|
+
header_prec : character, optional
|
|
113
|
+
Specify the precision used for the record headers. Possible
|
|
114
|
+
values are 'h', 'i', 'l' and 'q' with their meanings from
|
|
115
|
+
Python's struct module. The default is 'i' (the system's
|
|
116
|
+
default integer).
|
|
117
|
+
|
|
118
|
+
"""
|
|
119
|
+
file.__init__(self, fname, *args, **kwargs)
|
|
120
|
+
self.ENDIAN = endian
|
|
121
|
+
self.HEADER_PREC = header_prec
|
|
122
|
+
|
|
123
|
+
def _read_exactly(self, num_bytes):
|
|
124
|
+
"""Read in exactly num_bytes, raising an error if it can't be done."""
|
|
125
|
+
if _PY3:
|
|
126
|
+
data = b''
|
|
127
|
+
else:
|
|
128
|
+
data = ''
|
|
129
|
+
while True:
|
|
130
|
+
l = len(data)
|
|
131
|
+
if l == num_bytes:
|
|
132
|
+
return data
|
|
133
|
+
else:
|
|
134
|
+
read_data = self.read(num_bytes - l)
|
|
135
|
+
if read_data == '':
|
|
136
|
+
raise IOError('Could not read enough data.'
|
|
137
|
+
' Wanted %d bytes, got %d.' % (num_bytes, l))
|
|
138
|
+
data += read_data
|
|
139
|
+
|
|
140
|
+
def _read_check(self):
|
|
141
|
+
return numpy.frombuffer(
|
|
142
|
+
self._read_exactly(self._header_length),
|
|
143
|
+
dtype=self.ENDIAN + self.HEADER_PREC,
|
|
144
|
+
)[0]
|
|
145
|
+
|
|
146
|
+
def _write_check(self, number_of_bytes):
|
|
147
|
+
"""Write the header for the given number of bytes"""
|
|
148
|
+
self.write(numpy.array(number_of_bytes,
|
|
149
|
+
dtype=self.ENDIAN+self.HEADER_PREC,).tostring()
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def readRecord(self):
|
|
153
|
+
"""Read a single fortran record"""
|
|
154
|
+
l = self._read_check()
|
|
155
|
+
data_str = self._read_exactly(l)
|
|
156
|
+
check_size = self._read_check()
|
|
157
|
+
if check_size != l:
|
|
158
|
+
raise IOError('Error reading record from data file')
|
|
159
|
+
return data_str
|
|
160
|
+
|
|
161
|
+
def writeRecord(self,s):
|
|
162
|
+
"""Write a record with the given bytes.
|
|
163
|
+
|
|
164
|
+
Parameters
|
|
165
|
+
----------
|
|
166
|
+
s : the string to write
|
|
167
|
+
|
|
168
|
+
"""
|
|
169
|
+
length_bytes = len(s)
|
|
170
|
+
self._write_check(length_bytes)
|
|
171
|
+
self.write(s)
|
|
172
|
+
self._write_check(length_bytes)
|
|
173
|
+
|
|
174
|
+
def readString(self):
|
|
175
|
+
"""Read a string."""
|
|
176
|
+
return self.readRecord()
|
|
177
|
+
|
|
178
|
+
def writeString(self,s):
|
|
179
|
+
"""Write a string
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
s : the string to write
|
|
184
|
+
|
|
185
|
+
"""
|
|
186
|
+
self.writeRecord(s)
|
|
187
|
+
|
|
188
|
+
_real_precisions = 'df'
|
|
189
|
+
|
|
190
|
+
def readReals(self, prec='f'):
|
|
191
|
+
"""Read in an array of real numbers.
|
|
192
|
+
|
|
193
|
+
Parameters
|
|
194
|
+
----------
|
|
195
|
+
prec : character, optional
|
|
196
|
+
Specify the precision of the array using character codes from
|
|
197
|
+
Python's struct module. Possible values are 'd' and 'f'.
|
|
198
|
+
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
_numpy_precisions = {'d': numpy.float64,
|
|
202
|
+
'f': numpy.float32
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if prec not in self._real_precisions:
|
|
206
|
+
raise ValueError('Not an appropriate precision')
|
|
207
|
+
|
|
208
|
+
data_str = self.readRecord()
|
|
209
|
+
return numpy.frombuffer(data_str, dtype=self.ENDIAN + prec)
|
|
210
|
+
|
|
211
|
+
def writeReals(self, reals, prec='f'):
|
|
212
|
+
"""Write an array of floats in given precision
|
|
213
|
+
|
|
214
|
+
Parameters
|
|
215
|
+
----------
|
|
216
|
+
reals : array
|
|
217
|
+
Data to write
|
|
218
|
+
prec` : string
|
|
219
|
+
Character code for the precision to use in writing
|
|
220
|
+
"""
|
|
221
|
+
if prec not in self._real_precisions:
|
|
222
|
+
raise ValueError('Not an appropriate precision')
|
|
223
|
+
|
|
224
|
+
nums = numpy.array(reals, dtype=self.ENDIAN+prec)
|
|
225
|
+
self.writeRecord(nums.tostring())
|
|
226
|
+
|
|
227
|
+
_int_precisions = 'hilq'
|
|
228
|
+
|
|
229
|
+
def readInts(self, prec='i'):
|
|
230
|
+
"""Read an array of integers.
|
|
231
|
+
|
|
232
|
+
Parameters
|
|
233
|
+
----------
|
|
234
|
+
prec : character, optional
|
|
235
|
+
Specify the precision of the data to be read using
|
|
236
|
+
character codes from Python's struct module. Possible
|
|
237
|
+
values are 'h', 'i', 'l' and 'q'
|
|
238
|
+
|
|
239
|
+
"""
|
|
240
|
+
if prec not in self._int_precisions:
|
|
241
|
+
raise ValueError('Not an appropriate precision')
|
|
242
|
+
|
|
243
|
+
data_str = self.readRecord()
|
|
244
|
+
return numpy.frombuffer(data_str, dtype=self.ENDIAN + prec)
|
|
245
|
+
|
|
246
|
+
def writeInts(self, ints, prec='i'):
|
|
247
|
+
"""Write an array of integers in given precision
|
|
248
|
+
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
reals : array
|
|
252
|
+
Data to write
|
|
253
|
+
prec : string
|
|
254
|
+
Character code for the precision to use in writing
|
|
255
|
+
"""
|
|
256
|
+
if prec not in self._int_precisions:
|
|
257
|
+
raise ValueError('Not an appropriate precision')
|
|
258
|
+
|
|
259
|
+
nums = numpy.array(ints, dtype=self.ENDIAN+prec)
|
|
260
|
+
self.writeRecord(nums.tostring())
|