Commits
Pam Ford authored d62d2389590
357 357 | if (pwv == 0.0) { |
358 358 | if (telescopeName_=="ALMA") pwv = 1.0; |
359 359 | else pwv = 5.0; |
360 360 | parent_->logmesg("load_cache", |
361 361 | "Using default pwv " + casacore::String::toString(pwv) + " for telescope " + telescopeName_); |
362 362 | } |
363 363 | pwv_ = pwv; |
364 364 | } |
365 365 | |
366 366 | void PlotMSAtm::getMeanWeather() { |
367 - | // Info from MS WEATHER table in weather_ Record |
368 - | // set defaults |
369 - | casacore::Float pressure, humidity(20.0), temperature(273.15); |
370 - | // NB: plotbandpass uses default pressure 563 in all cases; |
371 - | // see CAS-9053 algorithm #2 |
372 - | pressure = (telescopeName_=="ALMA" ? 563.0 : 786.0); // mb |
373 - | |
374 - | // values from WEATHER table if it exists |
375 - | bool noWeather(false); |
367 + | // Fill weather_ Record with mean values from MS WEATHER table |
368 + | // Set defaults; CAS-9053 default pressure depends on telescope |
369 + | casacore::Float humidity(20.0), temperature(273.15); |
370 + | casacore::Float pressure = (telescopeName_=="ALMA" ? 563.0 : 786.0); // mb |
371 + | |
372 + | // Use values from WEATHER table if it exists |
373 + | bool noWeather(true); |
376 374 | if (!tableName_.empty()) { |
377 - | casacore::Table mstab(tableName_); |
378 - | if (mstab.keywordSet().fieldNumber("WEATHER") > -1) { |
379 - | casacore::String subname = tableName_ + "::WEATHER"; |
380 - | try { |
381 - | casacore::Table subtable = Table::openTable(subname); |
382 - | // get columns and temp. units |
383 - | casacore::Vector<casacore::Float> pressureCol, humidityCol, |
384 - | temperatureCol; |
385 - | casacore::Vector<casacore::Double> timeCol; |
386 - | pressureCol = ScalarColumn<casacore::Float>(subtable, "PRESSURE").getColumn(); |
387 - | humidityCol = ScalarColumn<casacore::Float>(subtable, "REL_HUMIDITY").getColumn(); |
388 - | ScalarColumn<casacore::Float> tempColumn = |
389 - | ScalarColumn<casacore::Float>(subtable, "TEMPERATURE"); |
390 - | temperatureCol = tempColumn.getColumn(); |
391 - | casacore::String units = |
392 - | tempColumn.keywordSet().asArrayString("QuantumUnits").tovector()[0]; |
393 - | timeCol = ScalarColumn<casacore::Double>(subtable, "TIME").getColumn(); |
394 - | mstab.closeSubTables(); |
395 - | |
396 - | // now select based on cal times |
397 - | casacore::Vector<casacore::Float> selpressure, selhumidity, |
398 - | seltemperature; |
399 - | // pressure |
400 - | if (!pressureCol.empty()) { |
401 - | selpressure = getValuesNearTimes(pressureCol, timeCol); |
402 - | if (!selpressure.empty()) pressure = mean(selpressure); |
403 - | } |
404 - | // humidity |
405 - | if (!humidityCol.empty()) { |
406 - | selhumidity = getValuesNearTimes(humidityCol, timeCol); |
407 - | if (!selhumidity.empty()) humidity = mean(selhumidity); |
408 - | } |
409 - | // temperature |
410 - | if (!temperatureCol.empty()) { |
411 - | seltemperature = getValuesNearTimes(temperatureCol, timeCol); |
412 - | if (!seltemperature.empty()) { |
413 - | temperature = mean(seltemperature); |
414 - | if (units.compare("K")!=0) |
415 - | temperature += (float)273.15; // convert C to K |
416 - | } |
375 + | try { |
376 + | // openTable throws exception if table doesn't exist |
377 + | casacore::Table wtable = Table::openTable(tableName_ + "::WEATHER"); |
378 + | TableColumn tempCol = TableColumn(wtable, "TEMPERATURE"); |
379 + | String tempUnits = tempCol.keywordSet().asArrayString("QuantumUnits").tovector()[0]; |
380 + | // select valid stations and values in range |
381 + | casacore::Table selwtable = selectWeatherTable(wtable, tempUnits); |
382 + | |
383 + | // get columns |
384 + | casacore::Vector<casacore::Float> |
385 + | pressureCol(ScalarColumn<casacore::Float>(selwtable, "PRESSURE").getColumn()), |
386 + | humidityCol(ScalarColumn<casacore::Float>(selwtable, "REL_HUMIDITY").getColumn()), |
387 + | temperatureCol(ScalarColumn<casacore::Float>(selwtable, "TEMPERATURE").getColumn()); |
388 + | casacore::Vector<casacore::Double> |
389 + | timeCol(ScalarColumn<casacore::Double>(selwtable, "TIME").getColumn()); |
390 + | |
391 + | // select values based on cal times |
392 + | casacore::Vector<casacore::Float> selpressure, selhumidity, seltemperature; |
393 + | casacore::Float meanp(0.0), meanh(0.0), meant(0.0); |
394 + | // pressure |
395 + | if (!pressureCol.empty()) { |
396 + | selpressure = getValuesNearTimes(pressureCol, timeCol); |
397 + | if (!selpressure.empty()) |
398 + | meanp = mean(selpressure); |
399 + | if (meanp==0.0) |
400 + | parent_->logmesg("load_cache", "WEATHER pressure is zero, using default value instead."); |
401 + | else |
402 + | pressure = meanp; |
403 + | } |
404 + | // humidity |
405 + | if (!humidityCol.empty()) { |
406 + | selhumidity = getValuesNearTimes(humidityCol, timeCol); |
407 + | if (!selhumidity.empty()) |
408 + | meanh = mean(selhumidity); |
409 + | if (meanh==0.0) |
410 + | parent_->logmesg("load_cache", "WEATHER humidity is zero, using default value instead."); |
411 + | else |
412 + | humidity = meanh; |
413 + | } |
414 + | |
415 + | // temperature |
416 + | if (!temperatureCol.empty()) { |
417 + | seltemperature = getValuesNearTimes(temperatureCol, timeCol); |
418 + | if (!seltemperature.empty()) |
419 + | meant = mean(seltemperature); |
420 + | if (meant==0.0) { |
421 + | parent_->logmesg("load_cache", "WEATHER temperature is zero, using default value instead."); |
422 + | } else { |
423 + | if (tempUnits=="C") meant += (float)273.15; // convert C to K |
424 + | temperature = meant; |
417 425 | } |
418 - | } catch (AipsError & err) { |
419 - | noWeather = true; |
420 426 | } |
421 - | } else { |
422 - | noWeather = true; |
427 + | noWeather = false; |
428 + | } catch (AipsError & err) { |
429 + | cout << err.getMesg() << endl; |
423 430 | } |
424 - | } else { |
425 - | noWeather = true; |
426 - | } |
427 - | if (noWeather) { |
428 - | parent_->logmesg("load_cache", "Could not open WEATHER table, using default values: humidity " + casacore::String::toString(humidity) + ", pressure " + casacore::String::toString(pressure) + ", temperature " + casacore::String::toString(temperature) + " for Atm/Tsky"); |
429 - | } |
430 - | // reset to defaults |
431 - | if (humidity==0.0) { |
432 - | humidity = 20.0; |
433 - | parent_->logmesg("load_cache", "WEATHER table humidity is 0.0, using default value " + casacore::String::toString(humidity)); |
434 - | } |
435 - | if (pressure==0.0) { |
436 - | pressure = (telescopeName_=="ALMA" ? 563.0 : 786.0); // mb |
437 - | parent_->logmesg("load_cache", "WEATHER table pressure is 0.0, using default value " + casacore::String::toString(pressure)); |
438 - | } |
439 - | if (temperature==0.0) { |
440 - | temperature = 273.15; |
441 - | parent_->logmesg("load_cache", "WEATHER table temperature is 0.0, using default value " + casacore::String::toString(temperature)); |
442 431 | } |
432 + | |
433 + | String msg = "Using"; |
434 + | msg += (noWeather ? " default " : " "); |
435 + | msg += "weather values for Atm/Tsky:\n"; |
436 + | msg += " humidity " + casacore::String::toString(humidity) + |
437 + | ", pressure " + casacore::String::toString(pressure) + |
438 + | ", temperature " + casacore::String::toString(temperature); |
439 + | parent_->logmesg("load_cache", msg); |
443 440 | // to use in atmosphere.initAtmProfile (tool) |
444 441 | weather_.define("humidity", humidity); // % |
445 442 | weather_.define("pressure", pressure); // mb |
446 443 | weather_.define("temperature", temperature); // K |
447 444 | } |
448 445 | |
446 + | Table PlotMSAtm::selectWeatherTable(Table& wtable, String tempUnits) { |
447 + | // Remove invalid station, values from weather table |
448 + | TableExprNode ten; |
449 + | if (telescopeName_=="ALMA") { |
450 + | try { |
451 + | // do not use weather station "MeteoItinerant" |
452 + | casacore::Table staTable = Table::openTable(tableName_ + "::ASDM_STATION"); |
453 + | casacore::Table result = staTable(staTable.col("name")=="MeteoItinerant"); |
454 + | Vector<uInt> antIds = result.rowNumbers(staTable); |
455 + | if (!antIds.empty()) ten = (wtable.col("NS_WX_STATION_ID") != antIds(0)); |
456 + | } catch (AipsError & err) { |
457 + | // table does not exist |
458 + | } |
459 + | } |
460 + | // SCIREQ-1241 |
461 + | // temperature in the range -30 to +30C |
462 + | // pressure in the range 450 to 800mb |
463 + | // Humidity in the range -10 to +110% |
464 + | Float mintemp = (tempUnits=="C" ? -30.0 : 243.15); |
465 + | Float maxtemp = (tempUnits=="C" ? 30.0 : 303.15); |
466 + | ten = ten && (wtable.col("TEMPERATURE")>=mintemp && wtable.col("TEMPERATURE")<=maxtemp); |
467 + | ten = ten && (wtable.col("PRESSURE")>=450.0 && wtable.col("PRESSURE")<=800.0); |
468 + | ten = ten && (wtable.col("REL_HUMIDITY")>=-10.0 && wtable.col("REL_HUMIDITY")<=110.0); |
469 + | casacore::Table selwtable(wtable(ten)); |
470 + | return selwtable; |
471 + | } |
472 + | |
449 473 | casacore::Double PlotMSAtm::computeMeanAirmass() { |
450 474 | // Calculate airmass from elevation |
451 475 | casacore::Vector<casacore::Double> airmasses; |
452 476 | airmasses.resize(fields_.size()); |
453 477 | casacore::Double elevation; |
454 478 | for (uInt i=0; i<fields_.size(); ++i) { |
455 479 | elevation = getElevation(fields_(i)); |
456 480 | if (elevation <= 3.0) elevation = 45.0; |
457 481 | airmasses(i) = 1.0 / std::cos((90.0 - elevation) * C::pi / 180.0); |
458 482 | } |