Skip to content

Commit

Permalink
FIX: Update for multiple warnings. (#1569)
Browse files Browse the repository at this point in the history
* FIX: Update for multiple warnings.

* FIX: PEP8 fixes.

* FIX: One last PEP8.
  • Loading branch information
zssherman committed Apr 26, 2024
1 parent def1f9f commit c4a3284
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pyart/graph/radardisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(self, radar, shift=(0.0, 0.0)):

# radar location in latitude and longitude
if radar.latitude["data"].size == 1:
lat = float(radar.latitude["data"])
lon = float(radar.longitude["data"])
lat = float(radar.latitude["data"][0])
lon = float(radar.longitude["data"][0])
else:
# for moving platforms stores use the median location.
# The RadarDisplay object does not give a proper
Expand Down
2 changes: 1 addition & 1 deletion pyart/io/_sigmetfile.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ SIGMET_DATA_TYPES = {
def convert_sigmet_data(data_type, data, nbins):
""" Convert sigmet data. """
out = np.empty_like(data, dtype='float32')
mask = np.zeros_like(data, dtype=np.bool8)
mask = np.zeros_like(data, dtype='bool')

data_type_name = SIGMET_DATA_TYPES[data_type]

Expand Down
12 changes: 5 additions & 7 deletions pyart/io/cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""

import datetime
import getpass
import platform
import warnings
from datetime import datetime, timedelta, timezone

import netCDF4
import numpy as np
Expand Down Expand Up @@ -531,7 +531,7 @@ def write_cfradial(
else:
user = getpass.getuser()
node = platform.node()
time_str = datetime.datetime.now().isoformat()
time_str = datetime.now().isoformat()
t = (user, node, time_str)
history = "created by {} on {} at {} using Py-ART".format(*t)

Expand All @@ -551,7 +551,7 @@ def write_cfradial(
only_use_cftime_datetimes=False,
only_use_python_datetimes=True,
)
td = dt - datetime.datetime.utcfromtimestamp(0)
td = dt - datetime.fromtimestamp(0, tz=timezone.utc).replace(tzinfo=None)
base_time = {
"data": np.array([td.seconds + td.days * 24 * 3600], "int32"),
"string": dt.strftime("%d-%b-%Y,%H:%M:%S GMT"),
Expand Down Expand Up @@ -698,7 +698,7 @@ def write_cfradial(
)
if start_dt.microsecond != 0:
# truncate to nearest second
start_dt -= datetime.timedelta(microseconds=start_dt.microsecond)
start_dt -= timedelta(microseconds=start_dt.microsecond)
end_dt = netCDF4.num2date(
radar.time["data"][-1],
units,
Expand All @@ -707,9 +707,7 @@ def write_cfradial(
)
if end_dt.microsecond != 0:
# round up to next second
end_dt += datetime.timedelta(seconds=1) - datetime.timedelta(
microseconds=end_dt.microsecond
)
end_dt += timedelta(seconds=1) - timedelta(microseconds=end_dt.microsecond)
start_dic = {
"data": np.array(start_dt.isoformat() + "Z", dtype="S"),
"long_name": "UTC time of first ray in the file",
Expand Down
6 changes: 4 additions & 2 deletions pyart/io/chl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import struct
from datetime import datetime
from datetime import datetime, timezone

import numpy as np

Expand Down Expand Up @@ -87,7 +87,9 @@ def read_chl(
tdata = np.array(chl_file.time)
min_time = np.floor(tdata.min())
time["data"] = (tdata - min_time).astype("float64")
time["units"] = make_time_unit_str(datetime.utcfromtimestamp(min_time))
time["units"] = make_time_unit_str(
datetime.fromtimestamp(min_time, tz=timezone.utc).replace(tzinfo=None)
)

# range
_range = filemetadata("range")
Expand Down
4 changes: 2 additions & 2 deletions pyart/io/grid_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""

import datetime
import warnings
from datetime import datetime, timezone

import netCDF4
import numpy as np
Expand Down Expand Up @@ -311,7 +311,7 @@ def write_grid(
if arm_time_variables:
time = grid.time
dt = netCDF4.num2date(time["data"][0], time["units"])
td = dt - datetime.datetime.utcfromtimestamp(0)
td = dt - datetime.fromtimestamp(0, tz=timezone.utc).replace(tzinfo=None)
td = td.seconds + td.days * 24 * 3600

base_time = {
Expand Down
4 changes: 2 additions & 2 deletions pyart/io/nexrad_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import struct
import warnings
from collections import namedtuple
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import numpy as np
from mda_xdrlib.xdrlib import Unpacker
Expand Down Expand Up @@ -371,7 +371,7 @@ def _get_data_msg_134(self):

def _datetime_from_mdate_mtime(mdate, mtime):
"""Returns a datetime for a given message date and time."""
epoch = datetime.utcfromtimestamp(0)
epoch = datetime.fromtimestamp(0, tz=timezone.utc).replace(tzinfo=None)
return epoch + timedelta(days=mdate - 1, seconds=mtime)


Expand Down
4 changes: 2 additions & 2 deletions pyart/io/output_to_geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _get_rgb_values(data, vmin, vmax, color_levels, cmap):
rarr = []
garr = []
barr = []
cmap = plt.cm.get_cmap(cmap)
cmap = plt.get_cmap(cmap)
for val in index:
if not np.isnan(val):
ind = int(np.round(val))
Expand Down Expand Up @@ -287,7 +287,7 @@ def _create_sld(cmap, vmin, vmax, filename, color_levels=None):
with steps << 255 (e.g., hydrometeor ID).
"""
cmap = plt.cm.get_cmap(cmap)
cmap = plt.get_cmap(cmap)
if color_levels is None:
color_levels = 255
name, _ = filename.split(".")
Expand Down
2 changes: 1 addition & 1 deletion pyart/util/columnsect.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def get_field_location(radar, latitude, longitude):

# Determine the time at the center of each ray within the column
# Define the start of the radar volume as a numpy datetime object for xr
base_time = np.datetime64(datetime_from_radar(radar).isoformat())
base_time = np.datetime64(datetime_from_radar(radar).isoformat(), "ns")
# Convert Py-ART radar object time (time since volume start) to time delta
# Add to base time to have sequential time within the xr Dataset
# for easier future merging/work
Expand Down
6 changes: 3 additions & 3 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def metadata(self):

@property
def ny(self):
return self.ds.dims["y"]
return self.ds.sizes["y"]

@property
def nx(self):
return self.ds.dims["x"]
return self.ds.sizes["x"]

@property
def nz(self):
return self.ds.dims["z"]
return self.ds.sizes["z"]

# Attribute init/reset methods
def init_point_x_y_z(self):
Expand Down
5 changes: 3 additions & 2 deletions tests/graph/test_radarmapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def test_radarmapdisplay_cartopy_ppi(outfile=None):
)
def test_radarmapdisplay_cartopy_preexisting_ax(outfile=None):
import cartopy
from cartopy.io.img_tiles import Stamen
from cartopy.io.img_tiles import GoogleTiles

radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
display = pyart.graph.RadarMapDisplay(radar, shift=(0.1, 0.0))
fig = plt.figure()
ax = plt.axes(projection=cartopy.crs.PlateCarree())
ax.add_image(Stamen("terrain-background"), 6)
tiler = GoogleTiles(style="terrain")
ax.add_image(tiler, 6)
display.plot_ppi_map("reflectivity_horizontal", 0, ax=ax, embellish=False)
if outfile:
fig.savefig(outfile)
Expand Down

0 comments on commit c4a3284

Please sign in to comment.