Bonjour,

Je suis en master de géologie et je dois apprendre python en autonomie. J'aurais besoin d'aide car je rencontre des difficultés dans l'élaboration de mon répertoire de données. Je dois aller récupérer des données sismiques sur le site de IRIS et ensuite les ranger sous forme de dossier.

Je dois créer un dossier correspondant aux dates des différents séismes : folderName
et un dossier correspondant aux stations activées durant le séisme : Name_Stations

Mon soucis est que dans mon programme je n'arrive pas à créer le chemin d'accès me permettant de créer les dossiers "Name_Stations" dans folderName, pouvez-vous m'aider s'il vous plait? Je tiens à préciser que le programme ne marche pas encore, il crée seulement des dossiers pour le moment.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from obspy.clients.fdsn import Client
import numpy as np
from obspy.core import UTCDateTime, read, Stream
import os
 
# Client
client = Client("IRIS")
 
# Date de la période étudiée
starttime=UTCDateTime("2008-06-01")
endtime=UTCDateTime("2013-04-10")
 
#Inventaire des différentes stations de la zone TO
inv_TO = client.get_stations(
        network="TO", starttime=starttime,endtime=endtime, 
        minlatitude=-17, maxlatitude=-13,level="channel", 
        minlongitude=-75, maxlongitude=-70, maxradius=100)  
 
# number of stations for TO network
nb_TO = inv_TO[0].selected_number_of_stations
 
# get coordinates of TO
TO_coords = np.empty([nb_TO, 2])
 
for k in range(nb_TO):
    TO_coords[k,0] = inv_TO[0][k].latitude
    TO_coords[k,1] = inv_TO[0][k].longitude
 
# get station names
TO_sta = ["" for x in range(nb_TO)]
for p in range(nb_TO):
    TO_sta[p] = inv_TO[0][p].code
 
# get event metadata of events within radius=1,5° degrees of stations
event_radius = 1,5 # degrees
for p in range(nb_TO):
    # create empty Stream object
    st = Stream()       
 
    # check if station was active during requested time frame
    act = inv_TO[0][p].is_active(starttime=starttime, endtime=endtime)
    if act is True:
        lat = TO_coords[p,0] # station latitude
        lon = TO_coords[p,1] # station longitude
 
        try:
            TO_events = client.get_events(minlatitude=-17, maxlatitude=-13, minlongitude=-75, maxlongitude=-70,minmagnitude=4, starttime=starttime, endtime=endtime) # produces a Catalog object
# Création fichier données séismes (Mg, localisation, etc)
#            TO_events.write("%s_events.xml" %TO_sta[p], format="QUAKEML")
            n_events = TO_events.count() # number of events found
 
            # request waveform data from origin time minus 1 minute to origin time plus 5 minutes:                       
            for j in range(n_events):
                    # event origin time
                    otime = UTCDateTime(TO_events[j].origins[0].time)
 
                    # Création dossier avec pour nom la date des séismes    
                    Name = str(otime)
                    Name = Name.replace(':', '-')
                    folderName = Name
                    os.makedirs("C:/Users/Aurore/Desktop/Stage M2/Python/Repertoire Donnees/" + folderName)                      
 
                # Création dossier stations par séismes
                    for k in range(nb_TO):
                        stations = inv_TO[0][k].code
                        Name_Stations = str(stations)
                        os.makedirs(os.path.join('C:/Users/Aurore/Desktop/Stage M2/Python/Repertoire Donnees/' + Name_Stations))
 
                     #  Retourne le dossier parent de l'élément
#                        dirname(p)
 
                        try:
                            st += client.get_waveforms("TO",TO_sta[p],"*","???",otime-60, otime+5*60)
                            print ('Waveform data found for station %s event %i!' %(TO_sta[p],j+1))
                        except Exception:
                            print ('No waveform data found for station %s event %i...' %(TO_sta[p],j+1))
                            continue
 
            TO_events.plot(projection="local",title="Event locations %s" %TO_sta[p]) 
            st.plot()
            # write data to file
            st.write("%s_data.MSEED" %TO_sta[p], format="MSEED")
        except Exception:
            print ('No events found for station %s...' %TO_sta[p])
            continue
    else:
        print ('Station %s was not active in requested time frame' %TO_sta[p])


Merci d'avance pour vos réponses