Commit 01731027 authored by CEVAER's avatar CEVAER

Added L2C to L2M and to Light conversion functions

parent d212cfc6
......@@ -310,3 +310,72 @@ def getDataAtCoord(data,lon,lat):
else :
dataAtCoord[key]=dataAtCoord[key]+180
return dataAtCoord
# Convert L2C file system path into L2M filesystem path
# INPUT:
# path : iterable or non iterable of a full L2C path (list of string or just string depending on input)
# resolution : resolution of the L2M path needed
# Return:
# A path or a list of path (same type as path parameter) containing the L2M paths
def L2CtoL2M(path, resolution):
if type(path) == str:
pathList = [path]
else:
pathList = path
pathList = [p.replace("L2C", "L2M").replace("_CC_", "_CM_").replace("-cc-", "-cm-") for p in pathList]
pathList = [p.split("/") for p in pathList]
for p in pathList:
filenameSplit = p[-1].split("-")
# Set the field which indicates the file resolution to the needed resolution.
# Adding leading zeros to keep field length
filenameSplit[-2] = str(resolution).zfill(len(filenameSplit[-2]))
p[-1] = "-".join(filenameSplit)
pathList = ["/".join(p) for p in pathList]
if type(path) == str:
return pathList[0]
else:
return pathList
# Convert L2C file system path into L2C/L2M light filesystem path
# INPUT:
# path (list of string or string) : iterable or non iterable of a full L2C path
# resolution (int) : resolution of the L2M path needed. If not provided, will return the L2CLight
# Return:
# A path or a list of path (same type as path parameter) containing the L2CLight/L2MLight paths
def L2CtoLight(path, resolution=None):
if type(path) == str:
pathList = [path]
else:
pathList = path
pathsOut = []
for p in pathList:
base = os.path.dirname(p)
if resolution:
addPath = "post_processing/nclight_L2M"
else:
addPath = "post_processing/nclight"
newPath = os.path.join(base, addPath)
newNcFile = os.path.splitext(os.path.basename(p))[0] + "_light.nc"
if resolution:
newNcFile = newNcFile.replace("-cc-", "-cm-")
filenameSplit = newNcFile.split("-")
# Set the field which indicates the file resolution to the needed resolution.
# Adding leading zeros to keep field length
filenameSplit[-2] = str(resolution).zfill(len(filenameSplit[-2]))
newNcFile = "-".join(filenameSplit)
fullNcPath = os.path.join(newPath, newNcFile)
pathsOut.append(fullNcPath)
if type(path) == str:
return pathsOut[0]
else:
return pathsOut
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