Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ssp-software
data-access-tools
Commits
95a4d11d
Commit
95a4d11d
authored
Jun 21, 2022
by
michitaro
Browse files
la2016
parent
d9ed72ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
la2016/colorPostage/.gitignore
View file @
95a4d11d
/.venv
/coords.txt
/png2
/png3
\ No newline at end of file
la2016/colorPostage/colorPostage.py
View file @
95a4d11d
...
...
@@ -16,32 +16,27 @@
'''
import
PIL.Image
import
numpy
import
argparse
import
tarfile
import
subprocess
import
tempfile
import
getpass
import
os
import
os.path
import
os
,
os
.
path
import
contextlib
import
logging
logging
.
basicConfig
(
level
=
logging
.
INFO
)
import
logging
;
logging
.
basicConfig
(
level
=
logging
.
INFO
)
try
:
import
pyfits
import
pyfits
# type: ignore
except
:
import
astropy.io.fits
as
pyfits
FLUXMAG0
=
10
**
(
27
/
2.5
)
import
astropy.io.fits
as
pyfits
# type: ignore
import
numpy
import
PIL.Image
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--outDir'
,
'-o'
,
required
=
True
)
parser
.
add_argument
(
'--user'
,
'-u'
,
required
=
True
)
parser
.
add_argument
(
'--filters'
,
'-f'
,
nargs
=
3
,
default
=
[
'HSC-I'
,
'HSC-R'
,
'HSC-G'
])
parser
.
add_argument
(
'--filters'
,
'-f'
,
nargs
=
3
,
default
=
[
'HSC-I'
,
'HSC-R'
,
'HSC-G'
])
parser
.
add_argument
(
'--fov'
,
default
=
'30asec'
)
parser
.
add_argument
(
'--rerun'
,
default
=
'any'
,
choices
=
'la2016 la2014'
.
split
())
...
...
@@ -49,7 +44,7 @@ def main():
parser
.
add_argument
(
'input'
,
type
=
argparse
.
FileType
(
'r'
))
args
=
parser
.
parse_args
()
password
=
getpass
.
getpass
(
'Password
:
'
)
password
=
os
.
environ
.
get
(
'HSC_PASSWORD'
)
or
getpass
.
getpass
(
'Password
?
'
)
checkPassword
(
args
.
user
,
password
)
coords
,
outs
=
loadCoords
(
args
.
input
)
...
...
@@ -67,13 +62,13 @@ def main():
makeColorPng
(
rgb
,
outFile
,
args
.
color
)
TOP_PAGE
=
'https://hscla.mtk.nao.ac.jp/das_cutout/la201
4
/'
API
=
'https://hscla.mtk.nao.ac.jp/das_cutout/la201
4
/cgi-bin/cutout'
TOP_PAGE
=
'https://hscla.mtk.nao.ac.jp/das_cutout/la201
6
/'
API
=
'https://hscla.mtk.nao.ac.jp/das_cutout/la201
6
/cgi-bin/cutout'
def
loadCoords
(
input
):
import
re
comment
=
re
.
compile
(
'\s*(?:$|#)'
)
comment
=
re
.
compile
(
r
'\s*(?:$|#)'
)
num
=
1
coords
=
[]
outs
=
[]
...
...
@@ -100,8 +95,7 @@ def requestFileFor(coords, filters, fov, rerun):
tmp
.
write
(
'#? filter ra dec sw sh rerun
\n
'
.
encode
(
'utf-8'
))
for
coord
in
coords
:
for
filterName
in
filters
:
tmp
.
write
(
'{} {} {} {} {} {}
\n
'
.
format
(
filterName
,
coord
[
0
],
coord
[
1
],
fov
,
fov
,
rerun
).
encode
())
tmp
.
write
(
'{} {} {} {} {} {}
\n
'
.
format
(
filterName
,
coord
[
0
],
coord
[
1
],
fov
,
fov
,
rerun
).
encode
())
tmp
.
flush
()
yield
tmp
.
name
...
...
@@ -109,7 +103,7 @@ def requestFileFor(coords, filters, fov, rerun):
def
batch
(
arr
,
n
):
i
=
0
while
i
<
len
(
arr
):
yield
arr
[
i
:
i
+
n
]
yield
arr
[
i
:
i
+
n
]
i
+=
n
...
...
@@ -129,7 +123,9 @@ def rgbBundle(files):
dst
=
locals
()[
ch
]
copyFileObj
(
fileObj
,
dst
)
rgb
[
ch
]
=
dst
.
name
yield
objNum
,
rgb
if
len
(
rgb
)
>
0
:
yield
objNum
,
rgb
def
copyFileObj
(
src
,
dst
):
...
...
@@ -140,8 +136,7 @@ def copyFileObj(src, dst):
def
checkPassword
(
user
,
password
):
with
tempfile
.
NamedTemporaryFile
()
as
netrc
:
netrc
.
write
(
'machine hscla.mtk.nao.ac.jp login {} password {}'
.
format
(
user
,
password
).
encode
(
'ascii'
))
netrc
.
write
(
'machine hscla.mtk.nao.ac.jp login {} password {}'
.
format
(
user
,
password
).
encode
(
'ascii'
))
netrc
.
flush
()
httpCode
=
subprocess
.
check_output
(
[
'curl'
,
'--netrc-file'
,
netrc
.
name
,
'-o'
,
os
.
devnull
,
'-w'
,
'%{http_code}'
,
'-s'
,
TOP_PAGE
]).
strip
()
...
...
@@ -151,13 +146,11 @@ def checkPassword(user, password):
def
queryTar
(
user
,
password
,
requestFile
):
with
tempfile
.
NamedTemporaryFile
()
as
netrc
:
netrc
.
write
(
'machine hscla.mtk.nao.ac.jp login {} password {}'
.
format
(
user
,
password
).
encode
(
'ascii'
))
netrc
.
write
(
'machine hscla.mtk.nao.ac.jp login {} password {}'
.
format
(
user
,
password
).
encode
(
'ascii'
))
netrc
.
flush
()
pipe
=
subprocess
.
Popen
([
'curl'
,
'--netrc-file'
,
netrc
.
name
,
'-L'
,
# '--dump-header', '-',
'--form'
,
'list=@{}'
.
format
(
requestFile
),
'--silent'
,
API
,
...
...
@@ -165,9 +158,14 @@ def queryTar(user, password, requestFile):
with
tarfile
.
open
(
fileobj
=
pipe
.
stdout
,
mode
=
'r|*'
)
as
tar
:
while
True
:
info
=
tar
.
next
()
if
info
is
None
:
break
try
:
info
=
tar
.
next
()
except
tarfile
.
StreamError
as
e
:
if
tar
.
offset
==
0
:
break
else
:
raise
if
info
is
None
:
break
logging
.
info
(
'extracting {}...'
.
format
(
info
.
name
))
f
=
tar
.
extractfile
(
info
)
yield
info
,
f
...
...
@@ -187,7 +185,7 @@ def makeColorPng(rgb, out, color):
for
i
,
ch
in
enumerate
(
'rgb'
):
if
ch
in
rgb
:
with
pyfits
.
open
(
rgb
[
ch
])
as
hdul
:
x
=
scale
(
hdul
[
1
].
data
,
FLUXMAG0
)
x
=
scale
(
hdul
[
1
].
data
,
hdul
[
0
].
header
[
'
FLUXMAG0
'
]
)
layers
[
i
]
=
x
if
color
==
'hsc'
:
...
...
la2016/colorPostage/test.bash
View file @
95a4d11d
cat
>
coords.txt
<<
EOT
# ra dec outfile(optional)
4.62630 16.44671 a.png
4.63742 16.44747 b.png
4.62537 16.44345 c.png
4.65146 16.44694 d.png
4.64854 16.44695 e.png
4.65057 16.44706 f.png
4.62701 16.44535 g.png
4.65151 16.44745 h.png
4.63186 16.44911 i.png
4.63830 16.44271 j.png
269.6323064579072 66.63089594376515 a.png
EOT
~/anaconda3
/bin/python colorPostage.py
--user
michitaro.nike@gmail.com
--outDir
png3 ./coords.txt
./.venv
/bin/python colorPostage.py
--user
michitaro.nike@gmail.com
--outDir
png3 ./coords.txt
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment