Commit cbc33d92 authored by Miguel Tremblay's avatar Miguel Tremblay
Browse files

Migration from 'numarray' to 'numpy'.

parent 4cfd2b36
......@@ -37,7 +37,7 @@ from metro_module import Metro_module
import string
import time
import numarray
import numpy
import metro_logger
import metro_config
......@@ -172,7 +172,7 @@ class Metro_model(Metro_module):
# start roadlayer MATRIX
naLayerType = cs_data.get_matrix_col('TYPE')
lLayerType = naLayerType.astype(numarray.Int32).tolist()
lLayerType = naLayerType.astype(numpy.int32).tolist()
lLayerThick = cs_data.get_matrix_col('THICKNESS').tolist()
nNbrOfLayer = len(lLayerType)
......@@ -247,21 +247,21 @@ class Metro_model(Metro_module):
# Concatenate the information to send it to C.
npSWO1 = observation.get_attribute('SST_VALID_INTERPOLATED')\
.astype(numarray.Int32)
.astype(numpy.int32)
npSWO2 = observation.get_attribute('AT_VALID_INTERPOLATED')\
.astype(numarray.Int32)
.astype(numpy.int32)
npSWO3 = observation.get_attribute('TD_VALID_INTERPOLATED')\
.astype(numarray.Int32)
.astype(numpy.int32)
npSWO4 = observation.get_attribute('WS_VALID_INTERPOLATED')\
.astype(numarray.Int32)
npSWO = numarray.zeros(4*metro_constant.nNL)
.astype(numpy.int32)
npSWO = numpy.zeros(4*metro_constant.nNL)
# Put all the arrays in one for the fortran code.
for i in range(0,len(npSWO1)):
npSWO[4*i] = npSWO1[i]
npSWO[4*i+1] = npSWO2[i]
npSWO[4*i+2] = npSWO3[i]
npSWO[4*i+3] = npSWO4[i]
lSWO = npSWO.astype(numarray.Int32).tolist()
lSWO = npSWO.astype(numpy.int32).tolist()
bNoObs = observation.get_attribute('NO_OBS')
......
......@@ -46,7 +46,7 @@ Description: Interpolation of data in order to be at every 30 seconds.
from metro_preprocess import Metro_preprocess
import time
import numarray
import numpy
from toolbox import metro_util
from toolbox import metro_date
......@@ -99,7 +99,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
Returns: None
Functions Called: forecast_data.get_matrix_col
numarray.arange,
numpy.arange,
metro_date.get_hour
wf_controlled_data.append_matrix_col
......@@ -115,17 +115,17 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
nbrHours = len(wf_original_data.get_matrix_col('AT'))
self.naTime = numarray.arange(0,nbrHours)*3600
self.naTime = numpy.arange(0,nbrHours, dtype=numpy.float)*3600
# Used in fsint2.
naTimeStart = \
wf_original_data.get_matrix_col('FORECAST_TIME')
nHourStart = int(metro_date.get_hour(naTimeStart[0]))
naTimeAtHours = numarray.arange(0,nbrHours) + nHourStart
naTimeAtHours = numpy.arange(0,nbrHours, dtype=numpy.float) + nHourStart
wf_controlled_data.append_matrix_col('Hour', naTimeAtHours)
def __interpolate_FT(self, wf_original_data, wf_controlled_data, \
wf_interpolated_data):
"""
......@@ -151,7 +151,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
naFT = wf_original_data.get_matrix_col('FORECAST_TIME')
naFT = metro_util.interpolate(self.naTime, naFT, \
metro_constant.fTimeStep)
metro_constant.fTimeStep)
wf_interpolated_data.append_matrix_col('FORECAST_TIME', naFT)
nHourStart = int(metro_date.get_hour(naFT[0]))
......@@ -163,6 +163,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
wf_interpolated_data.append_matrix_col('Time', naTime)
# Air temperature
def __interpolate_AT(self, wf_original_data, wf_interpolated_data):
"""
......@@ -223,7 +224,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
# Patch because of the -99 at the end of the forecast
fMax = naQP.max()
naQP = numarray.where(naQP < 0, fMax, naQP)
naQP = numpy.where(naQP < 0, fMax, naQP)
naQP = naQP - metro_util.shift_right(naQP, 0)
naSN = naSN - metro_util.shift_right(naSN, 0)
......@@ -238,7 +239,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
naQP = naQP *10e-4 # Set it in meter
naQP = naQP / 3600.0 # Convert by second
naQP = numarray.where(naQP < 0, 0, naQP)
naQP = numpy.where(naQP < 0, 0, naQP)
wf_interpolated_data.append_matrix_col('QP', naQP)
wf_interpolated_data.append_matrix_col('SN', naSN)
......@@ -251,8 +252,8 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
Name: __interpolate_WS
Parameters:[I] metro_data wf_original_data : original data. Read-only
[I] metro_data wf_interpolated_data : container of the interpolated
data.
[I] metro_data wf_interpolated_data : container of the
interpolated data.
Returns: None
......@@ -330,9 +331,9 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
naAP = wf_original_data.get_matrix_col('AP')
# Replace invalid date by the normal pressure (1013.25 mb)
naAP = numarray.where(naAP < metro_constant.nLowerPressure,\
naAP = numpy.where(naAP < metro_constant.nLowerPressure,\
metro_constant.fNormalPressure, naAP)
naAP = numarray.where(naAP > metro_constant.nUpperPressure,\
naAP = numpy.where(naAP > metro_constant.nUpperPressure,\
metro_constant.fNormalPressure, naAP)
# Convert it in pascals.
......@@ -356,7 +357,7 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
Functions Called: metro_util.interpolate,
metro_data.get_matrix_col
metro_data.append_matrix_col
numarray.where, around
numpy.where, around
Description: Interpolate the type of precipitation. The nearest neighbor is
is used.
......@@ -389,13 +390,13 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
else:
lPI.append(2)
naPI = numarray.array(lPI)
naPI = numpy.array(lPI)
# Interpolate
naPI = metro_util.interpolate(self.naTime, naPI, \
metro_constant.fTimeStep)
# Round
naPI = numarray.around(naPI)
naPI = numpy.around(naPI)
# Store
wf_interpolated_data.append_matrix_col('PI', naPI)
......@@ -421,14 +422,14 @@ class Metro_preprocess_interpol_forecast(Metro_preprocess):
"""
lCC = wf_original_data.get_matrix_col('CC')
naCC = numarray.array(lCC)
naCC = numpy.array(lCC)
# Interpolate
naCC = metro_util.interpolate(self.naTime, naCC, \
metro_constant.fTimeStep)
# Round
naCC = numarray.around(naCC)
naCC = numpy.around(naCC)
# Store
wf_interpolated_data.append_matrix_col('CC', naCC)
......
......@@ -43,7 +43,7 @@ Date: 4 aout 2004
from metro_preprocess import Metro_preprocess
import numarray
import numpy
import metro_config
import metro_logger
......@@ -111,7 +111,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
Returns: None
Functions Called: metro_data.get_matrix_col
numarray.zeros
numpy.zeros
metro_date.get_hour, get_minute
metro_date.get_elapsed_time
metro_data.append_matrix_col
......@@ -127,7 +127,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
"""
naOT = ro_controlled_data.get_matrix_col('OBSERVATION_TIME')
naTime = numarray.zeros(len(naOT))
naTime = numpy.zeros(len(naOT))
naTime[0] = metro_date.get_hour(naOT[0])*3600 + \
metro_date.get_minute(naOT[0])*60
if len(naOT) == 0:
......@@ -151,7 +151,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
Returns: None
Functions Called: metro_data.get_matrix_col
numarray.where, nonzero
numpy.where, nonzero
metro_logger.print_message
metro_data.del_matrix_row
metro_date.get_hour
......@@ -170,10 +170,10 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
################ Check road surface temperature ###############
naST = ro_controlled_data.get_matrix_col('ST')
# More than nRoadTemperatureHigh degrees
naBad = numarray.where(naST > metro_constant\
naBad = numpy.where(naST > metro_constant\
.nRoadTemperatureHigh , 1, 0)
if len(naBad) > 0:
naBadIndices = (numarray.nonzero(naBad))[0]
naBadIndices = (numpy.nonzero(naBad))[0]
if len(naBadIndices) > 0:
sMessage = _("Invalid road temperature")
metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,
......@@ -188,9 +188,9 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
ro_controlled_data.del_matrix_row(naBadIndices)
# or less than nRoadTemperatureMin
naST = ro_controlled_data.get_matrix_col('ST')
naBad = numarray.where(naST < metro_constant.nRoadTemperatureMin , 1, 0)
naBad = numpy.where(naST < metro_constant.nRoadTemperatureMin , 1, 0)
if len(naBad) > 0:
naBadIndices = (numarray.nonzero(naBad))[0]
naBadIndices = (numpy.nonzero(naBad))[0]
ro_controlled_data.del_matrix_row(naBadIndices)
def __check_time_order(self, ro_controlled_data, wf_controlled_data):
......@@ -203,7 +203,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
Functions Called: metro_data.get_matrix_col
metro_util.get_difference_array
numarray.where, nonzero, arange
numpy.where, nonzero, arange
metro_date.get_day, get_hour, get_minute
metro_data.del_matrix_row
metro_logger.print_message
......@@ -222,9 +222,9 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
# If a gap of more than nGapMinuteObservation
# minutes is identify, cut the value before.
naCheck = metro_util.get_difference_array(naTime)
naBad = numarray.where( naCheck > metro_constant.\
naBad = numpy.where( naCheck > metro_constant.\
nGapMinuteObservation*60, 1, 0)
naBadIndice = (numarray.nonzero(naBad))[0]
naBadIndice = (numpy.nonzero(naBad))[0]
if len(naBadIndice) > 0:
sMessage = _("More than %d minutes between 2 measures")\
% (metro_constant.nGapMinuteObservation)
......@@ -244,11 +244,11 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
sMessage)
toto = numarray.arange(0,naBadIndice[len(naBadIndice)-1]+1)
toto = numpy.arange(0,naBadIndice[len(naBadIndice)-1]+1)
ro_controlled_data.del_matrix_row(toto)
naTime = ro_controlled_data.get_matrix_col('Time')
naBad = numarray.where( naCheck < 0, 1, 0)
naBadIndice = (numarray.nonzero(naBad))[0]
naBad = numpy.where( naCheck < 0, 1, 0)
naBadIndice = (numpy.nonzero(naBad))[0]
# Accept 1 value under zero because the last value of
# naBadIndice = naCheck[len(naCheck)-1] - naCheck[0]
if len(naBadIndice) > 1:
......@@ -257,8 +257,8 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
sMessage )
# Remove the values that are equal.
naBad = numarray.where( naCheck == 0, 1, 0)
naBadIndice = (numarray.nonzero(naBad))[0]
naBad = numpy.where( naCheck == 0, 1, 0)
naBadIndice = (numpy.nonzero(naBad))[0]
ro_controlled_data.del_matrix_row(naBadIndice)
......@@ -269,12 +269,12 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
naOT = ro_controlled_data.get_matrix_col('Time')
nHourStart = metro_date.get_hour(naFT[0])
naDiff = - naOT + nHourStart*3600
naBad = numarray.where(naDiff > metro_constant.\
naBad = numpy.where(naDiff > metro_constant.\
nHourForExpirationOfObservation*3600, 1, 0)
if len(naBad) > 0:
naBadIndices = (numarray.nonzero(naBad))[0]
naBadIndices = (numpy.nonzero(naBad))[0]
if len(naBadIndices) > 0:
naBadIndices = (numarray.nonzero(naBad))[0]
naBadIndices = (numpy.nonzero(naBad))[0]
sMessage = _("Observation is more than %d hours") \
% ( metro_constant.nHourForExpirationOfObservation)\
+ _("before the first roadcast")
......@@ -298,10 +298,10 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
naOT = ro_controlled_data.get_matrix_col('Time')\
+nHourStart*3600
naDiff = - naOT + int(metro_date.get_hour(fStart_time))*3600
naBad = numarray.where(naDiff > metro_constant\
naBad = numpy.where(naDiff > metro_constant\
.nHourForExpirationOfObservation*3600, 1, 0)
if len(naBad) > 0:
naBadIndices = (numarray.nonzero(naBad))[0]
naBadIndices = (numpy.nonzero(naBad))[0]
if len(naBadIndices) > 0:
sMessage = _("Observation after the first roadcast time of METRo")
metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
......@@ -329,7 +329,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
# Returns: None
#
# Functions Called: metro_data.get_matrix_col
# numarray.where,
# numpy.where,
# metro_data.set_attribute
#
# Description: Set the attributes in road_data_collection to tell if the
......@@ -349,8 +349,8 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
naWS = ro_controlled_data.get_matrix_col('WS')
# Check SST #######################################
naCheck = numarray.where(naSST > metro_constant.nSubSurRoadTmpHigh, 0, 1)
naCheck = numarray.where(naSST < metro_constant.nSubSurRoadTmpMin, 0,\
naCheck = numpy.where(naSST > metro_constant.nSubSurRoadTmpHigh, 0, 1)
naCheck = numpy.where(naSST < metro_constant.nSubSurRoadTmpMin, 0,\
naCheck)
if len(naCheck) > 0:
......@@ -375,24 +375,24 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
naSST[i] = fCurrent
ro_controlled_data.set_matrix_col('SST', naSST)
observation_data.set_attribute('SST_VALID', numarray.ones(len(naSST)))
observation_data.set_attribute('SST_VALID', numpy.ones(len(naSST)))
# Check AT ###########################################
naCheck = numarray.where(naAT > metro_constant.nAirTempHigh , 0, 1)
naCheck = numarray.where(naAT < metro_constant.nAirTempMin , 0, naCheck)
naCheck = numpy.where(naAT > metro_constant.nAirTempHigh , 0, 1)
naCheck = numpy.where(naAT < metro_constant.nAirTempMin , 0, naCheck)
if len(naCheck) > 0:
observation_data.set_attribute('AT_VALID', naCheck)
# Check TD ##########################################
naCheck = numarray.where(naTD > metro_constant.nAirTempHigh, 0, 1)
naCheck = numarray.where(naTD < metro_constant.nAirTempMin, 0, naCheck)
naCheck = numarray.where(naTD > naAT , 0, naCheck)
naCheck = numpy.where(naTD > metro_constant.nAirTempHigh, 0, 1)
naCheck = numpy.where(naTD < metro_constant.nAirTempMin, 0, naCheck)
naCheck = numpy.where(naTD > naAT , 0, naCheck)
if len(naCheck) > 0:
observation_data.set_attribute('TD_VALID', naCheck)
# Check WS ###########################################
naCheck = numarray.where(naWS > metro_constant.nMaxWindSpeed, 0, 1)
naCheck = numarray.where(naWS < 0, 0, naCheck)
naCheck = numpy.where(naWS > metro_constant.nMaxWindSpeed, 0, 1)
naCheck = numpy.where(naWS < 0, 0, naCheck)
if len(naCheck) > 0:
observation_data.set_attribute('WS_VALID', naCheck)
......@@ -406,7 +406,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
# Returns: None
#
# Functions Called: metro_data.get_matrix_col
# numarray.where.
# numpy.where.
#
# Description: Transform the road condition (SC) into boolean field
#
......@@ -418,7 +418,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
#####################################################
def __set_road_condition(self, ro_controlled_data):
naSC = ro_controlled_data.get_matrix_col('SC')
naSC = numarray.where(naSC == 33, 0, 1)
naSC = numpy.where(naSC == 33, 0, 1)
ro_controlled_data.set_matrix_col('SC', naSC)
####################################################
......@@ -527,7 +527,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
# Returns: None
#
# Functions Called: metro_data.get_matrix_col
# numarray.where.
# numpy.where.
#
# Description: When the dew point is over the the air temperature, replace
# it by the air temperature.
......@@ -543,7 +543,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
naAT = ro_controlled_data.get_matrix_col('AT')
# First check, if TD > AT, replace TD by AT
naTD = numarray.where(naTD > naAT, naAT, naTD)
naTD = numpy.where(naTD > naAT, naAT, naTD)
ro_controlled_data.set_matrix_col('TD', naTD)
......
......@@ -46,7 +46,7 @@ _ = metro_util.init_translation('metro_read_forecast')
class Metro_read_forecast(Metro_read):
##
# methodes redefinies
# Overwritten methods
##
def start(self):
Metro_read.start(self)
......@@ -65,7 +65,7 @@ class Metro_read_forecast(Metro_read):
metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
sError_message)
else:
# creer et ajouter infdata
# Create and append infdata
infdata_forecast = metro_infdata.Metro_infdata(
'FORECAST', metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
infdata_forecast.set_input_information(sFile_content)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment