³ò
¿ÝýIc           @   sP  d  Z  d d k Z d d k Z d „  Z d „  Z d „  Z d „  Z e d j oýd d k l	 Z	 l
 Z
 l Z l Z d d	 k l Z d d k Z e i d
 e _ e	 e i d ƒ Z e i i e i i e ƒ d ƒ d d Z e
 d e i ƒ Z e d j o
 d Z n e Z e Z e d j o
 d Z nc e d j o d Z d Z nF e d j o
 d Z n/ e d j o
 d Z n e d j o
 d Z n e d e i ƒ Z e d e i ƒ Z e d e i ƒ p e Z e	 e i d ƒ Z e	 e i d ƒ Z e oZ e d j o# e i i e i d d e ƒ Z n e d j o e i i e d ƒ Z qIn e o†e dR d" e f dS dT dU dV dW dX g ƒ Z  e d j o3 d+ e  d# <e i i d, d- d. d/ d0 d1 ƒ e  d$ <nS e d j oE d2 e  d# <e i i d3 d4 d5 d6 d7 d8 ƒ e  d$ <d9 e d: e  d) <n e e  ƒ Z! e i" e ƒ Z# e e! ƒ Z! e e# ƒ Z$ xÜ e! D]ˆ Z% e e% e% i& e ƒ e' e ƒ Z( e$ i) e( ƒ d j oK d; e% GHe i i e e# e$ i* e( ƒ ƒ Z( d< e e( ƒ GHe i+ e( ƒ qFqFWnI e d j o e d= GHe i, ƒ  n% e d j o e d> GHe i, ƒ  n e i i- e ƒ o e. e d? ƒ i/ ƒ  i ƒ  Z! nn e i i0 e ƒ oM e i" e ƒ Z! xH e1 e' e! ƒ ƒ D]# Z2 e i i e e! e2 ƒ e! e2 <q…Wn e d@ e GHe d j o e dA e GHe i, ƒ  n e o4 e e e e e! ƒ e e e e i" e ƒ ƒ ƒ Z! n e e e e! ƒ Z! e' e! ƒ d j o e dB GHe i, ƒ  n e! i3 ƒ  e i4 dC ƒ Z5 e i4 dD ƒ Z$ dE e dF e dG e$ dH e dI e dJ e dK e$ dL dK e5 dL dM g Z6 e. e5 dN ƒ i7 dO i e6 ƒ dO ƒ e! i8 ƒ  e. e$ dN ƒ i7 dO i e! ƒ dO ƒ e i9 e i: dP dP dQ e5 ƒ e i, ƒ  n d S(Y   sü  
#+
# NAME:
#	mag_noaa
# PURPOSE:
#	Downloads daily-updated photospheric magnetic maps from NOAA and
#	run's it through X's HCSS code to make a viable source surface map.
# CALLING SEQUENCE:
#	mag_noaa.py <source> <destination> -ftp -sync -gzip -obs=obs
#	as cron job:
#	bash --login -c "mag_noaa.py"
# OPTIONAL INPUTS:
#	<source>	source of photospheric magnetic field maps
#			This is either a directory containing wso*.dat maps,
#			or a text file with a list of fully-qualified names
#			of wso*.dat files.
#	<destination>	destination directory for source surface maps
#	-ftp		synchronizes files on NOAA ftp server with local files.
#			If -ftp is set then <source>=$DAT/map/wso_noaa and
#			<destination>=$DAT/map/wso_noaa/hcss are used, unless
#			-source and/or -destination are specified.
#	-sync		only processes photospheric maps that do not have
#			a matching source surface file in <destination>
#	-gzip		gzip the output files in <destination> 
#	-obs=obs	observatory; must be one of wso, nso, mwo
#			default is wso (Wilson Solar Observatory)
# CALLS:
#	mirror, xhcs
# PROCEDURE:
#	Currently  magnetic source surface map at 15 solar radii are made.
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS)
#	OCT-2003, Paul Hick (UCSD/CASS)
#		Added mag_noaa_badfiles to exclude files stored in the text
#		file 'badfiles_'+obs+'.txt' located in the destination directory.
#	NOV-2003, Paul Hick (UCSD/CASS)
#		Added a check to detect when a photospheric map downloaded from
#		NOAA overwrites an existing file. In this case the source surface
#		file in the destination directory (produced from the overwritten
#		file) is deleted to make sure that the new file is processed by
#		Xuepus program.
#	OCT-2005, Paul Hick (UCSD/CASS)
#		Modified default for destination directory to subdirectory
#		hcss in source directory.
#	JUN-2006, Paul Hick (UCSD/CASS)
#		nso_ktpk are now downloaded from remote subdirectory 2006
#	FEB-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		nso_ktpk are now downloaded from remote subdirectory 2007
#-
iÿÿÿÿNc         C   s…   g  } xx |  D]p } t  i i | ƒ } | d d j o | d } n | } t  i i | ƒ d } | i t  i i | ƒ d ƒ q W| S(   Ni   s   .gzi    (   t   ost   patht   splitextt   appendt   split(   t   lstt   newlstt   ft   tmp(    (    s   mag_noaa.pyt   mag_noaa_nameonly6   s     !c   	      C   s•   t  | ƒ } t  | ƒ } g  } xp t t | ƒ ƒ D]\ } | | } | | | i |  ƒ t |  ƒ } | i | ƒ d j o | i | | ƒ q1 q1 W| S(   Ni    (   R	   t   ranget   lent   findt   countR   (	   t   obs_lstR   t   obs_reft   reft   lst_nogzt   ref_nogzR   t   iR   (    (    s   mag_noaa.pyt   mag_noaa_diffH   s     
!c         C   sR   g  } xE | D]= } t  i i | ƒ d i |  ƒ d j o | i | ƒ q q W| S(   Ni   i    (   R    R   R   R   R   (   t   obsR   R   t   l(    (    s   mag_noaa.pyt   mag_noaa_obsZ   s     &c   	      C   sÉ   t  i i |  d | d ƒ } t  i i | ƒ o t | d ƒ i ƒ  } | i ƒ  } t | ƒ } t | ƒ } g  } xS t t	 | ƒ ƒ D]5 } | i
 | | ƒ d j o | i | | ƒ q‚ q‚ Wn | } | S(   Nt	   badfiles_s   .txtt   ri    (   R    R   t   joint   existst   opent   readR   R	   R
   R   R   R   (	   t   destinR   R   t   badlistR   R   R   R   R   (    (    s   mag_noaa.pyt   mag_noaa_badfilesc   s     t   __main__(   t   argnt   startt   is_theret   hide_env(   t   mirrort   TUBi    i   s   , s   -obs=t    t   wso_noaat   wsot   wso_arget   nso_ktpkt   svsm_m11lr_B3_crt   nso_noaat   nsot   mwo_noaat   mwos   -ftps   -gzips   -synci   t   DATt   mapt   hcsst   jobt   mag_noaat	   local_dirt   remote_sitet
   remote_dirt   remote_passwords   pphick@ucsd.edut	   recursivet   falset   get_pattt   local_ignores   helios.sec.noaa.govs   /pubt   lmayert   WSAt   synoptict   WSOt   dailys   solarch.tuc.noao.edus	   /synoptict   level3t   vsmt   mergeds
   carr-dailyt   2007t   ^s	   .*fts.gz$s   existing file downloaded: s   removing source surface file: s%   no source file or directory specifieds"   no destination directory specifiedR   s   invalid source specified, s   not yet implemented: s   no new photospheric mapss   .pros   .txts   xhcs, "s   ", destination="s	   ", list="s   ", remote_prefix="s   ", local_prefix="s
   ", gzip=%ds   tmp = do_file(/delete, "s   ", /silent)t   exitt   ws   
t   idls   -quiet(   R5   s   mag_noaa(   R8   R(   (   R9   R(   (   R:   s   pphick@ucsd.edu(   s	   recursiveR<   (   R=   R(   (   R>   R4   (;   t   __doc__t   sysR    R	   R   R   R    t   __name__t   tinyR"   R#   R$   R%   R&   t   tempfilet   environt   tempdirt   argvt   sayR   R   R   R   t   local_prefixt   remote_prefixt   ftpt   gzipt   synct   sourceR   R   t   dictt   argst   new_listt   listdirt   dst_listt   tmp_listt   fileR   R   R   R   t   indext   removeRI   t   isfileR   R   t   isdirR
   R   t   sortt   mktempt   main_prot   linest   writet   reverset   spawnlpt   P_WAIT(    (    (    s   mag_noaa.pys   <module>3   sÊ   					"*




0*	
)
% !	"		 %"	
/	#
#