Commit f6d2e876 authored by Sasa Zhang's avatar Sasa Zhang
Browse files

python3 migration

parent 8204b213
Pipeline #185438 failed with stage
in 1 minute and 3 seconds
......@@ -62,28 +62,28 @@ if [ -n "$PYTHON_INCLUDE" ] ; then
exit 1
fi
PYTHON_INC=-I$PYTHON_INCLUDE
elif which python-config >/dev/null; then
echo "Using python-config to detect python settings."
elif which python3-config >/dev/null; then
echo "Using python3-config to detect python settings."
echo "You can override detected values by setting"
echo "enviroment variable PYTHON_INCLUDE."
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
PYTHON_INC=`python-config --includes`
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
PYTHON_INC=`python3-config --includes`
else
echo "----------------------------------------------------------"
echo "WARNING!"
echo "No python path defined."
echo "Will try to used the default path for python 2.4"
echo "Will try to used the default path for python 3.6"
echo "If it still doesn't work,"
echo "please set environment variable PYTHON_INCLUDE to your"
echo "python include directory."
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
echo "----------------------------------------------------------"
echo ""
PYTHON_INC="-I/usr/include/python2.4/"
PYTHON_INC="-I/usr/include/python3.6/"
fi
echo " Python include path = "$PYTHON_INC
PLATFORM=`python -c "import platform;print platform.architecture()[0]"`
PLATFORM=`python3 -c "import platform;print(platform.architecture()[0])"`
if [ $PLATFORM = "64bit" ]; then
FORTRAN_DEFAULT_INTEGER="-fdefault-integer-8"
echo " 64 bit architecture detected"
......@@ -93,7 +93,7 @@ fi
echo " Using SWIG"
echo ' macadam.i :'
swig -python macadam.i
swig -python macadam.i
echo " C compilation"
gcc -c -fPIC -Wall -Wno-implicit macadam.c $PYTHON_INC
......@@ -133,6 +133,3 @@ if [ ! -d $destination_path/usr/lib/metro ]; then
mkdir -p $destination_path/usr/lib/metro
fi
cp _macadam.so $destination_path/usr/lib/metro/
#cp -v _macadam.so macadam.py ../frontend/model/
......@@ -29,7 +29,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Every file in the source directories is listed separatly so that we don't
# Every file in the source directories is listed separately so that we don't
# include unwanted files. This way, we are forced to consider what goes in the
# package and what doesn't each time we make modifications. We don't blindly
# add a directory with all the temporary and test files and it helps us to keep
......
......@@ -76,7 +76,6 @@ class Metro_data_collection:
else:
sMessage = _("Invalid attribute name. Valid attribute name are:\n%s") % (str(self.lAttribute_list))
print(ERROR_ATTRIBUTE, sMessage)
raise
def set_attribute(self, sAttribute_name, value):
if sAttribute_name in self.lAttribute_list:
......@@ -85,7 +84,6 @@ class Metro_data_collection:
else:
sMessage = _("Invalid attribute name. Valid attribute name are:\n%s") % (str(self.lAttribute_list))
print(ERROR_ATTRIBUTE, sMessage)
raise
def append_attribute(self, sAttribute_name, value):
if sAttribute_name not in self.lAttribute_list:
......@@ -94,7 +92,6 @@ class Metro_data_collection:
else:
sMessage = _("Attribute name '%s' already used") % sAttribute_name
print(ERROR_ATTRIBUTE, sMessage)
raise
def get_attribute_list(self):
return self.lAttribute_list
......@@ -9,7 +9,7 @@
# Code contributed by:
# Miguel Tremblay - Canadian meteorological center
# Francois Fortin - Canadian meteorological center
#
# $LastChangedDate$
# $LastChangedRevision$
################################################################################
......
......@@ -49,7 +49,7 @@ _ = metro_util.init_translation('metro_data_station')
class Metro_data_station(Metro_data):
"""
Specialised class for station data.
This class inherit Metro_data. It add some method facilating the manipulation of station data.
This class inherit Metro_data. It add some method facilitating the manipulation of station data.
"""
# Get the longitude of the station
......
......@@ -81,7 +81,6 @@ class Metro_infdata:
sMessage = _("%s object doesn't have a Metro_data item. ") % (str(self.__class__)) + \
_("Try to use the get_data_collection() method")
print(ERROR_INFDATA_ITEM, sMessage)
raise
def set_data(self, value):
if self.iData_type == DATATYPE_METRO_DATA:
......@@ -90,7 +89,6 @@ class Metro_infdata:
sMessage = _("%s object doesn't have a Metro_data item. ") % (str(self.__class__)) + \
_("Try to use the set_data_collection() method")
print(ERROR_INFDATA_ITEM, sMessage)
raise
# DATA COLLECTION
def get_data_collection(self):
......@@ -100,7 +98,6 @@ class Metro_infdata:
sMessage = _("%s object doesn't have a Metro_data_collection ") % (str(self.__class__)) + \
_("item. Try to use the get_data() method.")
print(ERROR_INFDATA_ITEM, sMessage)
raise
def set_data_collection(self, value):
if self.iData_type == DATATYPE_METRO_DATA_COLLECTION:
......@@ -109,4 +106,3 @@ class Metro_infdata:
sMessage = _("%s object doesn't have a Metro_data_collection ") % (str(self.__class__)) + \
_("item. Try to use the set_data() method.")
print(ERROR_INFDATA_ITEM, sMessage)
raise
......@@ -60,4 +60,3 @@ class Metro_infdata_container:
sError = _("'%s' is not a valid infdata name\n") % sInfdata_name + \
_("Try one of the following infdata name:\n%s") % sInfdata_name_list
print(ERROR_INFDATA_CONTAINER, sError)
raise
......@@ -142,7 +142,6 @@ class Metro_model(Metro_module):
sMessage = "Forecast_data=" + str(lForecast_data)
metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG, sMessage)
# start roadlayer MATRIX
npLayerType = cs_data.get_matrix_col('TYPE')
lLayerType = npLayerType.astype(numpy.int32).tolist()
......@@ -175,7 +174,7 @@ class Metro_model(Metro_module):
ft = wforiginal.get_matrix_col('FORECAST_TIME')
# Forecast
# Get the interpolated values.
# Get the interpolated values.
wf_interpolated_data = forecast.get_interpolated_data()
npAT = wf_interpolated_data.get_matrix_col('AT')
lAT = npAT.tolist()
......
......@@ -102,7 +102,7 @@ class Metro_postprocess_round_roadcast(Metro_postprocess):
lExtended_roadcast = metro_config.get_value('XML_ROADCAST_PREDICTION_EXTENDED_ITEMS')
lRoadcast_items = lStandard_roadcast + lExtended_roadcast
# Get the default value for the accurary of "float" of the roadcast
# Get the default value for the accuracy of "float" of the roadcast
iDefault_precision = metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')
dData_types = metro_config.get_value('XML_DATATYPE_STANDARD')
......
......@@ -98,8 +98,7 @@ class Metro_postprocess_subsample_roadcast(Metro_postprocess):
for i in range(0, iNb_timesteps):
fCurrentTime = lTimeStep[i] * 3600
# Forecast at every 20 minutes, i.e. 1200 seconds
# if current time is a 20 minute interval
# and roadcast time is >= roadcast start date
# if current time is a 20 minute interval and roadcast time is >= roadcast start date
if round(fCurrentTime) % nSecondsForOutput == 0:
sLast_observation = metro_config.get_value('DATA_ATTRIBUTE_LAST_OBSERVATION')
fLast_observation = metro_date.parse_date_string(sLast_observation)
......@@ -149,8 +148,7 @@ class Metro_postprocess_subsample_roadcast(Metro_postprocess):
lRCvect = [0] * rc_subsampled.get_real_nb_matrix_col()
lMatrix_line = [None] * rc_subsampled.get_real_nb_matrix_col()
# if current time is a 20 minute interval
# and roadcast time is >= roadcast start date
# if current time is a 20 minute interval and roadcast time is >= roadcast start date
if round(fCurrentTime) % nSecondsForOutput == 0 and dElement_Array['ROADCAST_TIME'][i] >= fStartDate:
for sElement in list(dElement_Array.keys()):
lIndexList = rc_subsampled.index_of_matrix_col(sElement)
......
......@@ -166,8 +166,8 @@ class Metro_preprocess_combine(Metro_preprocess):
npSwo = npSwo[self.nDeltaIndice:nLenTDO]
npCheck = numpy.where(npSwo == 0, 1, 0)
npBadIndices = (numpy.nonzero(npCheck))[0]
# If there is no error in the dew point, use the observations, otherwise
# use the forecast for all the observation.
# If there is no error in the dew point, use the observations,
# otherwise use the forecast for all the observation.
if len(npBadIndices) == 0:
for i in range(0, nLenTDO - self.NTP):
npTD[i - self.NTP2] = npTDO[i + self.NTP - 1]
......@@ -218,8 +218,7 @@ class Metro_preprocess_combine(Metro_preprocess):
for i in range(0, nLenWSO - self.NTP):
npWS[i - self.NTP2] = npWSO[i + self.NTP - 1]
# Relaxation of observation on the atmospheric forecast
# 4 hour relaxation constant
# Relaxation of observation on the atmospheric forecast 4 hour relaxation constant
nTimeStepsInRelaxation = 4 * 3600 / metro_constant.fTimeStep
# Check if there is long enough atmospheric forecast
if nLenWS < nTimeStepsInRelaxation:
......@@ -233,8 +232,7 @@ class Metro_preprocess_combine(Metro_preprocess):
fCurrentObs = npWSO[nLenWSO - 1]
fCurrentFor = npWS[nLenWSO - self.NTP - self.NTP2]
if fCurrentObs < fCurrentFor:
# The value of 0.01 is arbitrary. It is to avoid a division
# by a value too near of zero.
# The value of 0.01 is arbitrary. It is to avoid a division by a value too near of zero.
if fCurrentFor < 0.01:
fCurrentFor = 1.0
if fCurrentObs == 0:
......@@ -269,7 +267,7 @@ class Metro_preprocess_combine(Metro_preprocess):
"""
npQP = wf_interpolated_data.get_matrix_col('QP')
# Create the road condition array. 0 is dry, 1 is wet
# Create the road condition array. 0 is dry, 1 is wet.
# This is only use in the initialization of profile
npSC = numpy.ones(len(npQP))
......
......@@ -90,8 +90,7 @@ class Metro_preprocess_fsint2(Metro_preprocess):
self.npAzim = horizon_data.get_matrix_col('AZIMUTH')
self.npElev = horizon_data.get_matrix_col('ELEVATION')
# Verification if the array has an monotone and
# regular incrementation steps
# Verification if the array has an monotone and regular incrementation steps
if not metro_util.is_array_uniform(self.npAzim):
sMessage = _("Azimuth data in station configuration file ") + \
_("is not ordered by equal growing azimuths. ") + \
......
......@@ -230,8 +230,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
"""
npTime = ro_controlled_data.get_matrix_col('Time')
npCheck = metro_util.get_difference_array(npTime)
# If a gap of more than nGapMinuteObservation
# minutes is identify, cut the value before.
# If a gap of more than nGapMinuteObservation minutes is identify, cut the value before.
npCheck = metro_util.get_difference_array(npTime)
npBad = numpy.where(npCheck > metro_constant.nGapMinuteObservation * 60, 1, 0)
npBadIndice = (numpy.nonzero(npBad))[0]
......@@ -252,8 +251,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
npTime = ro_controlled_data.get_matrix_col('Time')
npBad = numpy.where(npCheck < 0, 1, 0)
npBadIndice = (numpy.nonzero(npBad))[0]
# Accept 1 value under zero because the last value of
# npBadIndice = npCheck[len(npCheck)-1] - npCheck[0]
# Accept 1 value under zero because the last value of npBadIndice = npCheck[len(npCheck)-1] - npCheck[0]
if len(npBadIndice) > 1:
sMessage = _("Time of observation are not in order. ") + _("Check the %d th value") % (npBadIndice[1])
metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)
......@@ -287,8 +285,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
if sStart_time == "":
return
# Check if the observation are not before the start of the roadcast
# if specified.
# Check if the observation are not before the start of the roadcast if specified.
fStart_time = metro_date.parse_date_string(sStart_time)
npOT = ro_controlled_data.get_matrix_col('Time') + nHourStart * 3600
npDiff = - npOT + int(metro_date.get_hour(fStart_time)) * 3600
......@@ -420,8 +417,7 @@ class Metro_preprocess_qa_qc_observation(Metro_preprocess):
Description: Set the time difference between the beginning of observation and the beginning of the roadcast.
"""
# Compute the time difference between the first forecast time
# and the beginning of the observation
# Compute the time difference between the first forecast time and the beginning of the observation
StartForecast = wf_controlled_data.get_matrix_col('FORECAST_TIME')[0]
StartObservation = ro_controlled_data.get_matrix_col('OBSERVATION_TIME')[0]
fTimeElapsed = metro_date.get_elapsed_time(StartForecast, StartObservation, "UTC", "hours")
......
......@@ -84,8 +84,7 @@ def get_corrected_solar_flux(utc, S, lat, lon, horiz, m=1):
if m == 1:
S_cor[i] = 0.0
# Enhanced method:
# Replace global solar flux with its diffuse component.
# Enhanced method: Replace global solar flux with its diffuse component.
elif m == 2:
S_cor[i] = sflux_diffuse_component(S[i], sun_elev)
......
......@@ -138,8 +138,8 @@ class Metro_preprocess_validate_input(Metro_preprocess):
fNumberHourToRemove = nNumberSecondsToRemove / 3600.0
fNewStartTime = fFirst_observation_date + nNumberSecondsToRemove
sNewStartTime = metro_date.seconds2iso8601(fNewStartTime)
# Retrieve the first time in observation that is after this date
# numpy trick. Put 0 where the time is under fNewStartTime
# Retrieve the first time in observation that is after this date numpy trick.
# Put 0 where the time is under fNewStartTime
npNumberOfItemToRemove = numpy.where(npOT < fNewStartTime, 1, 0)
# Get the indice of the last indice that is not zero
tNonZero = numpy.nonzero(npNumberOfItemToRemove)
......
......@@ -186,8 +186,7 @@ class Sun:
if upper_limb:
altit = altit - sradius
# Compute the diurnal arc that the Sun traverses to reach
# the specified altitude altit:
# Compute the diurnal arc that the Sun traverses to reach the specified altitude altit:
cost = (self.sind(altit) - self.sind(lat) * self.sind(sdec))/(self.cosd(lat) * self.cosd(sdec))
if cost >= 1.0:
......@@ -273,7 +272,7 @@ class Sun:
return lon, r
def sunRADec(self, d):
""""""
# Compute Sun's ecliptical coordinates
res = self.sunpos(d)
lon = res[0]
......
......@@ -44,7 +44,7 @@ from functools import reduce
# check endianess
_big_endian = struct.pack('i', 1)[0] != '\x01'
_big_endian = struct.pack('i', 1)[0] != 1
# and define appropriate constants
if _big_endian:
......
......@@ -110,8 +110,7 @@ def get_sun_position(utc, lat, lon):
dEclipticObliquity = 0.4090928 - 6.2140e-9 * dElapsedJulianDays + 0.0000396 * cos(dOmega)
# Calculate celestial coordinates ( right ascension and declination ) in radians
# but without limiting the angle to be less than 2*Pi (i.e., the result may be
# greater than 2*Pi)
# but without limiting the angle to be less than 2*Pi (i.e., the result may be greater than 2*Pi)
dSin_EclipticLongitude = sin(dEclipticLongitude)
dY = cos(dEclipticObliquity) * dSin_EclipticLongitude
dX = cos(dEclipticLongitude)
......@@ -143,13 +142,12 @@ def get_sun_position(utc, lat, lon):
if __name__ == "__main__":
"""Selftest"""
"""
Selftest
"""
utc = time.gmtime()
# utc = time.strptime("2012-10-09", "%Y-%m-%d")
lat = 48.167803
lon = 17.106844
sun_azim, sun_elev = get_sun_position(utc, lat, lon)
utc_iso = time.strftime("%Y-%m-%dT%H:%M:%S", utc)
......
......@@ -63,7 +63,7 @@ LOGGER_MSG_EXECSECONDARY = 2 # show if verbosity = FULL
LOGGER_MSG_WARNING = 11 # show if verbosity = ( FULL || NORMAL )
LOGGER_MSG_EXECPRIMARY = 12 # show if verbosity = ( FULL || NORMAL )
LOGGER_MSG_CRITICAL = 21 # always displayed
LOGGER_MSG_STOP = 22 # alwayds displayed
LOGGER_MSG_STOP = 22 # always displayed
LOGGER_MSG_DEBUG_TXTID = _("DEBUG ")
LOGGER_MSG_INFORMATIVE_TXTID = _("INFORMATIVE")
......
......@@ -122,7 +122,6 @@ def roadlayer_type_to_roadlayer_code(sLayerType):
if sLayerType in dValidLayerType:
iLayer_code = dValidLayerType[sLayerType]
else:
# raise an error
sMessage = _("'%s' is not a valid road layer type. ") % sLayerType + \
_("Valid type are %s ") % (list(dValidLayerType.keys())) + \
_("Check the station configuration file")
......
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