Commit 96e47871 authored by CEVAER's avatar CEVAER

Added ORM dependencies, added extract file date, finding track points for that date.

parent bbc02554
# smap_cyclones
Package used to adapt SMAP data for a cyclone oriented usage.
Provide scripts to extract cyclone data from SMAP NetCDF files.
\ No newline at end of file
#!/usr/bin/env python
import argparse
import logging
import datetime
import os
import sys
from sqlalchemy import create_engine, and_
from sqlalchemy.orm import sessionmaker
from cyclobs_orm import SimpleTrack
logging.basicConfig()
logger = logging.getLogger(os.path.basename(__file__))
logger.setLevel(logging.INFO)
def extractDateFromFilename(filename):
datePart = "-".join(filename.split("_")[4:7])
return datetime.datetime.strptime(datePart, "%Y-%m-%d")
def getTrackPointsFromDatabase(session, smapDate):
reqTracks = session.query(SimpleTrack).filter(and_(SimpleTrack.date >= smapDate,
SimpleTrack.date < smapDate + datetime.timedelta(days=1))).all()
return reqTracks
def processSmapFile(session, file):
logger.debug(f"Processing {file}...")
fileDate = extractDateFromFilename(os.path.basename(file))
logger.debug(f"File date {fileDate}")
trackPoints = getTrackPointsFromDatabase(session, fileDate)
logger.debug(f"{trackPoints}")
trakcPointsPerSid = {trackPoint.sid: trackPoint for trackPoint in trackPoints}
if __name__ == "__main__":
pass
\ No newline at end of file
description = """
Read SMAP netCDF files from a directory, extract the wind data of cyclones and save it into a new netCDF file.
"""
parser = argparse.ArgumentParser(description=description)
parser.add_argument("--dbd", action="store", type=str, required=True, help='database (postgresql://user:pass@host:5432/base_name)')
parser.add_argument("--debug", action="store_true", default=False, help="Run in debug mode (verbose output)")
args = parser.parse_args()
if sys.gettrace():
logger.setLevel(logging.DEBUG)
if args.debug:
logger.setLevel(logging.DEBUG)
engine = create_engine(args.dbd)
Session = sessionmaker(bind=engine)
smapTests = ["/home/datawork-cersat-public/provider/remss/satellite/l3/smap/smap/wind/v1.0/daily/2020/110/RSS_smap_wind_daily_2020_04_19_v01.0.nc",
"/home/datawork-cersat-public/provider/remss/satellite/l3/smap/smap/wind/v1.0/daily/2020/025/RSS_smap_wind_daily_2020_01_25_v01.0.nc"
]
for f in smapTests:
processSmapFile(Session(), f)
......@@ -5,11 +5,13 @@ from pathlib import Path
import glob
install_requires = [
'sqlalchemy',
'cyclobs_orm'
]
setup(name='smap_cyclones',
description='cyclobs web server',
description='Package used to adapt SMAP data for a cyclone oriented usage.',
url='https://gitlab.ifremer.fr/cyclobs/cyclobs',
author = "Théo CEVAER",
author_email = "theo.cevaer@ifremer.fr",
......@@ -18,7 +20,7 @@ setup(name='smap_cyclones',
include_package_data=True,
scripts=glob.glob('bin/**'),
use_scm_version=True,
setup_requires=['setuptools_scm'ss],
setup_requires=['setuptools_scm'],
install_requires=install_requires,
data_files=[ (os.path.dirname(p) , [p] ) for p in glob.glob('etc/**',recursive=True) if not os.path.isdir(p) ],
zip_safe = False
......
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