Liu-Jincan / study-fpm

学习fortran-package-manager(fpm)的过程记录~~
0 stars 0 forks source link

4 #4

Open Liu-Jincan opened 2 years ago

Liu-Jincan commented 2 years ago

1

Liu-Jincan commented 2 years ago
By:
Created time:20220827, 
By        :Liu-jincan,
脚本中需转换成英文,
Usage:
之前在VSC的work.sh中用MATLAB实现了CFOSAT和HY2B卫星数据对矩形网格背景场数据的时空匹配,但是由于在超级计算机中无法使用MATLAB环境、且之前没有对非结构网格进行匹配,这里考虑在work.sh添加模块parm_satellite_match_python介绍,在SCRIPTS中添加此模块脚本parm_satellite_match_python.sh,最终实现对卫星数据与背景数据时空匹配进行一个代码集成。

该sh文件会生成一个parm_satellite_match_python.py文件,在相关python环境中运行该文件。

为了考虑业务化的应用、模块化编程,一天匹配一次,

参数:
-i        背景场 nc 数据所在文件夹路径,该路径下的文件夹结构yyyy/yyyymmdd/,文件形式**.nc,
-S        卫星数据所在文件夹路径, 
-u         背景场 nc文件是非结构网格,
-C        使用CFOSAT卫星数据,要求卫星数据路径下的文件夹结构为yyyy/yyyymmdd/,文件形式*.tar.gz,
-J        使用JASON3卫星数据,要求卫星数据路径下的文件夹结构为yyyy/yyyymmdd/,文件形式**,
-o        背景场与卫星数据匹配的数据所在的文件夹路径,该文件夹需要提前创建、名称是自定义的,该路径下的文件夹结构yyyy/yyyymmdd/,文件形式**,文件变量包含(背景场时间、背景场经度、背景场纬度、背景场格点的Hindex)。
https://blog.csdn.net/weixin_44503976/article/details/119756590 
像matlab的.mat文件一样的python数据保存方式,
-H        文件变量添加(背景场SWH、卫星SWH),
-h        打印帮助页面,
-P        使用的python环境的bin目录,
-p        parm_satellite_match_python.py所在路径,运行完后需将py文件删除。
后面的需求在脚本添加,
Liu-Jincan commented 2 years ago
#!/bin/bash

# --------------------------------------------------------------------------- #
# 1. Function definitions                                                     #
# --------------------------------------------------------------------------- #

# 1.a Error message function
errmsg ()
{
  echo "" 2>&1
  while [ $# != 0 ]
  do
    echo "ERROR: $1" 2>&1
    shift
  done
  echo "" 2>&1
}

# 1.b Usage function
usage ()
{

cat 2>&1 << 'EOF'
# --------------------------------------------------------------------------- #
#                                                                             #
#                                                                             #
#                    Last update :         2022-08-28                         #
#                    Created time:         2022-08-27                         #
#                    By          :         liujincan                          #
#                                                                             #
# --------------------------------------------------------------------------- #

Script for: Spatial and temporal matching of satellite data with background data generated by WW3.  
            In order to consider a business-oriented application, match once a day.
Usage: parm_satellite_match_python.sh [options]
NB: The execution of this script needs to be recorded in a 'parm' in VSC's 'work.sh',
    just for having a better overview of execution of the project.
    That is very useful! At least for me!
Options:
    -i          The path to the folder where the WW3 generated background field netcdf data is located.
                The folder structure under this path is yyyy/yyyyyymmdd/ and the file form is ww3.yyyymmddThhZ.nc.
                For example, ww3.20220813T20Z.nc.
    -d          The day when the background field and satellite data match.
                ex, 20220815,
    -S          The path to the folder where the satellite data is located.
    -u          The background field netcdf file generated by WW3 is a non-structural grid.
                ugrid=1, non-structural grid.
                ugrid=0, rectangular grid. 
    -C          Using CFOSAT satellite data, 
                it is required that the folder structure under the satellite data path is yyyy/yyyyymmdd/ 
                and the file form is *.tar.gz.
                cfosat='cfosat1', Z_SATE_C_HYJ_20220815101515_P_CFO_OPER_SWI_L2_____C_20220815T051737_20220815T054248.tar.gz
    -J          Using JASON3 satellite data, 
                it is required that the folder structure under the satellite data path is yyyy/yyyyymmdd/
                and the file form **.
                jason3='jason31',
    -o          The path to the folder where the python-generated matching data is located.
                The folder needs to be created in advance, 
                the name is customized, 
                the folder structure under this path yyyy/yyyyyymmdd/, 
                the file form **, 
                the basic variables contain (background field 'time', background field 'longitude', background field 'latitude', 
                    background field grid point's 'Hindex').
                https://blog.csdn.net/weixin_44503976/article/details/119756590, python data storage like matlab's .mat files.            
    -H          Variables added (background field 'SWH', satellite 'SWH'),
                swh='swh1', No outlier processing.
    -h          Print the help page.
    -P          The bin directory of the python environment used.
                    conda create -n py-ev-satellite-match python=3.8
                The environment for py-ev-satellite-match is located in the 
                    Data-Assimilation-for-Ocean-Current-Forecasts/anaconda3/envs folder. 
    -p          Temporary folder for the entire process.
                You will need to delete this folder when you are finished.
Running example:
    parm_satellite_match_python.sh \
        -i /1t/NC \
        -d 20220815 \
        -S /1t/CFO \
        -u 1 \
        -C cfosat1 \
        -o /1t/NC_CFO_20220815 \
        -H swh1 \
        -P /1t/Data-Assimilation-for-Ocean-Current-Forecasts/anaconda3/envs/py-ev-satellite-match/bin/python \
        -p /1t/Data-Assimilation-for-Ocean-Current-Forecasts/SCRIPTS/parm_satellite_match_python/

Others:
        The spatio-temporal matching of CFOSAT and HY2B satellite data to rectangular grid background field data 
        was previously implemented in VSC's work.sh using MATLAB.

Modification history
        ex, 27-Jan-2014 : Adapts ww3_ounf section for multigrid            ( version 4.18 )

EOF
}

# --------------------------------------------------------------------------- #
# 2. Preparations                                                             #
# --------------------------------------------------------------------------- #

# 2.a Setup array of command-line arguments
optstr="i:d:S:u:C:J:o:H:hP:p:"  #option string for getopt function
args=`getopt $optstr $*`
# echo "$?"
set -- $args

# 2.b Process command-line options
path_NC=none
day=none
path_S=none
ugrid=none
cfosat=none
jason3=none
path_o=none
swh=none
help=none
path_py_bin=none
path_tmp_folder=none

while :
do
    case "$1" in
    -i) shift; path_NC="$1" ;;
    -d) shift; day="$1" ;;
    -S) shift; path_S="$1" ;;
    -u) shift; ugrid="$1" ;;
    -C) shift; cfosat="$1" ;;
    -J) shift; jason3="$1" ;;
    -o) shift; path_o="$1" ;;
    -H) shift; swh="$1" ;;
    -P) shift; path_py_bin="$1" ;;
    -p) shift; path_tmp_folder="$1" ;;
    -h) help=1 ;;
    --) break ;;
    esac
    shift
done
shift #remove the trailing --

# echo $help
if (( $help == 1 )); then
    usage
    exit 1
fi

# 2.c Get required arguments
# if (( $# == 0 )); then
#     errmsg "No option is set."
#     usage
#     exit 1
# fi

# --------------------------------------------------------------------------- #
# 3. Execute Test                                                             #
# --------------------------------------------------------------------------- #
# 3.a Go to tmp folder and create .py file
rm -rf $path_tmp_folder
mkdir -p $path_tmp_folder
cd $path_tmp_folder
touch parm_satellite_match_python.py

# 3.b .py file, Add import,
cd $path_tmp_folder
cat >> 'parm_satellite_match_python.py' <<'comment'
import a
comment

# 3.c .py file, Read the netcdf data of the background field,
cd $path_tmp_folder
cat >> 'parm_satellite_match_python.py' <<'comment'
import a
comment
Liu-Jincan commented 2 years ago

https://code.visualstudio.com/download

Liu-Jincan commented 2 years ago

/1t/Data-Assimilation-for-Ocean-Current-Forecasts/VSC-workspace

Liu-Jincan commented 2 years ago

https://blog.csdn.net/weixin_39907762/article/details/111450905