Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jedi/ioda/imsfv3_scf2iodaTemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ def _read(self):
ncd = nc.Dataset(self.filename)
lons = ncd.variables['lon'][:].ravel()
lats = ncd.variables['lat'][:].ravel()
stid = ncd.variables['stid'][:].ravel()
oros = ncd.variables['oro'][:].ravel()
sncv = ncd.variables['IMSscf'][:].ravel()
sncv[sncv == -999.] = float_missing_value
sndv = ncd.variables['IMSsnd'][:].ravel()
sndv[sndv == -999.] = float_missing_value
strstid = np.empty_like(lons, dtype=object)

lons = lons.astype('float32')
lats = lats.astype('float32')
stid = stid.astype('int64')
oros = oros.astype('float32')
sncv = sncv.astype('float32')
sndv = sndv.astype('float32')
Expand All @@ -104,6 +107,9 @@ def _read(self):

times = get_observation_time(self.filename, sncv, ncd)

for i in range(len(lons)):
strstid[i] = str(stid[i])
Comment on lines +110 to +111
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i in range(len(lons)):
strstid[i] = str(stid[i])
+ strstid = np.vectorize(str)(stid)

Copy link
Copy Markdown
Collaborator Author

@yuanxue2870 yuanxue2870 May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested edit above did not work. ERROR: Unrecognized data type <U9. I understand the loop is the least favorable option here: I have also tried other integer to string conversions before using a loop, e.g., astype(str) to convert integer array directly, but a similar error message is acquired (i.e., ERROR: Unrecognized data type <U21).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it, loop is fine in this case


ncd.close()

# add metadata variables
Expand All @@ -112,6 +118,7 @@ def _read(self):
self.varAttrs[('dateTime', metaDataName)]['_FillValue'] = long_missing_value
self.outdata[('latitude', metaDataName)] = lats
self.outdata[('longitude', metaDataName)] = lons
self.outdata[('stationIdentification', metaDataName)] = strstid
self.outdata[('stationElevation', metaDataName)] = oros
self.varAttrs[('stationElevation', metaDataName)]['units'] = 'm'

Expand Down