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 91a5bb5 commit 9989531
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 106 deletions.
56 changes: 18 additions & 38 deletions ush/ioda/bufr2ioda/bufr2ioda_altkob_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.

import sys
sys.path.append('/work2/noaa/da/spaturi/sandbox/CDA_testbed/global-workflow/sorc/gdas.cd/build/lib/python3.7/')
sys.path.append('/work2/noaa/da/spaturi/sandbox/CDA_testbed/global-workflow/sorc/gdas.cd/build/lib/python3.7/pyiodaconv/')
sys.path.append('/work2/noaa/da/spaturi/sandbox/CDA_testbed/global-workflow/sorc/gdas.cd/build/lib/python3.7/pyioda/')

import numpy as np
import numpy.ma as ma
import os
Expand All @@ -24,13 +20,16 @@
from pyioda import ioda_obs_space as ioda_ospace
from wxflow import Logger


def Compute_sequenceNumber(lon):

lon_u, seqNum = np.unique(lon, return_inverse=True)
seqNum = seqNum.astype(np.int64)
logger.debug(f"Len of Sequence Number: {len(seqNum)}")

return seqNum


def bufr_to_ioda(config, logger):

subsets = config["subsets"]
Expand All @@ -50,7 +49,7 @@ def bufr_to_ioda(config, logger):

yyyymmdd = cycle[0:8]
hh = cycle[8:10]

# General Information
converter = 'BUFR to IODA Converter'
platform_description = 'Surface obs from ALTKOB: temperature and salinity'
Expand All @@ -59,15 +58,14 @@ def bufr_to_ioda(config, logger):
DATA_PATH = os.path.join(dump_dir, f"{cycle_type}.{yyyymmdd}", str(hh), f"atmos",
bufrfile)
logger.debug(f"{bufrfile}, {DATA_PATH}")
#print(platform_description)

#===========================================
# ===========================================
# Make the QuerySet for all the data we want
#===========================================
# ===========================================
start_time = time.time()

logger.debug(f"Making QuerySet ...")
q = bufr.QuerySet() #(subsets)
q = bufr.QuerySet()

# MetaData
q.add('year', '*/YEAR')
Expand All @@ -91,10 +89,11 @@ def bufr_to_ioda(config, logger):
running_time = end_time - start_time
logger.debug(f"Running time for making QuerySet: {running_time} seconds")

#===============================================================
# ===============================================================
# Open the BUFR file and execute the QuerySet
# Use the ResultSet returned to get numpy arrays of the data
# ==============================================================
start_time = time.time()

logger.debug(f"Executing QuerySet to get ResultSet ...")
with bufr.File(DATA_PATH) as f:
Expand All @@ -115,7 +114,7 @@ def bufr_to_ioda(config, logger):
temp -= 273.15
saln = r.get('saln',group_by='depth')

# print ("masking temp & saln ...")
# 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]
Expand All @@ -137,10 +136,9 @@ def bufr_to_ioda(config, logger):

logger.debug(f" ... Executing QuerySet: Check BUFR variable generic \
dimension and type ...")
# #================================
# # Check values of BUFR variables, 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" saln min, max, length, dtype = {saln.min()}, {saln.max()}, {len(saln)}, {saln.dtype}")
logger.debug(f" lon min, max, length, dtype = {lon.min()}, {lon.max()}, {len(lon)}, {lon.dtype}")
Expand All @@ -153,7 +151,6 @@ def bufr_to_ioda(config, logger):
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}")

# =====================================
# Create IODA ObsSpace
Expand All @@ -171,7 +168,6 @@ def bufr_to_ioda(config, logger):
if path and not os.path.exists(path):
os.makedirs(path)

# logger.debug(f" ... ... Create output file ...', OUTPUT_PATH)
obsspace = ioda_ospace.ObsSpace(OUTPUT_PATH, mode='w', dim_dict=dims)

# Create Global attributes
Expand All @@ -181,16 +177,10 @@ def bufr_to_ioda(config, logger):
obsspace.write_attr('sourceFiles', bufrfile)
obsspace.write_attr('dataProviderOrigin', data_provider)
obsspace.write_attr('description', data_description)
#obsspace.write_attr('datetimeReference', reference_time)
obsspace.write_attr('datetimeRange', [str(dateTime.min()),
str(dateTime.max())])
obsspace.write_attr('datetimeRange', [str(dateTime.min()), str(dateTime.max())])
obsspace.write_attr('platformLongDescription', platform_description)
# obsspace.write_attr('platforms', PLATFORM + ': temperature and salinity')
# obsspace.write_attr('datetimeReference', date)
# obsspace.write_attr('dataProviderOrigin', 'GTS/NCEP data tank')
# obsspace.write_attr('description', '24-hrly from 6-hourly dumps')
#
# Create IODA variables

# Create IODA variables
logger.debug(f" ... ... Create variables: name, type, units, and attributes")

# Datetime
Expand Down Expand Up @@ -224,17 +214,6 @@ def bufr_to_ioda(config, logger):
.write_attr('long_name', 'Station Identification') \
.write_data(stationID)

# # Depth
# 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) \
# .write_attr('long_name', 'Sequence Number') \
# .write_data(seqNum)

# PreQC
obsspace.create_var('PreQC/seaSurfaceTemperature', dtype=PreQC.dtype, fillval=PreQC.fill_value) \
.write_attr('long_name', 'PreQC') \
Expand Down Expand Up @@ -275,6 +254,7 @@ def bufr_to_ioda(config, logger):

logger.debug(f"All Done!")


if __name__ == '__main__':

start_time = time.time()
Expand All @@ -284,7 +264,7 @@ def bufr_to_ioda(config, logger):
logger = Logger('bufr2ioda_trackob_surface.py', level=log_level,
colored_log=True)

with open(config, "r") as json_file:
with open(args.config, "r") as json_file:
config = json.load(json_file)

bufr_to_ioda(config, logger)
Expand Down
20 changes: 11 additions & 9 deletions ush/ioda/bufr2ioda/bufr2ioda_bathythermal_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
from pyioda import ioda_obs_space as ioda_ospace
from wxflow import Logger


def Compute_sequenceNumber(lon):
lon_u, seqNum = np.unique(lon, return_inverse=True)
seqNum = seqNum.astype(np.int64)
logger.debug(f"Len of Sequence Number: {len(seqNum)}")

return seqNum


def bufr_to_ioda(config, logger):

subsets = config["subsets"]
Expand All @@ -52,17 +54,16 @@ def bufr_to_ioda(config, logger):
platform_description = 'Profiles from BATHYthermal: temperature'

bufrfile = f"{cycle_type}.t{hh}z.{data_format}.tm{hh}.bufr_d"
DATA_PATH = os.path.join(dump_dir, f"{cycle_type}.{yyyymmdd}", str(hh), f"atmos",
bufrfile)
DATA_PATH = os.path.join(dump_dir, f"{cycle_type}.{yyyymmdd}", str(hh), f"atmos",bufrfile)
logger.debug(f"{bufrfile}, {DATA_PATH}")

#===========================================
# ==========================================
# Make the QuerySet for all the data we want
#===========================================
# ==========================================
start_time = time.time()

logger.debug(f"Making QuerySet ...")
q = bufr.QuerySet() #(subsets)
q = bufr.QuerySet()

# MetaData
q.add('year', '*/YEAR')
Expand All @@ -87,10 +88,11 @@ def bufr_to_ioda(config, logger):
running_time = end_time - start_time
logger.debug(f"Running time for making QuerySet: {running_time} seconds")

#===============================================================
# ==========================================================
# Open the BUFR file and execute the QuerySet
# Use the ResultSet returned to get numpy arrays of the data
# ==============================================================
# ==========================================================
start_time = time.time()

logger.debug(f"Executing QuerySet to get ResultSet ...")
with bufr.File(DATA_PATH) as f:
Expand Down Expand Up @@ -181,8 +183,8 @@ def bufr_to_ioda(config, logger):
obsspace.write_attr('description', data_description)
obsspace.write_attr('datetimeRange', [str(dateTime.min()), str(dateTime.max())])
obsspace.write_attr('platformLongDescription', platform_description)
#
# Create IODA variables

# Create IODA variables
logger.debug(f" ... ... Create variables: name, type, units, and attributes")

# Datetime
Expand Down
24 changes: 13 additions & 11 deletions ush/ioda/bufr2ioda/bufr2ioda_subpfl_argo_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
from pyioda import ioda_obs_space as ioda_ospace
from wxflow import Logger


def Compute_sequenceNumber(lon):

lon_u, seqNum = np.unique(lon, return_inverse=True)
seqNum = seqNum.astype(np.int64)
logger.debug(f"Len of Sequence Number: {len(seqNum)}")

return seqNum


def bufr_to_ioda(config, logger):

subsets = config["subsets"]
Expand Down Expand Up @@ -56,9 +59,9 @@ def bufr_to_ioda(config, logger):
bufrfile)
logger.debug(f"{bufrfile}, {DATA_PATH}")

#===========================================
# ==========================================
# Make the QuerySet for all the data we want
#===========================================
# ==========================================
start_time = time.time()

logger.debug(f"Making QuerySet ...")
Expand Down Expand Up @@ -88,11 +91,11 @@ def bufr_to_ioda(config, logger):
running_time = end_time - start_time
logger.debug(f"Running time for making QuerySet: {running_time} seconds")

#===============================================================
# ==========================================================
# Open the BUFR file and execute the QuerySet
# Use the ResultSet returned to get numpy arrays of the data
# ==============================================================

# ==========================================================
start_time = time.time()
logger.debug(f"Executing QuerySet to get ResultSet ...")
with bufr.File(DATA_PATH) as f:
r = f.execute(q)
Expand Down Expand Up @@ -128,9 +131,9 @@ def bufr_to_ioda(config, logger):
seqNum = Compute_sequenceNumber(lon)


#=================================================
# =======================================
# Separate ARGO profiles from subpfl tank
#=================================================
# =======================================
logger.debug(f"Finding index for ARGO floats where the second number of the stationID=9...")
index_list=[]
for index, number in enumerate(stationID):
Expand Down Expand Up @@ -166,10 +169,10 @@ def bufr_to_ioda(config, logger):

logger.debug(f" ... Executing QuerySet: Check BUFR variable generic \
dimension and type ...")
#================================
# Check values of BUFR variables, 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" saln min, max, length, dtype = {saln.min()}, {saln.max()}, {len(saln)}, {saln.dtype}")
logger.debug(f" lon min, max, length, dtype = {lon.min()}, {lon.max()}, {len(lon)}, {lon.dtype}")
Expand Down Expand Up @@ -200,7 +203,6 @@ def bufr_to_ioda(config, logger):
if path and not os.path.exists(path):
os.makedirs(path)

# logger.debug(f" ... ... Create output file ...', OUTPUT_PATH)
obsspace = ioda_ospace.ObsSpace(OUTPUT_PATH, mode='w', dim_dict=dims)

# Create Global attributes
Expand Down
22 changes: 12 additions & 10 deletions ush/ioda/bufr2ioda/bufr2ioda_subpfl_glider_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
from pyioda import ioda_obs_space as ioda_ospace
from wxflow import Logger


def Compute_sequenceNumber(lon):

lon_u, seqNum = np.unique(lon, return_inverse=True)
seqNum = seqNum.astype(np.int64)
logger.debug(f"Len of Sequence Number: {len(seqNum)}")

return seqNum


def bufr_to_ioda(config, logger):

subsets = config["subsets"]
Expand Down Expand Up @@ -56,9 +59,9 @@ def bufr_to_ioda(config, logger):
bufrfile)
logger.debug(f"{bufrfile}, {DATA_PATH}")

#===========================================
# ==========================================
# Make the QuerySet for all the data we want
#===========================================
# ==========================================
start_time = time.time()

logger.debug(f"Making QuerySet ...")
Expand Down Expand Up @@ -88,11 +91,11 @@ def bufr_to_ioda(config, logger):
running_time = end_time - start_time
logger.debug(f"Running time for making QuerySet: {running_time} seconds")

#===============================================================
# ==========================================================
# Open the BUFR file and execute the QuerySet
# Use the ResultSet returned to get numpy arrays of the data
# ==============================================================

# ==========================================================
start_time = time.time()
logger.debug(f"Executing QuerySet to get ResultSet ...")
with bufr.File(DATA_PATH) as f:
r = f.execute(q)
Expand Down Expand Up @@ -130,9 +133,9 @@ def bufr_to_ioda(config, logger):
logger.debug(f"Get sequenceNumber based on unique longitude...")
seqNum = Compute_sequenceNumber(lon)

#=================================================
# =========================================
# Separate GLIDER profiles from subpfl tank
#=================================================
# =========================================
logger.debug(f"Creating the mask for GLIDER floats based on station ID numbers ...")

mask_gldr = (stationID >= 68900) & (stationID <= 68999) | (stationID >= 1800000) & (stationID <= 1809999) \
Expand Down Expand Up @@ -167,10 +170,9 @@ def bufr_to_ioda(config, logger):
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" saln min, max, length, dtype = {saln.min()}, {saln.max()}, {len(saln)}, {saln.dtype}")
logger.debug(f" lon min, max, length, dtype = {lon.min()}, {lon.max()}, {len(lon)}, {lon.dtype}")
Expand Down
Loading

0 comments on commit 9989531

Please sign in to comment.