o
    Bi                     @   s^   d dl Zd dlZd dlZd dlZejdZ	ej
e	dd dd Zdd Zd	d
 Zdd ZdS )    Nz~/.cfgrib_cacheT)exist_okc           
      C   s   | dd }| dd }| dd }d}| d| d| d|  d}|d	 }t jtd
|  d}t j|rOt j|sOtd|  ddl}||| nt j|r]td|  ntd|  tj	|dd|id}	|	S )ziLoad GPM MERGE data for a specific date.
    Parameters
    date : str
        Date in 'YYYYMMDD' format.N         (/oper/share/ioper/tempo/MERGE/GPM/DAILY///MERGE_CPTEC_.grib2z.idxZMERGE_CPTEC_z
.grib2.idxz&Copying existing index file to cache: r   zUsing existing cached index: z Will create new index in cache: cfgribZ	indexpath)enginebackend_kwargs)
ospathjoin	cache_direxistsprintshutilcopy2xropen_dataset)
dateyearmonthdaybase_dir	file_pathZ
source_idxZ	cache_idxr   ds r   */home/aluno01/jupyter/caso_yaku/data_io.py
load_merge   s(   r    c                 C   sX   | dd }| dd }| dd }d}| d| d| d|  d}t j|r*d	S d
S )sCheck existence of MONAN data for a specific date.
    Parameters
    date : str
        Date in 'YYYYMMDD' format.Nr   r   r   r   r   r   r	   TFr   r   r   )r   r   r   r   r   r   r   r   r   check_merge0   s   r#   c                 C   sV   | dd }| dd }| dd }d}| d|  d|  d| d	}t j|d
d}|S )zeLoad MONAN data for a specific date.
    Parameters
    date : str
        Date in 'YYYYMMDD' format.Nr   r   r   \/pesq/share/bam/dist/paulo.kubota/externo/Curso_da_OMM_2025_estudos_de_casos/Galapagos_YAKU/r   /MONAN_DIAG_R_POS_GFS__.00.00.x1.5898242L55.ncnetcdf4)r   )r   r   )date_run	date_prevr   r   r   r   r   r   r   r   r   
load_monanC   s   r+   c                 C   sL   | dd }| dd }d}| d|  d|  d| d	}t j|r$d
S dS )r!   Nr   r   r   r$   r   r%   r&   r'   TFr"   )r)   r*   r   r   r   r   r   r   r   check_monanX   s   r,   )pandaspdnumpynpxarrayr   r   r   
expanduserr   makedirsr    r#   r+   r,   r   r   r   r   <module>   s   "