これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。
HTML ファイル生成日時: 2024/12/05 07:26:42.662 (台灣標準時)
JWST (James Webb Space Telescope) のデータを探し、欲しいデータが見つかったら、それをダウンロードするには、以下のようにすればよいようでござる。
まず、以下のようなスクリプトを用意するでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/13 20:03:40 (UT+8) daisuke> # # importing argparse module import argparse # importing sys module import sys # importing pathlib module import pathlib # importing datetime module import datetime # importing astropy module import astropy.units import astropy.coordinates # importing astroquery module import astroquery.esa.jwst # date/time now = datetime.datetime.now ().isoformat () # command name command = sys.argv[0] # constructing parser object descr = "searching JWST images available for download" parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('-o', '--output', default='', \ help='output file name') parser.add_argument ('-r', '--radius', type=float, default=1.0, \ help='search radius in arcmin (default: 1)') parser.add_argument ('ra', nargs=1, default='00h00m00.000s', \ help='RA of target object (default: 00h00m00.000s)') parser.add_argument ('dec', nargs=1, default='00d00m00.00s', \ help='Dec of target object (default: 00d00m00.000s)') # command-line argument analysis args = parser.parse_args () # input parameters file_output = args.output radius_arcmin = args.radius ra = args.ra[0] dec = args.dec[0] # units u_ha = astropy.units.hourangle u_deg = astropy.units.deg u_arcmin = astropy.units.arcmin # search radius radius = radius_arcmin * u_arcmin # coordinate coord = astropy.coordinates.SkyCoord (ra, dec, unit=(u_ha, u_deg), frame='icrs') # coordinate in hh:mm:ss.ss and dd:mm:ss.s format coord_str = coord.to_string (style='hmsdms') (coord_ra_str, coord_dec_str) = coord_str.split () coord_ra_deg = coord.ra.deg coord_dec_deg = coord.dec.deg # printing coordinate print (f'# Coordinate:') print (f'# RA: {coord_ra_str} = {coord_ra_deg} deg') print (f'# Dec: {coord_dec_str} = {coord_dec_deg} deg') # query jwst = astroquery.esa.jwst.Jwst.cone_search (coordinate=coord, radius=radius, \ async_job=True) # query result query_result = jwst.get_results () # writing query result with open (file_output, 'w') as fh: # writing header header = f'# obs. ID, calib. level, data type, instrument, energy band\n' fh.write (header) for i in range (len (query_result)): # if the data product is not image, then skip if (query_result["dataproducttype"][i] != 'image'): continue # coordinate coord = astropy.coordinates.SkyCoord (query_result["target_ra"][i], \ query_result["target_dec"][i], \ unit=(u_deg, u_deg), frame='icrs') # writing data into file record = f'{query_result["observationid"][i]:36s}' \ + f' {query_result["calibrationlevel"][i]:2d}' \ + f' {query_result["dataproducttype"][i]:5s}' \ + f' {query_result["instrument_name"][i]:12s}' \ + f' {query_result["energy_bandpassname"][i]:12s}' \ + f' {coord.ra.deg:8.3f} {coord.dec.deg:8.3f}\n' fh.write (record)
このスクリプトを実行して、指定した領域に公開されている JWST のデータが あるかどうかを調べてみるでござる。試しに、 M1 (Crab Nebula) のデータを 探してみることにするでござる。
% ./jwst_search.py -h usage: jwst_search.py [-h] [-o OUTPUT] [-r RADIUS] ra dec searching JWST images available for download positional arguments: ra RA of target object (default: 00h00m00.000s) dec Dec of target object (default: 00d00m00.000s) options: -h, --help show this help message and exit -o OUTPUT, --output OUTPUT output file name -r RADIUS, --radius RADIUS search radius in arcmin (default: 1) % ./jwst_search.py -o m1.txt 05:34:32 +22:00:52 # Coordinate: # RA: 05h34m32s = 83.63333333333331 deg # Dec: +22d00m52s = 22.014444444444443 deg INFO: Query finished. [astroquery.utils.tap.core] % ls -lF m1.txt -rw-r--r-- 1 daisuke taiwan 63207 May 14 07:50 m1.txt
検索結果を見てみるでござる。
% cat m1.txt # obs. ID, calib. level, data type, instrument, energy band jw01714001006_02103_00001_mirimage 2 image MIRI/IMAGE F1130W 83.636 22.016 jw01714006005_02101_00004_nrcalong 2 image NIRCAM/IMAGE F480M 83.636 22.016 jw01714006004_02101_00001_nrcb2 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714001003_02105_00002_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714001005_02105_00004_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714006001_02101_00001_nrca1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714006004_02101_00003_nrcblong 2 image NIRCAM/IMAGE F480M 83.636 22.016 jw01714006002_03101_00001_nrca1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714006005_02101_00001_nrcb1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714006003_02101_00004_nrca1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714006002_03101_00001_nrcb2 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714001003_02107_00003_mirimage 2 image MIRI/IMAGE F2100W 83.636 22.016 jw01714006004_02101_00002_nrca2 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714001002_02105_00004_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714001003_02105_00001_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714006003_02101_00006_nrcb1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714001008_02105_00002_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714001005_02105_00002_mirimage 2 image MIRI/IMAGE F1800W 83.636 22.016 jw01714006001_02101_00005_nrcb3 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714001002_02107_00003_mirimage 2 image MIRI/IMAGE F2100W 83.636 22.016 ..... jw01714006003_02101_00006_nrca1 2 image NIRCAM/IMAGE F150W2;F162M 83.636 22.016 jw01714-c1002_t001_miri_f1800w 3 image MIRI/IMAGE F1800W 83.636 22.016 jw01714-c1002_t001_miri_f2100w 3 image MIRI/IMAGE F2100W 83.636 22.016 jw01714-c1002_t001_miri_f1130w 3 image MIRI/IMAGE F1130W 83.636 22.016 jw01714-c1002_t001_miri_f560w 3 image MIRI/IMAGE F560W 83.636 22.016 jw01714004001_02101_00004_mirimage 2 image MIRI/IMAGE F770W 83.623 22.008 jw01714004001_02101_00002_mirimage 2 image MIRI/IMAGE F770W 83.623 22.008 jw01714004001_02103_00002_mirimage 2 image MIRI/IMAGE F1500W 83.623 22.008 jw01714-o004_t002_miri_f770w 3 image MIRI/IMAGE F770W 83.623 22.008 jw01714-o004_t002_miri_f2550w 3 image MIRI/IMAGE F2550W 83.623 22.008 jw01714-o004_t002_miri_f1500w 3 image MIRI/IMAGE F1500W 83.623 22.008 jw01714004001_02103_00004_mirimage 2 image MIRI/IMAGE F1500W 83.623 22.008 jw01714004001_02101_00001_mirimage 2 image MIRI/IMAGE F770W 83.623 22.008 jw01714004001_02105_00001_mirimage 2 image MIRI/IMAGE F2550W 83.623 22.008 jw01714004001_02105_00003_mirimage 2 image MIRI/IMAGE F2550W 83.623 22.008 jw01714004001_02105_00004_mirimage 2 image MIRI/IMAGE F2550W 83.623 22.008 jw01714004001_02105_00002_mirimage 2 image MIRI/IMAGE F2550W 83.623 22.008 jw01714004001_02103_00001_mirimage 2 image MIRI/IMAGE F1500W 83.623 22.008 jw01714004001_02103_00003_mirimage 2 image MIRI/IMAGE F1500W 83.623 22.008 jw01714004001_02101_00003_mirimage 2 image MIRI/IMAGE F770W 83.623 22.008
たくさんのデータがあるようでござる。一つ目の jw01714001006_02103_00001_mirimage という observation ID のデータを見 てみることにするでござる。以下のようなスクリプトを用意するでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/14 07:59:46 (UT+8) daisuke> # # importing argparse module import argparse # importing sys module import sys # importing pathlib module import pathlib # importing datetime module import datetime # importing astropy module import astropy.units import astropy.coordinates # importing astroquery module import astroquery.esa.jwst # date/time now = datetime.datetime.now ().isoformat () # command name command = sys.argv[0] # constructing parser object descr = "getting data product list of JWST data" parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('-i', '--obsid', default='', \ help='observation ID of JWST data') # command-line argument analysis args = parser.parse_args () # input parameters obsid = args.obsid # getting product list product_list = astroquery.esa.jwst.Jwst.get_product_list (observation_id=obsid) # printing product list print (f'# file name, product type, calib. level, availability') for i in range (len (product_list)): print (f'{product_list["filename"][i]:56s}', \ f'{product_list["producttype"][i]:10s}', \ f'{product_list["calibrationlevel"][i]:2d}', \ f'{product_list["public"][i]}')
このスクリプトを実行して、 observation ID "jw01714001006_02103_00001_mirimage" の data product の一覧 を得るでござる。
% ./jwst_productlist.py -h usage: jwst_productlist.py [-h] [-i OBSID] getting data product list of JWST data options: -h, --help show this help message and exit -i OBSID, --obsid OBSID observation ID of JWST data % ./jwst_productlist.py -i jw01714001006_02103_00001_mirimage # file name, product type, calib. level, availability jw01714001006_02103_00001_mirimage_cal.fits science 2 True jw01714001006_02103_00001_mirimage_cal.jpg preview 2 True jw01714001006_02103_00001_mirimage_i2d.fits science 2 True jw01714001006_02103_00001_mirimage_o001_crf.fits science 2 True jw01714001006_02103_00001_mirimage_o001_crf.jpg preview 2 True jw01714001006_02103_00001_mirimage_o001_crf_thumb.jpg thumbnail 2 True jw01714001006_02103_00001_mirimage_rate.fits science 2 True jw01714001006_02103_00001_mirimage_rate.jpg preview 2 True jw01714001006_02103_00001_mirimage_rate_thumb.jpg thumbnail 2 True jw01714001006_02103_00001_mirimage_rateints.fits science 2 True jw01714001006_02103_00001_mirimage_rateints.jpg preview 2 True jw01714001006_02103_00001_mirimage_rateints_thumb.jpg thumbnail 2 True jw01714001006_02103_00001_mirimage_uncal.fits science 1 True jw01714001006_02103_00001_mirimage_uncal.jpg preview 1 True jw01714001006_gs-acq1_2023055055034_cal.fits auxiliary 2 True jw01714001006_gs-acq1_2023055055034_stream.fits auxiliary 1 True jw01714001006_gs-acq1_2023055055034_uncal.fits auxiliary 1 True jw01714001006_gs-acq2_2023055055036_cal.fits auxiliary 2 True jw01714001006_gs-acq2_2023055055036_stream.fits auxiliary 1 True jw01714001006_gs-acq2_2023055055036_uncal.fits auxiliary 1 True ..... jw01714001006_gs-track_2023055062606_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055062759_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055062759_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055062759_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055062952_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055062952_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055062952_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055063158_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055063158_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055063158_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055063553_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055063553_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055063553_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055063839_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055063839_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055063839_uncal.fits auxiliary 1 True jw01714001006_gs-track_2023055064128_cal.fits auxiliary 2 True jw01714001006_gs-track_2023055064128_stream.fits auxiliary 1 True jw01714001006_gs-track_2023055064128_uncal.fits auxiliary 1 True jw01714_20240314t060102_pool.csv info 2 True
calibration level 2 の product type science のデータがダウンロードすべ きもののようでござる。 i2d のデータが re-sampled のデータのようなので、 "jw01714001006_02103_00001_mirimage_i2d.fits" というファイル 名のデータをダウンロードしてみるでござる。以下のようなスクリプトを準備 してみるでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/12 17:59:18 (UT+8) daisuke> # # importing argparse module import argparse # importing sys module import sys # importing pathlib module import pathlib # importing datetime module import datetime # importing astropy module import astropy.units import astropy.coordinates # importing astroquery module import astroquery.esa.jwst # date/time now = datetime.datetime.now ().isoformat () # command name command = sys.argv[0] # constructing parser object descr = "downloading JWST image" parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('files', nargs='+', default='', \ help='file names of JWST data') # command-line argument analysis args = parser.parse_args () # input parameters list_files = args.files # downloading data products for file_input in list_files: # downloading JWST image file_output = astroquery.esa.jwst.Jwst.get_product (file_name=file_input)
このスクリプトを実行してみるでござる。
% ./jwst_download.py -h usage: jwst_download.py [-h] files [files ...] downloading JWST image positional arguments: files file names of JWST data options: -h, --help show this help message and exit % ./jwst_download.py jw01714001006_02103_00001_mirimage_i2d.fits % ls -lF jw01714001006_02103_00001_mirimage_i2d.fits.gz -rw-r--r-- 1 daisuke taiwan 14927383 May 14 08:08 jw01714001006_02103_00001_mirimage_i2d.fits.gz
gzip で圧縮された FITS ファイルがダウンロードされたでござる。解凍する ために、以下のスクリプトを準備してみたでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/12 18:39:13 (UT+8) daisuke> # # importing argparse module import argparse # importing pathlib object import pathlib # importing gzip module import gzip # constructing parser object descr = "un-compressing gzip compressed file" parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('files', nargs='+', default='', \ help='files') # command-line argument analysis args = parser.parse_args () # input parameters list_files = args.files # processing file one-by-one for file_input in list_files: # printing status print (f'Now, processing file "{file_input}"...') # making pathlib object path_input = pathlib.Path (file_input) # if extension of file is not ".gz", then skip if not (path_input.suffix == '.gz'): # printing message print (f'WARNING:') print (f'WARNING: suffix of file "{file_input}" is not ".gz"!') print (f'WARNING: skipping...') print (f'WARNING:') # skipping continue # if the file does not exist, then skip if not (path_input.exists ()): # printing message print (f'WARNING:') print (f'WARNING: file "{file_input}" does not exist!') print (f'WARNING: skipping...') print (f'WARNING:') # skipping continue # output file name file_output = path_input.stem # printing status print (f' Now, creating file "{file_output}"...') # opening file for reading with gzip.open (file_input, 'rb') as fh_in: # reading data data = fh_in.read () # opening file for writing with open (file_output, 'wb') as fh_out: # writing data into file fh_out.write (data) # printing status print (f' Finished creating file "{file_output}"!') # printing status print (f'Finished processing file "{file_input}"!')
このスクリプトを実行してみるでござる。
% ./jwst_uncompress.py -h usage: jwst_uncompress.py [-h] files [files ...] un-compressing gzip compressed file positional arguments: files files options: -h, --help show this help message and exit % ./jwst_uncompress.py jw01714001006_02103_00001_mirimage_i2d.fits.gz Now, processing file "jw01714001006_02103_00001_mirimage_i2d.fits.gz"... Now, creating file "jw01714001006_02103_00001_mirimage_i2d.fits"... Finished creating file "jw01714001006_02103_00001_mirimage_i2d.fits"! Finished processing file "jw01714001006_02103_00001_mirimage_i2d.fits.gz"! % ls -lF jw01714001006_02103_00001_mirimage_i2d.fits* -rw-r--r-- 1 daisuke taiwan 29445120 May 14 08:12 jw01714001006_02103_00001_mirimage_i2d.fits -rw-r--r-- 1 daisuke taiwan 14927383 May 14 08:08 jw01714001006_02103_00001_mirimage_i2d.fits.gz
ダウンロードした FITS ファイルがどのようなものなのか調べてみるために、 以下のようなスクリプトを準備してみるでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/12 19:10:44 (UT+8) daisuke> # # importing argparse module import argparse # importing sys module import sys # importing pathlib module import pathlib # importing astropy module import astropy.io.fits # constructing parser object descr = 'showing structure of FITS files' parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('files', nargs='+', help='FITS files') # command-line argument analysis args = parser.parse_args () # file names list_files = args.files # processing files one-by-one for file_fits in list_files: # making pathlib object path_fits = pathlib.Path (file_fits) # if file is not a FITS file, then skip if not (path_fits.suffix == '.fits'): # printing message print (f'WARNING:') print (f'WARNING: file "{file_fits}" is not a FITS file!') print (f'WARNING: skipping') print (f'WARNING:') # skipping continue # if file does not exist, then skip if not (path_fits.exists ()): # printing message print (f'WARNING:') print (f'WARNING: file "{file_fits}" does not exist!') print (f'WARNING: skipping') print (f'WARNING:') # skipping continue # opening FITS file with astropy.io.fits.open (file_fits) as hdu: # printing HDU print (hdu.info ())
このスクリプトを実行してみるでござる。
% ./jwst_fitsstructure.py -h usage: jwst_fitsstructure.py [-h] files [files ...] showing structure of FITS files positional arguments: files FITS files options: -h, --help show this help message and exit % ./jwst_fitsstructure.py jw01714001006_02103_00001_mirimage_i2d.fits Filename: jw01714001006_02103_00001_mirimage_i2d.fits No. Name Ver Type Cards Dimensions Format 0 PRIMARY 1 PrimaryHDU 352 () 1 SCI 1 ImageHDU 75 (1029, 1019) float32 2 ERR 1 ImageHDU 10 (1029, 1019) float32 3 CON 1 ImageHDU 10 (1029, 1019, 1) int32 4 WHT 1 ImageHDU 9 (1029, 1019) float32 5 VAR_POISSON 1 ImageHDU 9 (1029, 1019) float32 6 VAR_RNOISE 1 ImageHDU 9 (1029, 1019) float32 7 VAR_FLAT 1 ImageHDU 9 (1029, 1019) float32 8 ASDF 1 BinTableHDU 11 1R x 1C [13514B] None
Primary HDU の次の HDU (Header Data Unit) が SCI となっているので、こ れが science data のようでござる。この部分を取り出してみるために、以下 のようなスクリプトを用意してみたでござる。
#!/usr/pkg/bin/python3.12 # # Time-stamp: <2024/05/12 19:20:59 (UT+8) daisuke> # # importing argparse module import argparse # importing sys module import sys # importing pathlib module import pathlib # importing astropy module import astropy.io.fits # constructing parser object descr = 'extracting science data from JWST FITS file' parser = argparse.ArgumentParser (description=descr) # adding arguments parser.add_argument ('-i', '--input', help='input file') parser.add_argument ('-o', '--output', help='output file') # command-line argument analysis args = parser.parse_args () # file names file_input = args.input file_output = args.output # making pathlib objects path_input = pathlib.Path (file_input) path_output = pathlib.Path (file_output) # if file is not a FITS file, then skip if not (path_input.suffix == '.fits'): # printing message print (f'WARNING:') print (f'WARNING: file "{file_input}" is not a FITS file!') print (f'WARNING: skipping') print (f'WARNING:') # exiting sys.exit (0) # if file is not a FITS file, then skip if not (path_output.suffix == '.fits'): # printing message print (f'WARNING:') print (f'WARNING: file "{file_output}" is not a FITS file!') print (f'WARNING: skipping') print (f'WARNING:') # exiting sys.exit (0) # if file does not exist, then skip if not (path_input.exists ()): # printing message print (f'WARNING:') print (f'WARNING: file "{file_input}" does not exist!') print (f'WARNING: skipping') print (f'WARNING:') # exiting sys.exit (0) # if file exists, then skip if (path_output.exists ()): # printing message print (f'WARNING:') print (f'WARNING: file "{file_output}" exists!') print (f'WARNING: skipping') print (f'WARNING:') # exiting sys.exit (0) # opening FITS file with astropy.io.fits.open (file_input) as hdu: # image of science data image = hdu[1].data # header of science data header = hdu[1].header # writing image and header into new file astropy.io.fits.writeto (file_output, image, header=header)
このスクリプトを実行してみるでござる。
% ./jwst_extractsci.py -h usage: jwst_extractsci.py [-h] [-i INPUT] [-o OUTPUT] extracting science data from JWST FITS file options: -h, --help show this help message and exit -i INPUT, --input INPUT input file -o OUTPUT, --output OUTPUT output file % ./jwst_extractsci.py -i jw01714001006_02103_00001_mirimage_i2d.fits -o m1_jwst_miri.fits % ls -lF *.fits -rw-r--r-- 1 daisuke taiwan 29445120 May 14 08:12 jw01714001006_02103_00001_mirimage_i2d.fits -rw-r--r-- 1 daisuke taiwan 4204800 May 14 08:18 m1_jwst_miri.fits
"m1_jwst_miri.fits" というファイルを Ginga を使って表示して みるでござる。
% ginga-3.12 m1_jwst_miri.fits
|
---|