147 | | def plotAll(source, destination, force): |
---|
| 147 | |
---|
| 148 | def plotLatest(filein, pathout): |
---|
| 149 | """ |
---|
| 150 | Plot latest sodar raw data file. |
---|
| 151 | |
---|
| 152 | plotLatest(filein, pathout) -> rc |
---|
| 153 | |
---|
| 154 | filein - path to raw data file. |
---|
| 155 | pathout - path to plot images directory. |
---|
| 156 | rc - 0 if successful |
---|
| 157 | """ |
---|
| 158 | |
---|
| 159 | if not os.path.exists(pathout): |
---|
| 160 | os.makedirs(pathout, mode=0775) |
---|
| 161 | |
---|
| 162 | try: |
---|
| 163 | rawDataHandle = openAnything.openAnything(filein) |
---|
| 164 | rawDataString = rawDataHandle.read() |
---|
| 165 | rawDataHandle.close() |
---|
| 166 | except: |
---|
| 167 | raise IOError("Failure to read raw data.") |
---|
| 168 | |
---|
| 169 | rawDataObject = a.rawData.RawData(rawDataString) |
---|
| 170 | formattedDataObject = a.formattedData.FormattedData(rawDataObject) |
---|
| 171 | arrayDataObject = a.ArrayData(formattedDataObject) |
---|
| 172 | |
---|
| 173 | beginStamp = arrayDataObject.beginStamp |
---|
| 174 | endStamp = arrayDataObject.endStamp |
---|
| 175 | numIntervals = arrayDataObject.numIntervals |
---|
| 176 | timeInterval = arrayDataObject.timeInterval |
---|
| 177 | minAltitude = arrayDataObject.minAltitude |
---|
| 178 | numAltitudes = arrayDataObject.numAltitudes |
---|
| 179 | altInterval = arrayDataObject.altInterval |
---|
| 180 | |
---|
| 181 | def makePcolor(vector, title, fileout, cbLabel): |
---|
| 182 | fig = p.figure(1) |
---|
| 183 | axe = fig.add_subplot(1, 1, 1) |
---|
| 184 | pc = axe.pcolor(vector) |
---|
| 185 | |
---|
| 186 | axe.set_xlabel('Time (hh:mm UTC)') |
---|
| 187 | axe.set_ylabel('Altitude (m)') |
---|
| 188 | axe.set_xbound(upper=numIntervals) |
---|
| 189 | |
---|
| 190 | xticks = axe.get_xticks() |
---|
| 191 | xticklabels = [(int(x) * timeInterval) + beginStamp |
---|
| 192 | for x in xticks] |
---|
| 193 | xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) |
---|
| 194 | for x in xticklabels] |
---|
| 195 | axe.set_xticklabels(xticklabels) |
---|
| 196 | |
---|
| 197 | yticks = axe.get_yticks() |
---|
| 198 | yticklabels = [str(y * altInterval + minAltitude) |
---|
| 199 | for y in yticks] |
---|
| 200 | axe.set_yticklabels(yticklabels) |
---|
| 201 | |
---|
| 202 | axe.set_title(title) |
---|
| 203 | cb = p.colorbar(pc) |
---|
| 204 | cb.set_label(cbLabel) |
---|
| 205 | |
---|
| 206 | fig.savefig(os.path.join(pathout, fileout)) |
---|
| 207 | fig.clear() |
---|
| 208 | |
---|
| 209 | return 0 |
---|
| 210 | |
---|
| 211 | uComponents = arrayDataObject.uComponents |
---|
| 212 | maskedUComponents = n.ma.masked_where(n.isnan(uComponents), |
---|
| 213 | uComponents) |
---|
| 214 | makePcolor(maskedUComponents.T, |
---|
| 215 | 'U Component of Wind Veloctiy for %s' % |
---|
| 216 | (str(beginStamp)[:10],), |
---|
| 217 | 'ims_sodar_latest_uComponents.png', |
---|
| 218 | 'Speed (cm/sec)') |
---|
| 219 | |
---|
| 220 | vComponents = arrayDataObject.vComponents |
---|
| 221 | maskedVComponents = n.ma.masked_where(n.isnan(vComponents), |
---|
| 222 | vComponents) |
---|
| 223 | makePcolor(maskedVComponents.T, |
---|
| 224 | 'V Component of Wind Veloctiy for %s' % |
---|
| 225 | (str(beginStamp)[:10],), |
---|
| 226 | 'ims_sodar_latest_vComponents.png', |
---|
| 227 | 'Speed (cm/sec)') |
---|
| 228 | |
---|
| 229 | wComponents = arrayDataObject.wComponents |
---|
| 230 | maskedWComponents = n.ma.masked_where(n.isnan(wComponents), |
---|
| 231 | wComponents) |
---|
| 232 | makePcolor(maskedWComponents.T, |
---|
| 233 | 'W Component of Wind Veloctiy for %s' % |
---|
| 234 | (str(beginStamp)[:10],), |
---|
| 235 | 'ims_sodar_latest_wComponents.png', |
---|
| 236 | 'Speed (cm/sec)') |
---|
| 237 | |
---|
| 238 | echoStrengths = arrayDataObject.echoStrengths |
---|
| 239 | maskedEchoStrenths = n.ma.masked_where(n.isnan(echoStrengths), |
---|
| 240 | echoStrengths) |
---|
| 241 | makePcolor(maskedEchoStrenths.T, |
---|
| 242 | 'Echo Strength for %s' % |
---|
| 243 | (str(beginStamp)[:10],), |
---|
| 244 | 'ims_sodar_latest_echoStrengths.png', |
---|
| 245 | 'Strength (no units)') |
---|
| 246 | |
---|
| 247 | # timeComponent = n.array(range(numIntervals)) |
---|
| 248 | # altComponent = n.array(range(numAltitudes)) |
---|
| 249 | # fig = p.figure(1) |
---|
| 250 | # axe = fig.add_subplot(1, 1, 1) |
---|
| 251 | # qv = axe.quiver(altComponent, |
---|
| 252 | # timeComponent, |
---|
| 253 | # maskedUComponents.T, |
---|
| 254 | # maskedVComponents.T) |
---|
| 255 | |
---|
| 256 | # axe.set_xlabel('Time (min)') |
---|
| 257 | # axe.set_ylabel('Altitude (m)') |
---|
| 258 | # axe.set_xbound(upper=numIntervals) |
---|
| 259 | |
---|
| 260 | # xticks = axe.get_xticks() |
---|
| 261 | # xticklabels = [(int(x) * timeInterval) + beginStamp |
---|
| 262 | # for x in xticks] |
---|
| 263 | # xticklabels = [':'.join(('%02u' % x.hour, '%02u' % x.minute)) |
---|
| 264 | # for x in xticklabels] |
---|
| 265 | # axe.set_xticklabels(xticklabels) |
---|
| 266 | |
---|
| 267 | # yticks = axe.get_yticks() |
---|
| 268 | # yticklabels = [str(y * altInterval + minAltitude) |
---|
| 269 | # for y in yticks] |
---|
| 270 | # axe.set_yticklabels(yticklabels) |
---|
| 271 | |
---|
| 272 | # axe.set_title('Wind Velocty for %s' % |
---|
| 273 | # (str(beginStamp)[:10],)) |
---|
| 274 | # cb = p.colorbar(qv) |
---|
| 275 | # cb.set_label('W Component Speed (cm/sec)') |
---|
| 276 | |
---|
| 277 | # fig.savefig(os.path.join(pathout, 'ims_sodar_latest_quiver.png')) |
---|
| 278 | # fig.clear() |
---|
| 279 | |
---|
| 280 | return 0 |
---|
| 281 | |
---|
| 282 | def plotAll(source, destination, latest, force): |
---|