{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to get RMs for a measurement set and write them to an h5parm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "from pathlib import Path\n", "\n", "from spinifex import h5parm_tools\n", "from spinifex.vis_tools import ms_tools" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### Required to load local data for example - not needed for normal use\n", "from importlib import resources\n", "\n", "with resources.as_file(resources.files(\"spinifex.data.tests\")) as datapath:\n", " spinifex_data = datapath" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the name of your measurement set" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ms = \"test.MS\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Unpacking of local test.MS - not needed for normal use\n", "\n", "import shutil\n", "\n", "with resources.as_file(resources.files(\"spinifex.data.tests\")) as test_data:\n", " zipped_ms = test_data / \"test.ms.zip\"\n", " shutil.unpack_archive(zipped_ms, \"./\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create a Path object for ms\n", "ms_path = Path(ms)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get metadata from ms, needed to get station_names\n", "ms_metadata = ms_tools.get_metadata_from_ms(ms_path)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get a dictionary with rm objects, keys are the station names\n", "rms = ms_tools.get_rm_from_ms(\n", " ms_path,\n", " use_stations=ms_metadata.station_names,\n", " # We set these options to use the data packaged with spinifex\n", " # Unsetting them will cause the function to download the data from the internet\n", " prefix=\"cod\",\n", " output_directory=spinifex_data,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# write to an h5parm object, this can be a new or existing h5parm\n", "h5parm_name = \"test.h5\"\n", "h5parm_tools.write_rm_to_h5parm(rms=rms, h5parm_name=h5parm_name)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "spinifex", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 2 }