Commit 55b08ef2 authored by Nico Vermaas's avatar Nico Vermaas

added fits_to_png functionality

parent 7bee5121
......@@ -5,6 +5,7 @@
Description: atdb plot module
"""
import os
import datetime
import plotly
import plotly.graph_objs as go
......@@ -543,4 +544,39 @@ def do_time_used_science_pie_plot(title, subtitle, data):
plt.grid(True,alpha=0.3)
plt.legend(loc='upper right')
plt.show()
\ No newline at end of file
plt.show()
def fits_to_png_apercal(input_file_name,output_file_name):
import matplotlib.pyplot as plt
from astropy.wcs import WCS
from astropy.io import fits
import matplotlib.colors as mc
output = output_file_name
fits_file = input_file_name
# open continuum image
fits_hdulist = fits.open(fits_file)
# get WCS header of cube
wcs = WCS(fits_hdulist[0].header)
# remove unnecessary axis
if wcs.naxis == 4:
wcs = wcs.dropaxis(3)
wcs = wcs.dropaxis(2)
img = fits_hdulist[0].data[0][0]
elif wcs.naxis == 3:
wcs = wcs.dropaxis(2)
img = fits_hdulist[0].data[0]
else:
img = fits_hdulist[0].data
# set up plot
ax = plt.subplot(projection=wcs)
# add image using sym-log scaling
fig = ax.imshow(img * 1.e3, norm=mc.SymLogNorm(1.e-9, vmin=0.03, vmax=200), origin='lower')
# add colorbar
cbar = plt.colorbar(fig)
cbar.set_label('Flux Density [mJy/beam]')
ax.coords[0].set_axislabel('Right Ascension')
ax.coords[1].set_axislabel('Declination')
ax.coords[0].set_major_formatter('hh:mm')
ax.set_title("{0:s}".format(os.path.basename(fits_file)))
plt.savefig(output, overwrite=True, bbox_inches='tight', dpi=300)
\ No newline at end of file
......@@ -310,8 +310,9 @@ def do_times(args):
if result['ingest_speed'] is not None and result['ingest_speed'] > 0:
datapoint = {}
datapoint['taskid'] = result['taskID']
nofrag,frag = result['timestamp_ingesting'].split('.')
timestamp = datetime.datetime.strptime(nofrag, '%Y-%m-%dT%H:%M:%S')
# nofrag,frag = result['timestamp_ingesting'].split('.')
# timestamp = datetime.datetime.strptime(nofrag, '%Y-%m-%dT%H:%M:%S')
timestamp = datetime.datetime.strptime(result['timestamp_ingesting'], '%Y-%m-%dT%H:%M:%SZ')
datapoint['timestamp'] = timestamp
datapoint['type'] = 'ingesting'
datapoint['duration'] = result['ingest_duration']
......@@ -325,8 +326,9 @@ def do_times(args):
if result['timestamp_ingest_error'] is not None:
datapoint = {}
datapoint['taskid'] = result['taskID']
nofrag,frag = result['timestamp_ingest_error'].split('.')
timestamp = datetime.datetime.strptime(nofrag, '%Y-%m-%dT%H:%M:%S')
# nofrag,frag = result['timestamp_ingest_error'].split('.')
# timestamp = datetime.datetime.strptime(nofrag, '%Y-%m-%dT%H:%M:%S')
timestamp = datetime.datetime.strptime(result['timestamp_ingest_error'], '%Y-%m-%dT%H:%M:%SZ')
datapoint['timestamp'] = timestamp
datapoint['type'] = 'ingest_error'
datapoint['speed_bps'] = prev_ingest_speed
......@@ -515,6 +517,12 @@ def main():
parser.add_argument("--interval",
default="day",
help="Shows bars per interval. Possible options: minute, hour, day, month")
parser.add_argument("--input_filename","-i",
default="",
help="input filename")
parser.add_argument("--output_filename","-o",
default="",
help="output filename")
# plot parameters
parser.add_argument("--title",
default="Title",
......@@ -534,6 +542,12 @@ def main():
parser.add_argument("--colormap",
default="viridis",
help="see: https://matplotlib.org/examples/color/colormaps_reference.html")
# commands
parser.add_argument("--fits2png",
default=False,
help="convert FITS to PNG.",
action="store_true")
# All parameters in a file
parser.add_argument('--argfile',
nargs='?',
......@@ -544,15 +558,16 @@ def main():
help="Show current version of this program.",
action="store_true")
args = get_arguments(parser)
# --------------------------------------------------------------------------------------------------------
if (args.version):
print('--- atdb_stats.py - version 1.0.0 - 9 jun 2019 ---')
print('--- atdb_stats.py - version 1.1.0 - 25 nov 2019 ---')
print('Copyright (C) 2019 - Nico Vermaas - ASTRON. This program comes with ABSOLUTELY NO WARRANTY;')
return
print('--- atdb_stats.py - version 1.0.0 - 9 jun 2019 ---')
print('--- atdb_stats.py - version 1.1.0 - 25 nov 2019 ---')
print('Copyright (C) 2019 - Nico Vermaas - ASTRON. This program comes with ABSOLUTELY NO WARRANTY;')
if args.starttime != None:
starttime = datetime.datetime.strptime(args.starttime, TIME_FORMAT)
......@@ -604,6 +619,9 @@ def main():
elif presentation=="time_used":
do_time_used(args)
elif args.fits2png:
atdb_plot.fits_to_png_apercal(args.input_filename,args.output_filename)
if args.remote_post_command != None:
execute_remote_command(args.atdb_host, args.remote_post_command)
......
--fits2png
--input_file=D:\my_happili\image_mf_04.fits
--output_file=D:\my_happili\image_mf_04.png
......@@ -7,4 +7,4 @@
--plot_type=scatter
--colormap=viridis
--starttime=2018-01-01 00:00
--endtime=2019-06-17 00:00
--endtime=2019-11-12 00:00
--presentation=time_used
--atdb_host=http://192.168.22.22/atdb
--title=APERTIF Science Pie - Aug 2019
--query=from=2019-08-01T00:01:00Z&to=2019-09-01T00:00:00Z&report_type=time_used_science_pie
\ No newline at end of file
--presentation=time_used
--atdb_host=http://192.168.22.22/atdb
--title=APERTIF Science Pie - Aug 2019
--query=from=2019-08-01T00:01:00Z&to=2019-09-01T00:00:00Z&report_type=time_used_science_pie
\ No newline at end of file
--presentation=time_used
--atdb_host=http://atdb.astron.nl/atdb
--title=APERTIF System Pie - Aug 2019
--query=from=2019-08-01T00:01:00Z&to=2019-09-01T00:00:00Z&report_type=time_used_system_pie
\ No newline at end of file
--presentation=time_used
--atdb_host=http://atdb.astron.nl/atdb
--title=APERTIF System Pie - Aug 2019
--query=from=2019-08-01T00:01:00Z&to=2019-08-31T00:08:00Z&report_type=time_used_system_pie
\ No newline at end of file
--presentation=times
--atdb_host=http://atdb.astron.nl/atdb
--title=I/O speeds from ATDB
--subtitle=18 - 23 july 2019
--subtitle=29/30 aug 2019
--y_axis_title=I/O Speed in Gbps
--query=starttime__gt=2019-07-18T00:00:00Z&starttime__lt=2019-07-23T00:00:00Z
--query=starttime__gt=2019-08-29T00:00:00Z&starttime__lt=2019-09-02T00:00:00Z
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment