xradio 0.0.31__py3-none-any.whl → 0.0.33__py3-none-any.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.
- xradio/_utils/list_and_array.py +5 -3
- xradio/vis/__init__.py +3 -5
- xradio/vis/_processing_set.py +3 -3
- xradio/vis/_vis_utils/_ms/_tables/load_main_table.py +4 -4
- xradio/vis/_vis_utils/_ms/_tables/read.py +57 -41
- xradio/vis/_vis_utils/_ms/_tables/read_main_table.py +17 -18
- xradio/vis/_vis_utils/_ms/_tables/read_subtables.py +5 -5
- xradio/vis/_vis_utils/_ms/_tables/write.py +2 -4
- xradio/vis/_vis_utils/_ms/_tables/write_exp_api.py +19 -13
- xradio/vis/_vis_utils/_ms/chunks.py +5 -72
- xradio/vis/_vis_utils/_ms/conversion.py +168 -27
- xradio/vis/_vis_utils/_ms/{_tables/create_field_and_source_xds.py → create_field_and_source_xds.py} +114 -85
- xradio/vis/_vis_utils/_ms/descr.py +8 -8
- xradio/vis/_vis_utils/_ms/msv4_sub_xdss.py +249 -77
- xradio/vis/_vis_utils/_ms/partition_queries.py +19 -185
- xradio/vis/_vis_utils/_ms/partitions.py +18 -22
- xradio/vis/_vis_utils/_ms/subtables.py +2 -2
- xradio/vis/_vis_utils/_utils/partition_attrs.py +2 -2
- xradio/vis/_vis_utils/_utils/xds_helper.py +12 -12
- xradio/vis/_vis_utils/ms.py +1 -43
- xradio/vis/_vis_utils/zarr.py +0 -1
- xradio/vis/convert_msv2_to_processing_set.py +8 -1
- xradio/vis/load_processing_set.py +0 -3
- xradio/vis/read_processing_set.py +2 -2
- {xradio-0.0.31.dist-info → xradio-0.0.33.dist-info}/METADATA +1 -1
- {xradio-0.0.31.dist-info → xradio-0.0.33.dist-info}/RECORD +29 -31
- {xradio-0.0.31.dist-info → xradio-0.0.33.dist-info}/WHEEL +1 -1
- xradio/vis/_vis_utils/ms_column_descriptions_dicts.py +0 -1360
- xradio/vis/vis_io.py +0 -146
- {xradio-0.0.31.dist-info → xradio-0.0.33.dist-info}/LICENSE.txt +0 -0
- {xradio-0.0.31.dist-info → xradio-0.0.33.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import numcodecs
|
|
2
|
-
import math
|
|
3
2
|
import time
|
|
4
3
|
from .._zarr.encoding import add_encoding
|
|
5
4
|
from typing import Dict, Union
|
|
@@ -11,7 +10,7 @@ import xarray as xr
|
|
|
11
10
|
|
|
12
11
|
from casacore import tables
|
|
13
12
|
from .msv4_sub_xdss import create_ant_xds, create_pointing_xds, create_weather_xds
|
|
14
|
-
from xradio.vis._vis_utils._ms.
|
|
13
|
+
from xradio.vis._vis_utils._ms.create_field_and_source_xds import (
|
|
15
14
|
create_field_and_source_xds,
|
|
16
15
|
)
|
|
17
16
|
from .msv2_to_msv4_meta import (
|
|
@@ -27,7 +26,7 @@ from ._tables.read import (
|
|
|
27
26
|
convert_casacore_time,
|
|
28
27
|
extract_table_attributes,
|
|
29
28
|
read_col_conversion,
|
|
30
|
-
|
|
29
|
+
load_generic_table,
|
|
31
30
|
)
|
|
32
31
|
from ._tables.read_main_table import get_baselines, get_baseline_indices, get_utimes_tol
|
|
33
32
|
from .._utils.stokes_types import stokes_types
|
|
@@ -215,7 +214,7 @@ def mem_chunksize_to_dict_main_balanced(
|
|
|
215
214
|
|
|
216
215
|
# Iterate through the dims, starting from the dims with lower chunk size
|
|
217
216
|
# (=bigger impact of a +1)
|
|
218
|
-
# Note the use of
|
|
217
|
+
# Note the use of np.floor, this iteration can either increase or decrease sizes,
|
|
219
218
|
# if increasing sizes we want to keep mem use below the upper limit, floor(2.3) = +2
|
|
220
219
|
# if decreasing sizes we want to take mem use below the upper limit, floor(-2.3) = -3
|
|
221
220
|
indices = np.argsort(dim_chunksizes[free_dims_mask])
|
|
@@ -411,27 +410,27 @@ def create_coordinates(
|
|
|
411
410
|
"baseline_id": np.arange(len(baseline_ant1_id)),
|
|
412
411
|
}
|
|
413
412
|
|
|
414
|
-
ddi_xds =
|
|
415
|
-
pol_setup_id = ddi_xds.
|
|
416
|
-
spectral_window_id = int(ddi_xds.
|
|
413
|
+
ddi_xds = load_generic_table(in_file, "DATA_DESCRIPTION").sel(row=ddi)
|
|
414
|
+
pol_setup_id = ddi_xds.POLARIZATION_ID.values
|
|
415
|
+
spectral_window_id = int(ddi_xds.SPECTRAL_WINDOW_ID.values)
|
|
417
416
|
|
|
418
|
-
spectral_window_xds =
|
|
417
|
+
spectral_window_xds = load_generic_table(
|
|
419
418
|
in_file,
|
|
420
419
|
"SPECTRAL_WINDOW",
|
|
421
420
|
rename_ids=subt_rename_ids["SPECTRAL_WINDOW"],
|
|
422
421
|
).sel(spectral_window_id=spectral_window_id)
|
|
423
|
-
coords["frequency"] = spectral_window_xds["
|
|
424
|
-
~(np.isnan(spectral_window_xds["
|
|
422
|
+
coords["frequency"] = spectral_window_xds["CHAN_FREQ"].data[
|
|
423
|
+
~(np.isnan(spectral_window_xds["CHAN_FREQ"].data))
|
|
425
424
|
]
|
|
426
425
|
|
|
427
|
-
pol_xds =
|
|
426
|
+
pol_xds = load_generic_table(
|
|
428
427
|
in_file,
|
|
429
428
|
"POLARIZATION",
|
|
430
429
|
rename_ids=subt_rename_ids["POLARIZATION"],
|
|
431
430
|
)
|
|
432
|
-
num_corr = int(pol_xds["
|
|
431
|
+
num_corr = int(pol_xds["NUM_CORR"][pol_setup_id].values)
|
|
433
432
|
coords["polarization"] = np.vectorize(stokes_types.get)(
|
|
434
|
-
pol_xds["
|
|
433
|
+
pol_xds["CORR_TYPE"][pol_setup_id, :num_corr].values
|
|
435
434
|
)
|
|
436
435
|
|
|
437
436
|
xds = xds.assign_coords(coords)
|
|
@@ -443,18 +442,25 @@ def create_coordinates(
|
|
|
443
442
|
|
|
444
443
|
msv4_measure = column_description_casacore_to_msv4_measure(
|
|
445
444
|
freq_column_description["CHAN_FREQ"],
|
|
446
|
-
ref_code=spectral_window_xds["
|
|
445
|
+
ref_code=spectral_window_xds["MEAS_FREQ_REF"].data,
|
|
447
446
|
)
|
|
448
447
|
xds.frequency.attrs.update(msv4_measure)
|
|
449
448
|
|
|
450
|
-
|
|
449
|
+
if (spectral_window_xds.NAME.values.item() is None) or (
|
|
450
|
+
spectral_window_xds.NAME.values.item() == "none"
|
|
451
|
+
):
|
|
452
|
+
spw_name = "spw_" + str(spectral_window_id)
|
|
453
|
+
else:
|
|
454
|
+
spw_name = spectral_window_xds.NAME.values.item()
|
|
455
|
+
|
|
456
|
+
xds.frequency.attrs["spectral_window_name"] = spw_name
|
|
451
457
|
msv4_measure = column_description_casacore_to_msv4_measure(
|
|
452
458
|
freq_column_description["REF_FREQUENCY"],
|
|
453
|
-
ref_code=spectral_window_xds["
|
|
459
|
+
ref_code=spectral_window_xds["MEAS_FREQ_REF"].data,
|
|
454
460
|
)
|
|
455
461
|
xds.frequency.attrs["reference_frequency"] = {
|
|
456
462
|
"dims": [],
|
|
457
|
-
"data": float(spectral_window_xds.
|
|
463
|
+
"data": float(spectral_window_xds.REF_FREQUENCY.values),
|
|
458
464
|
"attrs": msv4_measure,
|
|
459
465
|
}
|
|
460
466
|
xds.frequency.attrs["spectral_window_id"] = spectral_window_id
|
|
@@ -465,8 +471,8 @@ def create_coordinates(
|
|
|
465
471
|
# xds.frequency.attrs["doppler_type"] =
|
|
466
472
|
|
|
467
473
|
unique_chan_width = unique_1d(
|
|
468
|
-
spectral_window_xds.
|
|
469
|
-
np.logical_not(np.isnan(spectral_window_xds.
|
|
474
|
+
spectral_window_xds["CHAN_WIDTH"].data[
|
|
475
|
+
np.logical_not(np.isnan(spectral_window_xds["CHAN_WIDTH"].data))
|
|
470
476
|
]
|
|
471
477
|
)
|
|
472
478
|
# assert len(unique_chan_width) == 1, "Channel width varies for spectral_window."
|
|
@@ -475,7 +481,7 @@ def create_coordinates(
|
|
|
475
481
|
# ] # unique_chan_width[0]
|
|
476
482
|
msv4_measure = column_description_casacore_to_msv4_measure(
|
|
477
483
|
freq_column_description["CHAN_WIDTH"],
|
|
478
|
-
ref_code=spectral_window_xds["
|
|
484
|
+
ref_code=spectral_window_xds["MEAS_FREQ_REF"].data,
|
|
479
485
|
)
|
|
480
486
|
if not msv4_measure:
|
|
481
487
|
msv4_measure["type"] = "quantity"
|
|
@@ -538,7 +544,7 @@ def find_min_max_times(tb_tool: tables.table, taql_where: str) -> tuple:
|
|
|
538
544
|
|
|
539
545
|
|
|
540
546
|
def create_data_variables(
|
|
541
|
-
in_file, xds, tb_tool, time_baseline_shape, tidxs, bidxs, didxs
|
|
547
|
+
in_file, xds, tb_tool, time_baseline_shape, tidxs, bidxs, didxs, use_table_iter
|
|
542
548
|
):
|
|
543
549
|
# Create Data Variables
|
|
544
550
|
col_names = tb_tool.colnames()
|
|
@@ -560,6 +566,7 @@ def create_data_variables(
|
|
|
560
566
|
time_baseline_shape,
|
|
561
567
|
tidxs,
|
|
562
568
|
bidxs,
|
|
569
|
+
use_table_iter,
|
|
563
570
|
)[:, :, None, :],
|
|
564
571
|
(1, 1, xds.sizes["frequency"], 1),
|
|
565
572
|
),
|
|
@@ -574,6 +581,7 @@ def create_data_variables(
|
|
|
574
581
|
time_baseline_shape,
|
|
575
582
|
tidxs,
|
|
576
583
|
bidxs,
|
|
584
|
+
use_table_iter,
|
|
577
585
|
),
|
|
578
586
|
dims=col_dims[col],
|
|
579
587
|
)
|
|
@@ -596,6 +604,7 @@ def create_data_variables(
|
|
|
596
604
|
def create_taql_query(partition_info):
|
|
597
605
|
main_par_table_cols = [
|
|
598
606
|
"DATA_DESC_ID",
|
|
607
|
+
"OBSERVATION_ID",
|
|
599
608
|
"STATE_ID",
|
|
600
609
|
"FIELD_ID",
|
|
601
610
|
"SCAN_NUMBER",
|
|
@@ -619,6 +628,7 @@ def convert_and_write_partition(
|
|
|
619
628
|
out_file: str,
|
|
620
629
|
ms_v4_id: int,
|
|
621
630
|
partition_info: Dict,
|
|
631
|
+
use_table_iter: bool,
|
|
622
632
|
partition_scheme: str = "ddi_intent_field",
|
|
623
633
|
main_chunksize: Union[Dict, float, None] = None,
|
|
624
634
|
with_pointing: bool = True,
|
|
@@ -669,6 +679,7 @@ def convert_and_write_partition(
|
|
|
669
679
|
"""
|
|
670
680
|
|
|
671
681
|
taql_where = create_taql_query(partition_info)
|
|
682
|
+
# print("taql_where", taql_where)
|
|
672
683
|
ddi = partition_info["DATA_DESC_ID"][0]
|
|
673
684
|
obs_mode = str(partition_info["OBS_MODE"][0])
|
|
674
685
|
|
|
@@ -694,6 +705,26 @@ def convert_and_write_partition(
|
|
|
694
705
|
time_baseline_shape = (len(utime), len(baseline_ant1_id))
|
|
695
706
|
logger.debug("Calc indx for row split " + str(time.time() - start))
|
|
696
707
|
|
|
708
|
+
observation_id = check_if_consistent(
|
|
709
|
+
tb_tool.getcol("OBSERVATION_ID"), "OBSERVATION_ID"
|
|
710
|
+
)
|
|
711
|
+
|
|
712
|
+
def get_observation_info(in_file, observation_id, obs_mode):
|
|
713
|
+
generic_observation_xds = load_generic_table(
|
|
714
|
+
in_file,
|
|
715
|
+
"OBSERVATION",
|
|
716
|
+
taql_where=f" where (ROWID() IN [{str(observation_id)}])",
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
if obs_mode == "None":
|
|
720
|
+
obs_mode = "obs_" + str(observation_id)
|
|
721
|
+
|
|
722
|
+
return generic_observation_xds["TELESCOPE_NAME"].values[0], obs_mode
|
|
723
|
+
|
|
724
|
+
telescope_name, obs_mode = get_observation_info(
|
|
725
|
+
in_file, observation_id, obs_mode
|
|
726
|
+
)
|
|
727
|
+
|
|
697
728
|
start = time.time()
|
|
698
729
|
xds = xr.Dataset()
|
|
699
730
|
# interval = check_if_consistent(tb_tool.getcol("INTERVAL"), "INTERVAL")
|
|
@@ -715,13 +746,53 @@ def convert_and_write_partition(
|
|
|
715
746
|
|
|
716
747
|
start = time.time()
|
|
717
748
|
create_data_variables(
|
|
718
|
-
in_file,
|
|
749
|
+
in_file,
|
|
750
|
+
xds,
|
|
751
|
+
tb_tool,
|
|
752
|
+
time_baseline_shape,
|
|
753
|
+
tidxs,
|
|
754
|
+
bidxs,
|
|
755
|
+
didxs,
|
|
756
|
+
use_table_iter,
|
|
719
757
|
)
|
|
758
|
+
|
|
759
|
+
if (
|
|
760
|
+
"WEIGHT" not in xds.data_vars
|
|
761
|
+
): # Some single dish datasets don't have WEIGHT.
|
|
762
|
+
xds["WEIGHT"] = xr.DataArray(
|
|
763
|
+
np.ones(xds.SPECTRUM.shape, dtype=np.float64),
|
|
764
|
+
dims=xds.SPECTRUM.dims,
|
|
765
|
+
)
|
|
766
|
+
|
|
720
767
|
logger.debug("Time create data variables " + str(time.time() - start))
|
|
721
768
|
|
|
722
769
|
# Create ant_xds
|
|
723
770
|
start = time.time()
|
|
724
|
-
|
|
771
|
+
feed_id = unique_1d(
|
|
772
|
+
np.concatenate(
|
|
773
|
+
[
|
|
774
|
+
unique_1d(tb_tool.getcol("FEED1")),
|
|
775
|
+
unique_1d(tb_tool.getcol("FEED2")),
|
|
776
|
+
]
|
|
777
|
+
)
|
|
778
|
+
)
|
|
779
|
+
antenna_id = unique_1d(
|
|
780
|
+
np.concatenate(
|
|
781
|
+
[xds["baseline_antenna1_id"].data, xds["baseline_antenna2_id"].data]
|
|
782
|
+
)
|
|
783
|
+
)
|
|
784
|
+
|
|
785
|
+
ant_xds = create_ant_xds(
|
|
786
|
+
in_file,
|
|
787
|
+
xds.frequency.attrs["spectral_window_id"],
|
|
788
|
+
antenna_id,
|
|
789
|
+
feed_id,
|
|
790
|
+
telescope_name,
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
# Change antenna_ids to antenna_names
|
|
794
|
+
xds = antenna_ids_to_names(xds, ant_xds)
|
|
795
|
+
|
|
725
796
|
logger.debug("Time ant xds " + str(time.time() - start))
|
|
726
797
|
|
|
727
798
|
# Create weather_xds
|
|
@@ -828,13 +899,13 @@ def convert_and_write_partition(
|
|
|
828
899
|
)
|
|
829
900
|
|
|
830
901
|
xds.attrs["partition_info"] = {
|
|
831
|
-
"spectral_window_id": xds.frequency.attrs["spectral_window_id"],
|
|
902
|
+
# "spectral_window_id": xds.frequency.attrs["spectral_window_id"],
|
|
832
903
|
"spectral_window_name": xds.frequency.attrs["spectral_window_name"],
|
|
833
|
-
"field_id": to_list(unique_1d(field_id)),
|
|
904
|
+
# "field_id": to_list(unique_1d(field_id)),
|
|
834
905
|
"field_name": to_list(
|
|
835
906
|
np.unique(field_and_source_xds.field_name.values)
|
|
836
907
|
),
|
|
837
|
-
"source_id": to_list(unique_1d(source_id)),
|
|
908
|
+
# "source_id": to_list(unique_1d(source_id)),
|
|
838
909
|
"source_name": to_list(
|
|
839
910
|
np.unique(field_and_source_xds.source_name.values)
|
|
840
911
|
),
|
|
@@ -856,7 +927,9 @@ def convert_and_write_partition(
|
|
|
856
927
|
)
|
|
857
928
|
|
|
858
929
|
if with_pointing:
|
|
859
|
-
pointing_xds.to_zarr(
|
|
930
|
+
pointing_xds.to_zarr(
|
|
931
|
+
store=os.path.join(file_name, "POINTING"), mode=mode
|
|
932
|
+
)
|
|
860
933
|
|
|
861
934
|
if weather_xds:
|
|
862
935
|
weather_xds.to_zarr(
|
|
@@ -871,6 +944,74 @@ def convert_and_write_partition(
|
|
|
871
944
|
# logger.info("Saved ms_v4 " + file_name + " in " + str(time.time() - start_with) + "s")
|
|
872
945
|
|
|
873
946
|
|
|
947
|
+
def antenna_ids_to_names(xds, ant_xds):
|
|
948
|
+
|
|
949
|
+
if ant_xds.attrs["overall_telescope_name"] in ["ALMA", "VLA", "NOEMA", "EVLA"]:
|
|
950
|
+
moving_antennas = True
|
|
951
|
+
else:
|
|
952
|
+
moving_antennas = False
|
|
953
|
+
|
|
954
|
+
if moving_antennas:
|
|
955
|
+
if "baseline_antenna1_id" in xds: # Interferometer
|
|
956
|
+
|
|
957
|
+
baseline_ant1_name = np.core.defchararray.add(
|
|
958
|
+
ant_xds["name"].sel(antenna_id=xds["baseline_antenna1_id"]).values, "_"
|
|
959
|
+
)
|
|
960
|
+
baseline_ant1_name = np.core.defchararray.add(
|
|
961
|
+
baseline_ant1_name,
|
|
962
|
+
ant_xds["station"].sel(antenna_id=xds["baseline_antenna1_id"]).values,
|
|
963
|
+
)
|
|
964
|
+
baseline_ant2_name = np.core.defchararray.add(
|
|
965
|
+
ant_xds["name"].sel(antenna_id=xds["baseline_antenna2_id"]).values, "_"
|
|
966
|
+
)
|
|
967
|
+
baseline_ant2_name = np.core.defchararray.add(
|
|
968
|
+
baseline_ant2_name,
|
|
969
|
+
ant_xds["station"].sel(antenna_id=xds["baseline_antenna2_id"]).values,
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
xds["baseline_antenna1_id"] = xr.DataArray(
|
|
973
|
+
baseline_ant1_name, dims="baseline_id"
|
|
974
|
+
)
|
|
975
|
+
xds["baseline_antenna2_id"] = xr.DataArray(
|
|
976
|
+
baseline_ant2_name, dims="baseline_id"
|
|
977
|
+
)
|
|
978
|
+
xds = xds.rename(
|
|
979
|
+
{
|
|
980
|
+
"baseline_antenna1_id": "baseline_antenna1_name",
|
|
981
|
+
"baseline_antenna2_id": "baseline_antenna2_name",
|
|
982
|
+
}
|
|
983
|
+
)
|
|
984
|
+
else: # Single Dish
|
|
985
|
+
antenna_name = np.core.defchararray.add(
|
|
986
|
+
ant_xds["name"].sel(antenna_id=xds["antenna_id"]).values, "_"
|
|
987
|
+
)
|
|
988
|
+
antenna_name = np.core.defchararray.add(
|
|
989
|
+
antenna_name,
|
|
990
|
+
ant_xds["station"].sel(antenna_id=xds["antenna_id"]).values,
|
|
991
|
+
)
|
|
992
|
+
xds["antenna_id"] = xr.DataArray(antenna_name, dims="baseline_id")
|
|
993
|
+
xds = xds.rename({"antenna_id": "antenna_name"})
|
|
994
|
+
else:
|
|
995
|
+
if "baseline_antenna1_id" in xds: # Interferometer
|
|
996
|
+
xds["baseline_antenna1_id"] = ant_xds["name"].sel(
|
|
997
|
+
antenna_id=xds["baseline_antenna1_id"]
|
|
998
|
+
)
|
|
999
|
+
xds["baseline_antenna2_id"] = ant_xds["name"].sel(
|
|
1000
|
+
antenna_id=xds["baseline_antenna2_id"]
|
|
1001
|
+
)
|
|
1002
|
+
xds = xds.rename(
|
|
1003
|
+
{
|
|
1004
|
+
"baseline_antenna1_id": "baseline_antenna1_name",
|
|
1005
|
+
"baseline_antenna2_id": "baseline_antenna2_name",
|
|
1006
|
+
}
|
|
1007
|
+
)
|
|
1008
|
+
else: # Single Dish
|
|
1009
|
+
xds["antenna_id"] = ant_xds["name"].sel(antenna_id=xds["antenna_id"])
|
|
1010
|
+
xds = xds.rename({"antenna_id": "antenna_name"})
|
|
1011
|
+
|
|
1012
|
+
return xds
|
|
1013
|
+
|
|
1014
|
+
|
|
874
1015
|
def add_data_groups(xds):
|
|
875
1016
|
xds.attrs["data_groups"] = {}
|
|
876
1017
|
if "VISIBILITY" in xds:
|