Skip to content

Commit

Permalink
Convert logger from old astrohack to new general logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhosk committed Nov 20, 2023
1 parent 0aefa2a commit 0113579
Show file tree
Hide file tree
Showing 23 changed files with 212 additions and 134 deletions.
8 changes: 4 additions & 4 deletions src/astrohack/_utils/_algorithms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import scipy.signal as scisig
import numpy as np
import scipy.signal as scisig

from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger
import skriba.logger


def _calculate_suggested_grid_paramater(parameter, quantile=0.01):
import scipy

logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

# Determine skew properties and return median
if np.abs(scipy.stats.skew(parameter)) > 0.5:
Expand Down Expand Up @@ -43,7 +43,7 @@ def _apply_mask(data, scaling=0.5):
Returns:
numpy.ndarray: cropped aperture grid data
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

x, y = data.shape

Expand Down
8 changes: 4 additions & 4 deletions src/astrohack/_utils/_combine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import os
import xarray as xr

from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger
import skriba.logger

from astrohack._utils._dio import _load_image_xds
from scipy.interpolate import griddata
from astrohack._utils._constants import clight
Expand All @@ -15,12 +15,12 @@ def _combine_chunk(combine_chunk_params):
Args:
combine_chunk_params: Param dictionary for combine chunk
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

antenna = combine_chunk_params['this_ant']
ddi_dict = combine_chunk_params['image_mds'][antenna]
fname = 'combine'
ddi_list = _parm_to_list(fname, combine_chunk_params['ddi'], ddi_dict, 'ddi')
print("DDI_LIST:", ddi_list)

nddi = len(ddi_list)
out_xds_name = '/'.join([combine_chunk_params['combine_name'], antenna, ddi_list[0]])
Expand Down
2 changes: 0 additions & 2 deletions src/astrohack/_utils/_conversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import skriba.logger

import numpy as np

from astrohack._utils._constants import *


Expand Down
19 changes: 14 additions & 5 deletions src/astrohack/_utils/_dask_graph_tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import dask
import xarray
import skriba.logger

from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger
from astrohack._utils._tools import _parm_to_list


def _construct_general_graph_recursively(caller, looping_dict, chunk_function, param_dict, delayed_list, key_order,
parallel=False, oneup=None):
logger = _get_astrohack_logger()
def _construct_general_graph_recursively(
caller,
looping_dict,
chunk_function,
param_dict,
delayed_list,
key_order,
parallel=False,
oneup=None
):

logger = skriba.logger.get_logger(logger_name="astrohack")
if len(key_order) == 0:
if isinstance(looping_dict, xarray.Dataset):
param_dict['xds_data'] = looping_dict
Expand Down Expand Up @@ -50,7 +59,7 @@ def _dask_general_compute(caller, looping_dict, chunk_function, param_dict, key_
Returns: True if processing has occured, False if no data was processed
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")
delayed_list = []
_construct_general_graph_recursively(caller, looping_dict, chunk_function, param_dict, delayed_list=delayed_list,
key_order=key_order, parallel=parallel)
Expand Down
7 changes: 3 additions & 4 deletions src/astrohack/_utils/_diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import numpy as np
import matplotlib.pyplot as plt
from astropy.time import Time

from astrohack._utils._constants import figsize, fontsize, markersize
import numpy as np
from astrohack._utils._constants import fontsize, markersize
from astrohack._utils._plot_commons import _create_figure_and_axes, _close_figure
from astropy.time import Time


def _calc_index(n, m):
Expand Down
16 changes: 9 additions & 7 deletions src/astrohack/_utils/_extract_locit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import skriba.logger

import numpy as np
import astropy.units as units
import xarray as xr

from casacore import tables as ctables
from astropy.coordinates import SkyCoord, CIRS
from astropy.time import Time
import astropy.units as units
import xarray as xr

from prettytable import PrettyTable

from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger
from astrohack._utils._tools import _casa_time_to_mjd, _rad_to_deg_str
from astrohack._utils._conversion import _convert_unit
from astrohack._utils._constants import figsize, twopi, notavail
Expand All @@ -27,7 +29,7 @@ def _extract_antenna_data(fname, extract_locit_parms):
Returns:
Antenna dictionary
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")
cal_table = extract_locit_parms['cal_table']
ant_table = ctables.table(cal_table + '::ANTENNA', readonly=True, lockoptions={'option': 'usernoread'}, ack=False)
ant_off = ant_table.getcol('OFFSET')
Expand Down Expand Up @@ -87,7 +89,7 @@ def _extract_spectral_info(fname, extract_locit_parms):
Returns:
DDI dictionary
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")
cal_table = extract_locit_parms['cal_table']
spw_table = ctables.table(cal_table+'::SPECTRAL_WINDOW', readonly=True, lockoptions={'option': 'usernoread'}, ack=False)
ref_freq = spw_table.getcol('REF_FREQUENCY')
Expand Down Expand Up @@ -179,7 +181,7 @@ def _extract_antenna_phase_gains(fname, extract_locit_parms):
Returns:
Reference antenna
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

cal_table = extract_locit_parms['cal_table']
basename = extract_locit_parms['locit_name']
Expand Down Expand Up @@ -299,7 +301,7 @@ def _plot_source_table(filename, src_dict, label=True, precessed=False, obs_midp
figure_size: plot dimensions in inches
dpi: Dots per inch (plot resolution)
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")
n_src = len(src_dict)
radec = np.ndarray((n_src, 2))
name = []
Expand Down
1 change: 1 addition & 0 deletions src/astrohack/_utils/_extract_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import skriba.logger
import xarray as xr

from astrohack._utils._conversion import convert_dict_from_numba
from astrohack._utils._dio import _load_point_file
from casacore import tables as ctables
Expand Down
8 changes: 4 additions & 4 deletions src/astrohack/_utils/_holog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from astrohack._utils._panel_classes.antenna_surface import AntennaSurface
from astrohack._utils._plot_commons import _create_figure_and_axes, _close_figure, _get_proper_color_map

from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger
import skriba.logger

CURRENT_FUNCTION=0

Expand All @@ -43,7 +43,7 @@ def _holog_chunk(holog_chunk_params):
Args:
holog_chunk_params (dict): Dictionary containing holography parameters.
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")


function_name = inspect.stack()[CURRENT_FUNCTION].function
Expand Down Expand Up @@ -344,7 +344,7 @@ def _export_to_fits_holog_chunk(parm_dict):
Args:
parm_dict: parameter dictionary
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

inputxds = parm_dict['xds_data']
metadata = parm_dict['metadata']
Expand Down Expand Up @@ -532,7 +532,7 @@ def _plot_beam(laxis, maxis, pol_axis, data, basename, label, antenna, ddi, unit

function_name = inspect.stack()[CURRENT_FUNCTION].function

logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")

colormap = _get_proper_color_map(colormap)

Expand Down
43 changes: 21 additions & 22 deletions src/astrohack/_utils/_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import astropy.coordinates as coord
from skimage.draw import disk
from astrohack._utils._algorithms import _calc_coords
from astrohack._utils._logger._astrohack_logger import _get_astrohack_logger


def _parallactic_derotation(data, parallactic_angle_dict):
Expand All @@ -27,19 +26,19 @@ def _parallactic_derotation(data, parallactic_angle_dict):
maps = list(parallactic_angle_dict.keys())

# Get the median index for the first map (this should be the same for every map).
median_index = len(parallactic_angle_dict[maps[0]].parallactic_samples)//2
median_index = len(parallactic_angle_dict[maps[0]].parallactic_samples) // 2

# This is the angle we will rotated the maps to.
median_angular_reference = parallactic_angle_dict[maps[0]].parallactic_samples[median_index]

for map, map_value in enumerate(maps):
#median_angular_offset = median_angular_reference - parallactic_angle_dict[map_value].parallactic_samples[median_index]
#median_angular_offset *= 180/np.pi
#parallactic_angle = 360 - parallactic_angle_dict[map_value].parallactic_samples[median_index]*180/np.pi
# median_angular_offset = median_angular_reference - parallactic_angle_dict[map_value].parallactic_samples[median_index]
# median_angular_offset *= 180/np.pi

# parallactic_angle = 360 - parallactic_angle_dict[map_value].parallactic_samples[median_index]*180/np.pi

data[map] = scipy.ndimage.rotate(input=data[map, ...], angle=90, axes=(3, 2), reshape=False)

return data


Expand All @@ -58,16 +57,16 @@ def _mask_circular_disk(center, radius, array, mask_value=np.nan):
shape = np.array(array.shape[-2:])

if center is None:
center = shape//2
center = shape // 2

r, c = disk(center, radius, shape=shape)
mask = np.zeros(shape, dtype=array.dtype)
mask = np.zeros(shape, dtype=array.dtype)
mask[r, c] = 1

mask = np.tile(mask, reps=(array.shape[:-2] + (1, 1)))

mask[mask == 0] = mask_value

return mask


Expand All @@ -83,10 +82,10 @@ def _calculate_aperture_pattern(grid, delta, padding_factor=50):
Returns:
numpy.ndarray, numpy.ndarray, numpy.ndarray: aperture grid, u-coordinate array, v-coordinate array
"""
logger = _get_astrohack_logger()
logger = skriba.logger.get_logger(logger_name="astrohack")
logger.info("[holog]: Calculating aperture illumination pattern ...")

assert grid.shape[-1] == grid.shape[-2] ###To do: why is this expected that l.shape == m.shape
assert grid.shape[-1] == grid.shape[-2] ###To do: why is this expected that l.shape == m.shape
initial_dimension = grid.shape[-1]

# Calculate padding as the nearest power of 2
Expand Down Expand Up @@ -124,11 +123,11 @@ def _calculate_aperture_pattern(grid, delta, padding_factor=50):


def _calculate_parallactic_angle_chunk(
time_samples,
observing_location,
direction,
dir_frame="FK5",
zenith_frame="FK5",
time_samples,
observing_location,
direction,
dir_frame="FK5",
zenith_frame="FK5",
):
"""
Converts a direction and zenith (frame FK5) to a topocentric Altitude-Azimuth (https://docs.astropy.org/en/stable/api/astropy.coordinates.AltAz.html)
Expand Down
1 change: 0 additions & 1 deletion src/astrohack/_utils/_locit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from astrohack._utils._conversion import _convert_unit
from astrohack._utils._algorithms import _least_squares_fit
from astrohack._utils._constants import *
#from astrohack.client import _get_astrohack_logger


def _locit_separated_chunk(locit_parms):
Expand Down
1 change: 0 additions & 1 deletion src/astrohack/_utils/_locit_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from astrohack._utils._panel_classes.telescope import Telescope
from astrohack._utils._constants import *
#from astrohack.client import _get_astrohack_logger

import skriba.logger

Expand Down
Loading

0 comments on commit 0113579

Please sign in to comment.