Skip to content

Commit

Permalink
Fixed coding norms
Browse files Browse the repository at this point in the history
  • Loading branch information
ShastriPaturi committed Jan 10, 2024
1 parent cba1f1a commit 2dfa152
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 287 deletions.
62 changes: 31 additions & 31 deletions ush/ioda/bufr2ioda/bufr2ioda_altkob_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def bufr_to_ioda(config, logger):
q = bufr.QuerySet()

# MetaData
q.add('year', '*/YEAR')
q.add('month', '*/MNTH')
q.add('day', '*/DAYS')
q.add('hour', '*/HOUR')
q.add('minute', '*/MINU')
q.add('ryear', '*/RCYR')
q.add('rmonth', '*/RCMO')
q.add('rday', '*/RCDY')
q.add('rhour', '*/RCHR')
q.add('rminute', '*/RCMI')
q.add('latitude', '*/CLATH')
q.add('longitude', '*/CLONH')
q.add('year', '*/YEAR')
q.add('month', '*/MNTH')
q.add('day', '*/DAYS')
q.add('hour', '*/HOUR')
q.add('minute', '*/MINU')
q.add('ryear', '*/RCYR')
q.add('rmonth', '*/RCMO')
q.add('rday', '*/RCDY')
q.add('rhour', '*/RCHR')
q.add('rminute', '*/RCMI')
q.add('latitude', '*/CLATH')
q.add('longitude', '*/CLONH')

# ObsValue
q.add('temp', '*/SST0')
q.add('saln', '*/SSS0')
q.add('temp', '*/SST0')
q.add('saln', '*/SSS0')

end_time = time.time()
running_time = end_time - start_time
Expand All @@ -100,36 +100,36 @@ def bufr_to_ioda(config, logger):

# MetaData
logger.debug(f" ... Executing QuerySet: get MetaData ...")
dateTime = r.get_datetime('year', 'month', 'day', 'hour', 'minute',group_by='depth')
dateTime = r.get_datetime('year', 'month', 'day', 'hour', 'minute', group_by='depth')
dateTime = dateTime.astype(np.int64)
rcptdateTime = r.get_datetime('ryear', 'rmonth', 'rday', 'rhour', 'rminute',group_by='depth')
rcptdateTime = r.get_datetime('ryear', 'rmonth', 'rday', 'rhour', 'rminute', group_by='depth')
rcptdateTime = rcptdateTime.astype(np.int64)
lat = r.get('latitude',group_by='depth')
lon = r.get('longitude',group_by='depth')
lat = r.get('latitude', group_by='depth')
lon = r.get('longitude', group_by='depth')

# ObsValue
logger.debug(f" ... Executing QuerySet: get ObsValue ...")
temp = r.get('temp',group_by='depth')
temp = r.get('temp', group_by='depth')
temp -= 273.15
saln = r.get('saln',group_by='depth')
saln = r.get('saln', group_by='depth')

# Add mask based on min, max values
mask = ((temp > -10.0) & (temp <= 50.0)) & ((saln >= 0.0) & (saln <= 45.0))
lat = lat[mask]
lon = lon[mask]
dateTime = dateTime[mask]
dateTime = dateTime[mask]
rcptdateTime = rcptdateTime[mask]
temp = temp[mask]
saln = saln[mask]

# ObsError
logger.debug(f"Generating ObsError array with constant value (instrument error)...")
ObsError_temp = np.float32( np.ma.masked_array(np.full((len(mask)), 0.30)) )
ObsError_saln = np.float32( np.ma.masked_array(np.full((len(mask)), 1.00)) )
logger.debug(f"Generating ObsError array with constant value (instrument error)...")
ObsError_temp = np.float32(np.ma.masked_array(np.full((len(mask)), 0.30)))
ObsError_saln = np.float32(np.ma.masked_array(np.full((len(mask)), 1.00)))

# PreQC
logger.debug(f"Generating PreQC array with 0...")
PreQC = ( np.ma.masked_array(np.full((len(mask)), 0)) ).astype(np.int32)
PreQC = (np.ma.masked_array(np.full((len(mask)), 0))).astype(np.int32)

logger.debug(f" ... Executing QuerySet: Done!")

Expand All @@ -147,7 +147,7 @@ def bufr_to_ioda(config, logger):
logger.debug(f" ObsError_temp min, max, length, dtype = {ObsError_temp.min()}, {ObsError_temp.max()}, {len(ObsError_temp)}, {ObsError_temp.dtype}")
logger.debug(f" ObsError_saln min, max, length, dtype = {ObsError_saln.min()}, {ObsError_saln.max()}, {len(ObsError_saln)}, {ObsError_saln.dtype}")

logger.debug(f" stationID shape, dtype = {stationID.shape}, {stationID.astype(str).dtype}")
logger.debug(f" stationID shape, dtype = {stationID.shape}, {stationID.astype(str).dtype}")
logger.debug(f" dateTime shape, dtype = {dateTime.shape}, {dateTime.dtype}")
logger.debug(f" rcptdateTime shape, dytpe = {rcptdateTime.shape}, {rcptdateTime.dtype}")

Expand All @@ -166,7 +166,7 @@ def bufr_to_ioda(config, logger):
path, fname = os.path.split(OUTPUT_PATH)
if path and not os.path.exists(path):
os.makedirs(path)

obsspace = ioda_ospace.ObsSpace(OUTPUT_PATH, mode='w', dim_dict=dims)

# Create Global attributes
Expand All @@ -183,13 +183,13 @@ def bufr_to_ioda(config, logger):
logger.debug(f" ... ... Create variables: name, type, units, and attributes")

# Datetime
obsspace.create_var('MetaData/dateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
obsspace.create_var('MetaData/dateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
.write_attr('units', 'seconds since 1970-01-01T00:00:00Z') \
.write_attr('long_name', 'Datetime') \
.write_data(dateTime)

# rcptDatetime
obsspace.create_var('MetaData/rcptdateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
obsspace.create_var('MetaData/rcptdateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
.write_attr('units', 'seconds since 1970-01-01T00:00:00Z') \
.write_attr('long_name', 'receipt Datetime') \
.write_data(rcptdateTime)
Expand All @@ -209,7 +209,7 @@ def bufr_to_ioda(config, logger):
.write_data(lat)

# Station Identification
obsspace.create_var('MetaData/stationID', dtype=stationID.dtype, fillval=stationID.fill_value) \
obsspace.create_var('MetaData/stationID', dtype=stationID.dtype, fillval=stationID.fill_value) \
.write_attr('long_name', 'Station Identification') \
.write_data(stationID)

Expand Down Expand Up @@ -259,7 +259,7 @@ def bufr_to_ioda(config, logger):
start_time = time.time()
config = "bufr2ioda_trackob_surface.json"

log_level = 'DEBUG' #if args.verbose else 'INFO'
log_level = 'DEBUG' if args.verbose else 'INFO'
logger = Logger('bufr2ioda_trackob_surface.py', level=log_level,
colored_log=True)

Expand Down
71 changes: 35 additions & 36 deletions ush/ioda/bufr2ioda/bufr2ioda_bathythermal_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ def bufr_to_ioda(config, logger):
q = bufr.QuerySet()

# MetaData
q.add('year', '*/YEAR')
q.add('month', '*/MNTH')
q.add('day', '*/DAYS')
q.add('hour', '*/HOUR')
q.add('minute', '*/MINU')
q.add('ryear', '*/RCYR')
q.add('rmonth', '*/RCMO')
q.add('rday', '*/RCDY')
q.add('rhour', '*/RCHR')
q.add('rminute', '*/RCMI')
q.add('stationID', '*/RPID')
q.add('latitude', '*/CLAT')
q.add('longitude', '*/CLON')
q.add('depth', '*/BTOCN/DBSS')
q.add('year', '*/YEAR')
q.add('month', '*/MNTH')
q.add('day', '*/DAYS')
q.add('hour', '*/HOUR')
q.add('minute', '*/MINU')
q.add('ryear', '*/RCYR')
q.add('rmonth', '*/RCMO')
q.add('rday', '*/RCDY')
q.add('rhour', '*/RCHR')
q.add('rminute', '*/RCMI')
q.add('stationID', '*/RPID')
q.add('latitude', '*/CLAT')
q.add('longitude', '*/CLON')
q.add('depth', '*/BTOCN/DBSS')

# ObsValue
q.add('temp', '*/BTOCN/STMP')
q.add('temp', '*/BTOCN/STMP')

end_time = time.time()
running_time = end_time - start_time
Expand All @@ -100,58 +100,57 @@ def bufr_to_ioda(config, logger):

# MetaData
logger.debug(f" ... Executing QuerySet: get MetaData ...")
dateTime = r.get_datetime('year', 'month', 'day', 'hour', 'minute',group_by='depth')
dateTime = r.get_datetime('year', 'month', 'day', 'hour', 'minute', group_by='depth')
dateTime = dateTime.astype(np.int64)
rcptdateTime = r.get_datetime('ryear', 'rmonth', 'rday', 'rhour', 'rminute',group_by='depth')
rcptdateTime = r.get_datetime('ryear', 'rmonth', 'rday', 'rhour', 'rminute', group_by='depth')
rcptdateTime = rcptdateTime.astype(np.int64)
stationID = r.get('stationID',group_by='depth')
lat = r.get('latitude',group_by='depth')
lon = r.get('longitude',group_by='depth')
depth = r.get('depth',group_by='depth')
stationID = r.get('stationID', group_by='depth')
lat = r.get('latitude', group_by='depth')
lon = r.get('longitude', group_by='depth')
depth = r.get('depth', group_by='depth')

# ObsValue
logger.debug(f" ... Executing QuerySet: get ObsValue ...")
temp = r.get('temp',group_by='depth')
temp = r.get('temp', group_by='depth')
temp -= 273.15

# Add mask based on min, max values
# Add mask based on min, max values
mask = ((temp > -10.0) & (temp <= 50.0))
lat = lat[mask]
lon = lon[mask]
depth = depth[mask]
stationID = stationID[mask]
dateTime = dateTime[mask]
dateTime = dateTime[mask]
rcptdateTime = rcptdateTime[mask]
temp = temp[mask]

logger.debug(f"Get sequenceNumber based on unique longitude...")
seqNum = Compute_sequenceNumber(lon)

# ObsError
logger.debug(f"Generating ObsError array with constant value (instrument error)...")
ObsError_temp = np.float32( np.ma.masked_array(np.full((len(temp)), 0.24)) )

# PreQC
logger.debug(f"Generating PreQC array with 0...")
logger.debug(f"Generating PreQC array with 0...")
PreQC = ( np.ma.masked_array(np.full((len(temp)), 0)) ).astype(np.int32)

logger.debug(f" ... Executing QuerySet: Done!")

logger.debug(f" ... Executing QuerySet: Check BUFR variable generic \
dimension and type ...")

#================================
# ==================================================
# Check values of BUFR variables, dimension and type
#================================
# ==================================================

logger.debug(f" temp min, max, length, dtype = {temp.min()}, {temp.max()}, {len(temp)}, {temp.dtype}")
logger.debug(f" lon min, max, length, dtype = {lon.min()}, {lon.max()}, {len(lon)}, {lon.dtype}")
logger.debug(f" lat min, max, length, dtype = {lat.min()}, {lat.max()}, {len(lat)}, {lat.dtype}")
logger.debug(f" depth min, max, length, dtype = {depth.min()}, {depth.max()}, {len(depth)}, {depth.dtype}")
logger.debug(f" PreQC min, max, length, dtype = {PreQC.min()}, {PreQC.max()}, {len(PreQC)}, {PreQC.dtype}")
logger.debug(f" ObsError_temp min, max, length, dtype = {ObsError_temp.min()}, {ObsError_temp.max()}, {len(ObsError_temp)}, {ObsError_temp.dtype}")

logger.debug(f" stationID shape, dtype = {stationID.shape}, {stationID.astype(str).dtype}")
logger.debug(f" stationID shape, dtype = {stationID.shape}, {stationID.astype(str).dtype}")
logger.debug(f" dateTime shape, dtype = {dateTime.shape}, {dateTime.dtype}")
logger.debug(f" rcptdateTime shape, dytpe = {rcptdateTime.shape}, {rcptdateTime.dtype}")
logger.debug(f" sequence Num shape, dtype = {seqNum.shape}, {seqNum.dtype}")
Expand All @@ -171,7 +170,7 @@ def bufr_to_ioda(config, logger):
path, fname = os.path.split(OUTPUT_PATH)
if path and not os.path.exists(path):
os.makedirs(path)

obsspace = ioda_ospace.ObsSpace(OUTPUT_PATH, mode='w', dim_dict=dims)

# Create Global attributes
Expand All @@ -188,13 +187,13 @@ def bufr_to_ioda(config, logger):
logger.debug(f" ... ... Create variables: name, type, units, and attributes")

# Datetime
obsspace.create_var('MetaData/dateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
obsspace.create_var('MetaData/dateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
.write_attr('units', 'seconds since 1970-01-01T00:00:00Z') \
.write_attr('long_name', 'Datetime') \
.write_data(dateTime)

# rcptDatetime
obsspace.create_var('MetaData/rcptdateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
obsspace.create_var('MetaData/rcptdateTime', dtype=dateTime.dtype, fillval=dateTime.fill_value) \
.write_attr('units', 'seconds since 1970-01-01T00:00:00Z') \
.write_attr('long_name', 'receipt Datetime') \
.write_data(rcptdateTime)
Expand All @@ -214,18 +213,18 @@ def bufr_to_ioda(config, logger):
.write_data(lat)

# Station Identification
obsspace.create_var('MetaData/stationID', dtype=stationID.dtype, fillval=stationID.fill_value) \
obsspace.create_var('MetaData/stationID', dtype=stationID.dtype, fillval=stationID.fill_value) \
.write_attr('long_name', 'Station Identification') \
.write_data(stationID)

# Depth
obsspace.create_var('MetaData/depth', dtype=depth.dtype, fillval=depth.fill_value) \
obsspace.create_var('MetaData/depth', dtype=depth.dtype, fillval=depth.fill_value) \
.write_attr('units', 'm') \
.write_attr('long_name', 'Water depth') \
.write_data(depth)

# Sequence Number
obsspace.create_var('MetaData/sequenceNumber', dtype=PreQC.dtype, fillval=PreQC.fill_value) \
obsspace.create_var('MetaData/sequenceNumber', dtype=PreQC.dtype, fillval=PreQC.fill_value) \
.write_attr('long_name', 'Sequence Number') \
.write_data(seqNum)

Expand Down
Loading

0 comments on commit 2dfa152

Please sign in to comment.