Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
* utcnow to now(UTC)
* ndimage.filters is deprecated
  • Loading branch information
sergiopasra committed Oct 19, 2023
1 parent f1f7c84 commit cac5f3f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/megaradrp/instrument/components/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
from scipy.stats import norm
import scipy.interpolate as interpol
from scipy.ndimage.filters import convolve1d
from scipy.ndimage import convolve1d
from numina.instrument.hwdevice import HWDevice
from numina.instrument.simulation.efficiency import Efficiency

Expand Down
3 changes: 2 additions & 1 deletion src/megaradrp/processing/aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def run(self, img):
hdr['history'] = f'Aperture extraction method {method_name}'
hdr['history'] = f'Aperture extraction with {self.calibid}'
hdr['history'] = f'Aperture extraction offsets are {self.trace_repr.global_offset.coef.tolist()}'
hdr['history'] = f'Aperture extraction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Aperture extraction time {tnow.isoformat()}'

# Update Fibers
fibers_ext = img['FIBERS']
Expand Down
5 changes: 3 additions & 2 deletions src/megaradrp/processing/diffuselight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2019-2021 Universidad Complutense de Madrid
# Copyright 2019-2023 Universidad Complutense de Madrid
#
# This file is part of Megara DRP
#
Expand Down Expand Up @@ -39,7 +39,8 @@ def __init__(self, diffuse, datamodel=None, calibid='calibid-unknown',
def header_update(self, hdr, imgid):
hdr['NUM-DFL'] = self.calibid
hdr['history'] = f'Diffuse light correction {imgid}'
hdr['history'] = f'Diffuse light correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Diffuse light correction time {tnow.isoformat()}'

def run(self, img):
imgid = self.get_imgid(img)
Expand Down
2 changes: 1 addition & 1 deletion src/megaradrp/processing/extractobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import astropy.io.fits as fits
import astropy.units as u
from scipy.spatial import KDTree
from scipy.ndimage.filters import gaussian_filter
from scipy.ndimage import gaussian_filter
from numina.array.wavecalib.crosscorrelation import periodic_corr1d

# import megaradrp.datamodel as dm
Expand Down
6 changes: 4 additions & 2 deletions src/megaradrp/processing/fiberflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def run(self, img):
def header_update(self, hdr, imgid):
hdr['NUM-FLT'] = self.calibid
hdr['history'] = f'Flat correction {imgid}'
hdr['history'] = f'Flat correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Flat correction time {tnow.isoformat()}'


class FiberFlatCorrector(CommonFlatCorrector):
Expand All @@ -74,7 +75,8 @@ def __init__(self, fiberflat, datamodel=None, dtype='float32'):
def header_update(self, hdr, imgid):
hdr['NUM-FIBF'] = self.calibid
hdr['history'] = f'Fiber flat correction {imgid}'
hdr['history'] = f'Fiber flat correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Fiber flat correction time {tnow.isoformat()}'


class Splitter(Corrector):
Expand Down
3 changes: 2 additions & 1 deletion src/megaradrp/processing/fluxcalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def header_update(self, hdr, imgid):
update_flux_limits(hdr, self.pixlims, ref=0)

hdr['history'] = f'Flux calibration in {imgid}'
hdr['history'] = f'Flux calibration time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Flux calibration time {tnow.isoformat()}'


def update_flux_limits(header, pixlims, wcs=None, ref=1):
Expand Down
3 changes: 2 additions & 1 deletion src/megaradrp/processing/slitflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ def __init__(self, slitflat, datamodel=None, calibid='calibid-unknown',
def header_update(self, hdr, imgid):
hdr['NUM-SLTF'] = self.calibid
hdr['history'] = f'Slit flat correction {imgid}'
hdr['history'] = f'Slit flat correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Slit flat correction time {tnow.isoformat()}'
4 changes: 2 additions & 2 deletions src/megaradrp/processing/tests/test_modelmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_2():


def test_calc1():
import scipy.sparse.csr
import scipy.sparse
model = GaussBoxModelDescription().model_cls
g_mean = 100 + 6 * np.arange(623)
g_std = 1 + np.zeros_like(g_mean)
Expand All @@ -86,4 +86,4 @@ def test_calc1():
params['mean'] = g_mean
params['stddev'] = g_std
wm = calc_matrix(wshape, model, params, valid)
assert isinstance(wm, scipy.sparse.csr.csr_matrix)
assert isinstance(wm, scipy.sparse.csr_matrix)
26 changes: 13 additions & 13 deletions src/megaradrp/processing/trimover.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# License-Filename: LICENSE.txt
#

from __future__ import print_function, division
from __future__ import division

import logging
import datetime
Expand All @@ -29,10 +29,9 @@

def trimOut(img, detconf, direction='normal', out='trimmed.fits'):
"""
:param data: original data to be trimmed. Can be either a string <path>, an ImageHDU or a numpy array
:param img: original data to be trimmed. Can be either a string <path>, an ImageHDU or a numpy array
:param direction: Can be either 'normal' or 'mirror'
:param out: When the original data is a path, the returned value is a file too
:param bins: is the index of the _binning dictionary
:return:
"""

Expand Down Expand Up @@ -92,8 +91,8 @@ def direcfun(x): return x
return finaldata


def get_conf_value(confFile, key):
return confFile[key]
def get_conf_value(conf_file, key):
return conf_file[key]


def apextract_weights(data, weights, size=4096):
Expand All @@ -103,7 +102,7 @@ def apextract_weights(data, weights, size=4096):

def decompress(tar_file):
"""
:param tar_name: <str> name of the tar file
:param tar_file: <str> name of the tar file
:return: None
"""

Expand Down Expand Up @@ -198,10 +197,10 @@ def __init__(self, detconf, datamodel=None, calibid='calibid-unknown', dtype='fl
dtype=dtype)

def data_binning(self, data, binning):
'''
"""
Axis:x --> factorX
Axis:y --> factorY
'''
"""
factorX = 1.0 / binning[1]
factorY = 1.0 / binning[0]
x = int(factorY * data[0][0])
Expand All @@ -212,8 +211,6 @@ def data_binning(self, data, binning):
return x, y, z, t

def test_image(self):
import astropy.io.fits as fits

data = np.empty((4212, 4196), dtype='float32')
data[self.pcol1] += 1
data[self.orow1] += 10
Expand Down Expand Up @@ -253,7 +250,8 @@ def run(self, img):
hdr = img['primary'].header
hdr['NUM-OVPE'] = self.calibid
hdr['history'] = f'Overscan correction with {self.calibid}'
hdr['history'] = f'Overscan correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Overscan correction time {tnow.isoformat()}'
# hdr['history'] = 'Mean of prescan1 is %f' % p1
hdr['history'] = f'Median of col overscan1 is {oc1}'
hdr['history'] = "Overscan1 correction is spline3"
Expand Down Expand Up @@ -320,7 +318,8 @@ def run(self, img):
hdr = img['primary'].header
hdr['NUM-TRIM'] = self.calibid
hdr['history'] = f'Trimming correction with {self.calibid}'
hdr['history'] = f'Trimming correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Trimming correction time {tnow.isoformat()}'

return img

Expand Down Expand Up @@ -353,7 +352,8 @@ def run(self, img):
img[0].data[part:] *= self.gain2

hdr['history'] = f'Gain correction with {self.calibid}'
hdr['history'] = f'Gain correction time {datetime.datetime.utcnow().isoformat()}'
tnow = datetime.datetime.now(datetime.UTC)
hdr['history'] = f'Gain correction time {tnow.isoformat()}'
hdr['history'] = f'Gain1 correction value {self.gain1}'
hdr['history'] = f'Gain2 correction value {self.gain2}'
return img
4 changes: 2 additions & 2 deletions src/megaradrp/processing/twilight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2011-2021 Universidad Complutense de Madrid
# Copyright 2011-2023 Universidad Complutense de Madrid
#
# This file is part of Megara DRP
#
Expand Down Expand Up @@ -59,6 +59,6 @@ def run(self, img):
def header_update(self, hdr, imgid):
hdr['NUM-TWIF'] = self.calibid
cap = self.flattag.capitalize()
now = datetime.datetime.utcnow().isoformat()
now = datetime.datetime.now(datetime.UTC).isoformat()
hdr['history'] = f'{cap} flat correction {imgid}'
hdr['history'] = f'{cap} flat correction time {now}'
4 changes: 2 additions & 2 deletions src/megaradrp/processing/wavecalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Corrector for wavelength calibration"""

import logging
import datetime
from datetime import datetime, UTC
import warnings
import uuid

Expand Down Expand Up @@ -185,7 +185,7 @@ def calibrate_wl_rss(rss, solutionwl, npix, targetwcs, dtype='float32', span=0,
hdr['history'] = f'Wavelength calibration with {solutionwl.calibid}'
hdr['history'] = 'Aperture extraction offsets are {}'.format(
solutionwl.global_offset.coef.tolist())
hdr['history'] = f'Wavelength calibration time {datetime.datetime.utcnow().isoformat()}'
hdr['history'] = f'Wavelength calibration time {datetime.now(UTC).isoformat()}'
hdr['history'] = f'Resample span={span}'
# Update UUID
hdr['UUID'] = str(uuid.uuid1())
Expand Down
13 changes: 6 additions & 7 deletions src/megaradrp/recipes/calibration/bpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class BadPixelsMaskRecipe(MegaraBaseRecipe):

def run(self, rinput):
self.logger.info('start BPM recipe')
N = len(rinput.obresult.frames)
nframes = len(rinput.obresult.frames)

self.logger.debug('we have %d images', N)
half = N // 2
self.logger.debug('we have %d images', nframes)
half = nframes // 2
flow = self.init_filters(rinput, rinput.obresult.configuration)
self.logger.debug('we have %d images', N)
self.logger.debug('we have %d images', nframes)
reduced1 = basic_processing_with_combination_frames(
rinput.obresult.frames[:half],
flow,
Expand All @@ -86,9 +86,8 @@ def run(self, rinput):

self.set_base_headers(hdu.header)

hdu.header['history'] = 'BPM creation time {}'.format(
datetime.datetime.utcnow().isoformat()
)
tnow = datetime.datetime.now(datetime.UTC)
hdu.header['history'] = 'BPM creation time {}'.format(tnow.isoformat())

for frame in rinput.obresult.frames:
hdu.header['history'] = "With image {}".format(
Expand Down
4 changes: 2 additions & 2 deletions src/megaradrp/recipes/calibration/slitflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
# License-Filename: LICENSE.txt
#

from __future__ import division, print_function
from __future__ import division

import uuid

import numpy
from scipy.ndimage.filters import median_filter
from scipy.ndimage import median_filter
from astropy.io import fits
from numina.array import combine
from numina.core import Result
Expand Down
4 changes: 2 additions & 2 deletions src/megaradrp/recipes/calibration/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"""Fiber tracing Recipe."""

from __future__ import division, print_function
from __future__ import division

import logging
import warnings
Expand All @@ -27,7 +27,7 @@
from numina.array.wavecalib.crosscorrelation import convolve_comb_lines
from skimage.filters import threshold_otsu
from skimage.feature import peak_local_max
from scipy.ndimage.filters import minimum_filter
from scipy.ndimage import minimum_filter
from numina.frame.utils import copy_img

from megaradrp.processing.aperture import ApertureExtractor
Expand Down
12 changes: 7 additions & 5 deletions src/megaradrp/simulation/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

"""Simple monocromatic simulation"""

import uuid
import datetime
import math
from datetime import datetime
import uuid

import astropy.wcs as wcs
import astropy.io.fits as fits
Expand Down Expand Up @@ -153,7 +153,8 @@ def create_from_instrument(self, data, name, instrument, mode=''):
# pheader['FILENAME'] = name
# OBS mode
pheader['OBSMODE'] = mode
pheader['DATE-OBS'] = datetime.utcnow().isoformat()
tnow = datetime.datetime.now(datetime.UTC)
pheader['DATE-OBS'] = tnow.isoformat()
exptime = meta[instrument.name].get('exposed', 1.0)
pheader['EXPTIME'] = exptime
pheader['EXPOSED'] = exptime
Expand All @@ -169,9 +170,10 @@ def create(self, data, name, control):
pheader['OBSMODE'] = control.mode
pheader['UUID'] = str(uuid.uuid4())
# Date of simulation
pheader['DATE'] = datetime.utcnow().isoformat()
tnow = datetime.datetime.now(datetime.UTC)
pheader['DATE'] = tnow.isoformat()
# Date of simulated observation, not set yet
pheader['DATE-OBS'] = datetime.utcnow().isoformat()
pheader['DATE-OBS'] = tnow.isoformat()

# Seqs
metacontrol = control.config_info()
Expand Down

0 comments on commit cac5f3f

Please sign in to comment.