Skip to content

Commit

Permalink
Merge pull request #293 from mfixstsci/numpy-update-fixes
Browse files Browse the repository at this point in the history
Numpy Update (Master)
  • Loading branch information
mfixstsci authored Dec 20, 2022
2 parents 259ce20 + 048b60c commit 2cc6511
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 63 deletions.
7 changes: 3 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Changes included in this version
--------------------------------

Edit this template to detail updates to the codebase
v0.19.1
-------
- Patch for new numpy version release (1.25.0). This version deprecated np.int and np.float. This release removes mention of these old methods.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The following describes the typical work flow for contributing to the pysiaf pro
11. Delete your local copy of your branch.

### Installation
This package is supported in python 3.7, 3.8 and 3.9
This package is supported in python 3.8 and 3.9

`pip install pysiaf`

Expand Down
2 changes: 1 addition & 1 deletion generate/generate_fgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
polynomial_coefficients = iando.read.read_siaf_distortion_coefficients(instrument, AperName)

number_of_coefficients = len(polynomial_coefficients)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)

# set polynomial coefficients
siaf_indices = ['{:02d}'.format(d) for d in polynomial_coefficients['siaf_index'].tolist()]
Expand Down
6 changes: 3 additions & 3 deletions generate/generate_nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
polynomial_coefficients = iando.read.read_siaf_distortion_coefficients(instrument, AperName)

number_of_coefficients = len(polynomial_coefficients)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
aperture.Sci2IdlDeg = polynomial_degree

# set polynomial coefficients
Expand Down Expand Up @@ -163,8 +163,8 @@
if (sca_name == 'NRCA5') and (('MASK335R' in aperture.AperName) or ('MASK430R' in aperture.AperName)):
# see https://jira.stsci.edu/browse/JWSTSIAF-77
sca_name += '335R430R'
v2_offset = np.float(wedge_offsets['v2_offset'][wedge_offsets['name'] == sca_name])
v3_offset = np.float(wedge_offsets['v3_offset'][wedge_offsets['name'] == sca_name])
v2_offset = float(wedge_offsets['v2_offset'][wedge_offsets['name'] == sca_name])
v3_offset = float(wedge_offsets['v3_offset'][wedge_offsets['name'] == sca_name])
aperture.V2Ref += v2_offset
aperture.V3Ref += v3_offset
elif dependency_type == 'dhspil_wedge':
Expand Down
2 changes: 1 addition & 1 deletion generate/generate_niriss.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
polynomial_coefficients = iando.read.read_siaf_distortion_coefficients(instrument, AperName)

number_of_coefficients = len(polynomial_coefficients)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)

# set polynomial coefficients
siaf_indices = ['{:02d}'.format(d) for d in polynomial_coefficients['siaf_index'].tolist()]
Expand Down
14 changes: 7 additions & 7 deletions generate/generate_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def read_pcf_gtp(file_name):
# transform to numpy array when possible
for key in data.keys():
try:
data[key] = np.array(data[key][0].split()).astype(np.float)
data[key] = np.array(data[key][0].split()).astype(float)
except:
pass

Expand Down Expand Up @@ -802,7 +802,7 @@ def rows(pcfName, new_pcf_format=False):
# 'F140X_GWA_OTE', 'F110W_GWA_OTE', 'CLEAR_GWA_OTE']
elif AperName in pcf_file_mapping.keys():
number_of_coefficients = len(pcf_data[AperName]['A'])
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
aperture.Sci2IdlDeg = polynomial_degree
k = 0
# polynomial coefficients for transformation that goes directly from the GWA pupil plane to the sky
Expand All @@ -816,10 +816,10 @@ def rows(pcfName, new_pcf_format=False):

# coefficients to apply the reflection in the MIRROR taking into account the correction
# to the GWA position as derived from the sensor readings and their calibration relation
aperture.XSciScale = np.float(disperser_mirror_tiltx['CoeffsTemperature00'][0])
aperture.YSciScale = np.float(disperser_mirror_tilty['CoeffsTemperature00'][0])
aperture.XSciRef = np.float(disperser_mirror_tiltx['Zeroreadings'][0])
aperture.YSciRef = np.float(disperser_mirror_tilty['Zeroreadings'][0])
aperture.XSciScale = float(disperser_mirror_tiltx['CoeffsTemperature00'][0])
aperture.YSciScale = float(disperser_mirror_tilty['CoeffsTemperature00'][0])
aperture.XSciRef = float(disperser_mirror_tiltx['Zeroreadings'][0])
aperture.YSciRef = float(disperser_mirror_tilty['Zeroreadings'][0])
aperture.DDCName = 'None'

# TRANSFORM apertures for the conversion between the OTE image plane and the MSA plane
Expand All @@ -838,7 +838,7 @@ def rows(pcfName, new_pcf_format=False):
fore_pcf_data = read_pcf_gtp(fore_pcf)

# deal with different formats of the .pcf files
fore_year = np.int(fore_pcf_data['DATE'][0][0:4])
fore_year = int(fore_pcf_data['DATE'][0][0:4])
if fore_year > 2016:
new_pcf_format = True
else:
Expand Down
6 changes: 3 additions & 3 deletions generate/generate_reference_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def generate_siaf_pre_flight_reference_files_nircam():

#generate distortion reference file
number_of_coefficients = len(A)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
siaf_index = []
exponent_x = []
exponent_y = []
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def generate_siaf_pre_flight_reference_files_niriss(distortion_file_name, verbos


number_of_coefficients = len(AR)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)

# if oss is False:
if 1:
Expand Down Expand Up @@ -1294,7 +1294,7 @@ def generate_siaf_pre_flight_reference_files_fgs(verbose=False, mode='siaf'):
-2.81501600E-15, -1.73025000E-15, 2.57732600E-15, 1.75268080E-15, 2.95238320E-15])

number_of_coefficients = len(A)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)

# generate distortion coefficient files
siaf_index = []
Expand Down
8 changes: 4 additions & 4 deletions pysiaf/aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def set_distortion_coefficients_from_file(self, file_name):
polynomial_coefficients = read.read_siaf_distortion_coefficients(file_name=file_name)

number_of_coefficients = len(polynomial_coefficients)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
self.Sci2IdlDeg = polynomial_degree

# set polynomial coefficients
Expand Down Expand Up @@ -910,7 +910,7 @@ def distortion_transform(self, from_system, to_system, include_offset=True):
# Get the coefficients for "science" to "ideal" transformation (and back)

# degree of distortion polynomial
degree = np.int(getattr(self, 'Sci2IdlDeg'))
degree = int(getattr(self, 'Sci2IdlDeg'))

number_of_coefficients = polynomial.number_of_coefficients(degree)
all_keys = self.__dict__.keys()
Expand Down Expand Up @@ -1513,8 +1513,8 @@ def dms_corner(self):
This corresponds to the OSS corner position (x: ColCorner, y: RowCorner).
The notation for OSS is 1-based, i.e. the lower left corner of a FULL subarray is (1,1)
"""
col_corner = np.ceil(np.min(self.corners('det')[0])).astype(np.int_)
row_corner = np.ceil(np.min(self.corners('det')[1])).astype(np.int_)
col_corner = np.ceil(np.min(self.corners('det')[0])).astype(int)
row_corner = np.ceil(np.min(self.corners('det')[1])).astype(int)

return col_corner, row_corner

Expand Down
68 changes: 34 additions & 34 deletions pysiaf/iando/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def read_hst_siaf(file=None, version=None):
a = aperture.HstAperture()
# Process the first 'CAJ' record.
a.ap_name = text[0:10].strip() # Aperture Identifier.
a.v2_cent = np.float(text[10:25]) # SICS V2 Center. (same as a_v2_ref)
a.v3_cent = np.float(text[25:40]) # SICS V3 Center. (same as a_v3_ref)
a.v2_cent = float(text[10:25]) # SICS V2 Center. (same as a_v2_ref)
a.v3_cent = float(text[25:40]) # SICS V3 Center. (same as a_v3_ref)
a.a_shape = text[40:44] # Aperture Shape.
try:
a.maj = np.float(text[44:59]) # Major Axis Dimension.
a.maj = float(text[44:59]) # Major Axis Dimension.
except ValueError: # when field is empty
a.maj = None
a.Mac_Flag = text[59] # !SI Macro Aperture Flag.
Expand All @@ -144,24 +144,24 @@ def read_hst_siaf(file=None, version=None):
elif (text.rstrip()[-3::] == 'CAJ') & (CAJ_index == 1):
# Process the second 'CAJ' record.
try:
a.min = np.float(text[0:15]) # !Minor Axis Dimension.
a.min = float(text[0:15]) # !Minor Axis Dimension.
except ValueError: # when field is empty
a.min = None
a.plate_scale = np.float(text[15:30]) # !Arcsecond per Pixel plate scale.
a.a_area = np.float(text[30:45]) # !Area of SI Aperture.
a.theta = np.float(text[45:60]) # !Aperture Rotation Angle.
a.plate_scale = float(text[15:30]) # !Arcsecond per Pixel plate scale.
a.a_area = float(text[30:45]) # !Area of SI Aperture.
a.theta = float(text[45:60]) # !Aperture Rotation Angle.
a.SIAS_Flag = text[60] # !SIAS coordinate system flag. (If set then AK rec.)
rec_type = text[70:73] # !Record type.
CAJ_index = 2

elif (text.rstrip()[-3::] == 'CAJ') & (CAJ_index == 2):
# Process the third 'CAJ' record.
a.im_par = np.int(text[0:2]) # Image Parity.
a.ideg = np.int(text[2]) # !Polynomial Degree.
a.xa0 = np.float(text[3:18]) # !SIAS X Center. -> like JWST SCIENCE frame
a.ya0 = np.float(text[18:33]) # !SIAS Y Center.
a.xs0 = np.float(text[33:48]) # !SICS X Center. -> like JWST IDEAL frame
a.ys0 = np.float(text[48:63]) # !SICS Y Center.
a.im_par = int(text[0:2]) # Image Parity.
a.ideg = int(text[2]) # !Polynomial Degree.
a.xa0 = float(text[3:18]) # !SIAS X Center. -> like JWST SCIENCE frame
a.ya0 = float(text[18:33]) # !SIAS Y Center.
a.xs0 = float(text[33:48]) # !SICS X Center. -> like JWST IDEAL frame
a.ys0 = float(text[48:63]) # !SICS Y Center.
rec_type = text[70:73] # !Record type.
CAJ_index = 0

Expand All @@ -174,34 +174,34 @@ def read_hst_siaf(file=None, version=None):
rec_type = text[70:73] # !Record type.

elif text.rstrip()[-3::] == 'CAQ':
a.v1x = np.float(text[0:15]) # !SICS Vertex 1_X -> like JWST IDEAL frame
a.v1y = np.float(text[15:30]) # !SICS Vertex 1_Y
a.v2x = np.float(text[30:45]) # !SICS Vertex 2_X
a.v2y = np.float(text[45:60]) # !SICS Vertex 2_Y
a.v1x = float(text[0:15]) # !SICS Vertex 1_X -> like JWST IDEAL frame
a.v1y = float(text[15:30]) # !SICS Vertex 1_Y
a.v2x = float(text[30:45]) # !SICS Vertex 2_X
a.v2y = float(text[45:60]) # !SICS Vertex 2_Y
rec_type = text[70:73] # !Record type.

elif text.rstrip()[-2::] == 'AQ':
a.v3x = np.float(text[0:15]) # !SICS Vertex 3_X
a.v3y = np.float(text[15:30]) # !SICS Vertex 3_Y
a.v4x = np.float(text[30:45]) # !SICS Vertex 4_X
a.v4y = np.float(text[45:60]) # !SICS Vertex 4_Y
a.v3x = float(text[0:15]) # !SICS Vertex 3_X
a.v3y = float(text[15:30]) # !SICS Vertex 3_Y
a.v4x = float(text[30:45]) # !SICS Vertex 4_X
a.v4y = float(text[45:60]) # !SICS Vertex 4_Y
rec_type = text[70:73] # !Record type.

elif text.rstrip()[-2::] == 'AP':
# FGS pickles
a.pi_angle = np.float(text[0:15]) # !Inner Radius Orientation Angle.
a.pi_ext = np.float(text[15:30]) # !Angular Extent of the Inner Radius.
a.po_angle = np.float(text[30:45]) # !Outer Radius Orientation Angle.
a.po_ext = np.float(text[45:60]) # !Angular Extent of the Outer Radius.
a.pi_angle = float(text[0:15]) # !Inner Radius Orientation Angle.
a.pi_ext = float(text[15:30]) # !Angular Extent of the Inner Radius.
a.po_angle = float(text[30:45]) # !Outer Radius Orientation Angle.
a.po_ext = float(text[45:60]) # !Angular Extent of the Outer Radius.
rec_type = text[70:73] # !Record type.

elif text.rstrip()[-2::] == 'AM':
a.a_v2_ref = np.float(text[0:15]) # !V2 Coordinate of Aperture Reference Point.
a.a_v2_ref = float(text[0:15]) # !V2 Coordinate of Aperture Reference Point.
# (same as v2_cent)
a.a_v3_ref = np.float(text[15:30]) # !V3 Coordinate of Aperture Reference Point.
a.a_v3_ref = float(text[15:30]) # !V3 Coordinate of Aperture Reference Point.
# (same as v3_cent)
a.a_x_incr = np.float(text[30:45]) # !First Coordinate Axis increment.
a.a_y_incr = np.float(text[45:60]) # !Second Coordinate Axis increment.
a.a_x_incr = float(text[30:45]) # !First Coordinate Axis increment.
a.a_y_incr = float(text[45:60]) # !Second Coordinate Axis increment.

elif text.rstrip()[-2::] == 'AN':
if (a.a_shape == 'PICK') and ('FGS' in a.ap_name):
Expand Down Expand Up @@ -229,7 +229,7 @@ def read_hst_siaf(file=None, version=None):

elif (text.rstrip()[-3::] == 'CAK') & (CAK_index == 0):
# Process the first 'CAK' record.
n_polynomial_coefficients = np.int(((a.ideg + 1) * (a.ideg + 2)) / 2)
n_polynomial_coefficients = int(((a.ideg + 1) * (a.ideg + 2)) / 2)
# the order is
# SIAS to SICS X Transformation.
# SIAS to SICS Y Transformation.
Expand All @@ -238,19 +238,19 @@ def read_hst_siaf(file=None, version=None):

polynomial_coefficients = np.ones((n_polynomial_coefficients, 4)) * -99
for jj in np.arange(4):
polynomial_coefficients[CAK_index, jj] = np.float(text[15 * jj:15 * (jj + 1)])
polynomial_coefficients[CAK_index, jj] = float(text[15 * jj:15 * (jj + 1)])
CAK_index += 1

elif (text.rstrip()[-3::] == 'CAK') & (CAK_index != 0):
# Process the remaining 'CAK' records
for jj in np.arange(4):
polynomial_coefficients[CAK_index, jj] = np.float(text[15 * jj:15 * (jj + 1)])
polynomial_coefficients[CAK_index, jj] = float(text[15 * jj:15 * (jj + 1)])
CAK_index += 1

elif text.rstrip()[-2::] == 'AK':
# Process the last polynomial coefficient record.
for jj in np.arange(4):
polynomial_coefficients[CAK_index, jj] = np.float(text[15 * jj:15 * (jj + 1)])
polynomial_coefficients[CAK_index, jj] = float(text[15 * jj:15 * (jj + 1)])
a.polynomial_coefficients = polynomial_coefficients
CAK_index = 0

Expand Down Expand Up @@ -415,7 +415,7 @@ def read_jwst_siaf(instrument=None, filename=None, basepath=None):
except (TypeError, ValueError) as e:
# print('{}: {}: {}'.format(e, node.tag, node.text))
if node.tag == 'DetSciYAngle':
value = np.int(float((node.text)))
value = int(float((node.text)))
else:
raise TypeError
elif node.tag in aperture.STRING_ATTRIBUTES:
Expand Down
2 changes: 1 addition & 1 deletion pysiaf/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_against_test_data(siaf=None):
tilt = None
else:
test_header = fits.getheader(test_data_file)
tilt = (np.float(test_header['GWA_XTIL']), np.float(test_header['GWA_YTIL']))
tilt = (float(test_header['GWA_XTIL']), float(test_header['GWA_YTIL']))

if sca_name == 'SCA491':
AperName = 'NRS1_FULL_OSS'
Expand Down
4 changes: 2 additions & 2 deletions pysiaf/utils/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def jacob(a, b, x, y):
def number_of_coefficients(poly_degree):
"""Return number of coefficients corresponding to polynomial degree."""
if type(poly_degree) == int:
n_coefficients = np.int((poly_degree + 1) * (poly_degree + 2) / 2)
n_coefficients = int((poly_degree + 1) * (poly_degree + 2) / 2)
return n_coefficients
else:
raise TypeError('Argument has to be of type int')
Expand Down Expand Up @@ -486,7 +486,7 @@ def polynomial_degree(number_of_coefficients):
if not poly_degree.is_integer():
raise ValueError('Number of coefficients does not match a valid polynomial degree.')
else:
return np.int(poly_degree)
return int(poly_degree)


def prepend_rotation_to_polynomial(a, theta, verbose=False):
Expand Down
4 changes: 2 additions & 2 deletions pysiaf/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def compute_roundtrip_error(A, B, C, D, offset_x=0., offset_y=0., verbose=False,
"""
number_of_coefficients = len(A)
polynomial_degree = np.int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
polynomial_degree = int((np.sqrt(8 * number_of_coefficients + 1) - 3) / 2)
order = polynomial_degree

# regular grid of points (in science pixel coordinates) in the full frame science frame
Expand Down Expand Up @@ -440,7 +440,7 @@ def set_reference_point_and_distortion(instrument, aperture, parent_aperture):
"""
polynomial_degree = parent_aperture.Sci2IdlDeg
number_of_coefficients = np.int((polynomial_degree + 1) * (polynomial_degree + 2) / 2)
number_of_coefficients = int((polynomial_degree + 1) * (polynomial_degree + 2) / 2)

k = 0
sci2idlx_coefficients = np.zeros(number_of_coefficients)
Expand Down

0 comments on commit 2cc6511

Please sign in to comment.