ucar.nc2.units.DateRange Java Examples

The following examples show how to use ucar.nc2.units.DateRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvDatasetFcFmrc.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<DatasetBuilder> makeRunDatasets(DatasetBuilder parent) throws IOException {
  List<DatasetBuilder> datasets = new ArrayList<>();

  for (CalendarDate runDate : fmrc.getRunDates()) {
    String myname = name + "_" + RUN_NAME + runDate;
    myname = StringUtil2.replace(myname, ' ', "_");

    DatasetBuilder nested = new DatasetBuilder(parent);
    nested.setName(myname);
    nested.put(Dataset.UrlPath, this.configPath + "/" + RUNS + "/" + myname);
    nested.put(Dataset.Id, this.configPath + "/" + RUNS + "/" + myname);
    nested.addToList(Dataset.Documentation,
        new Documentation(null, null, null, "summary", "Data from Run " + myname));
    CalendarDateRange cdr = fmrc.getDateRangeForRun(runDate);
    if (cdr != null)
      nested.put(Dataset.TimeCoverage, new DateRange(cdr));
    datasets.add(nested);
  }

  Collections.reverse(datasets);
  return datasets;
}
 
Example #2
Source File: CatalogViewContextParser.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setTimeCoverage(Dataset ds) {
  DateRange tc = ds.getTimeCoverage();
  this.timeCoverage = new HashMap<>();
  if (tc != null) {
    DateType start = tc.getStart();
    if (start != null)
      this.timeCoverage.put("start", start.toString());
    DateType end = tc.getEnd();
    if (end != null)
      this.timeCoverage.put("end", end.toString());
    TimeDuration duration = tc.getDuration();
    if (duration != null)
      this.timeCoverage.put("duration", duration.toString());
    TimeDuration resolution = tc.getResolution();
    if (resolution != null)
      this.timeCoverage.put("resolution", resolution.toString());
  }
}
 
Example #3
Source File: StationRadialViewer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setDataset(FeatureDataset dataset) {
  this.sds = (StationRadialDataset) dataset;

  if (debugStationDatsets)
    System.out.println("PointObsViewer open type " + dataset.getClass().getName());
  CalendarDate startDate = dataset.getCalendarDateStart();
  CalendarDate endDate = dataset.getCalendarDateEnd();
  if ((startDate != null) && (endDate != null))
    chooser.setDateRange(new DateRange(startDate.toDate(), endDate.toDate()));

  List<StationBean> stationBeans = new ArrayList<>();
  List<Station> stations = sds.getStations();
  if (stations == null)
    return;

  for (Station station : stations)
    stationBeans.add(new StationBean(station));

  stnTable.setBeans(stationBeans);
  chooser.setStations(stationBeans);
  rdTable.clear();
}
 
Example #4
Source File: InvCatalogFactory10.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected DateRange readTimeCoverage(Element tElem) {
  if (tElem == null)
    return null;

  DateType start = readDate(tElem.getChild("start", defNS));
  DateType end = readDate(tElem.getChild("end", defNS));
  TimeDuration duration = readDuration(tElem.getChild("duration", defNS));
  TimeDuration resolution = readDuration(tElem.getChild("resolution", defNS));

  try {
    return new DateRange(start, end, duration, resolution);
  } catch (java.lang.IllegalArgumentException e) {
    factory.appendWarning(" ** warning: TimeCoverage error = " + e.getMessage() + "\n");
    return null;
  }
}
 
Example #5
Source File: InvDatasetFcFmrc.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<DatasetBuilder> makeOffsetDatasets(DatasetBuilder parent) throws IOException {
  List<DatasetBuilder> datasets = new ArrayList<>();

  for (double offset : fmrc.getForecastOffsets()) {
    String myname = name + "_" + OFFSET_NAME + offset + "hr";
    myname = StringUtil2.replace(myname, ' ', "_");

    DatasetBuilder nested = new DatasetBuilder(parent);
    nested.setName(myname);
    nested.put(Dataset.UrlPath, this.configPath + "/" + OFFSET + "/" + myname);
    nested.put(Dataset.Id, this.configPath + "/" + OFFSET + "/" + myname);
    nested.addToList(Dataset.Documentation, new Documentation(null, null, null, "summary",
        "Data from the " + offset + " hour forecasts, across different model runs."));
    CalendarDateRange cdr = fmrc.getDateRangeForOffset(offset);
    if (cdr != null)
      nested.put(Dataset.TimeCoverage, new DateRange(cdr));
    datasets.add(nested);
  }

  return datasets;
}
 
Example #6
Source File: InvDatasetFcFmrc.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<DatasetBuilder> makeForecastDatasets(DatasetBuilder parent) throws IOException {

    List<DatasetBuilder> datasets = new ArrayList<>();

    for (CalendarDate forecastDate : fmrc.getForecastDates()) {
      String myname = name + "_" + FORECAST_NAME + forecastDate;
      myname = StringUtil2.replace(myname, ' ', "_");

      DatasetBuilder nested = new DatasetBuilder(parent);
      nested.setName(myname);
      nested.put(Dataset.UrlPath, this.configPath + "/" + FORECAST + "/" + myname);
      nested.put(Dataset.Id, this.configPath + "/" + FORECAST + "/" + myname);
      nested.addToList(Dataset.Documentation, new Documentation(null, null, null, "summary",
          "Data with the same forecast date, " + name + ", across different model runs."));
      nested.put(Dataset.TimeCoverage, new DateRange(CalendarDateRange.of(forecastDate, forecastDate)));
      datasets.add(nested);
    }

    return datasets;
  }
 
Example #7
Source File: CatalogBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected DateRange readTimeCoverage(Element tElem) {
  if (tElem == null) {
    return null;
  }

  Calendar calendar = readCalendar(tElem.getAttributeValue("calendar"));
  DateType start = readDate(tElem.getChild("start", Catalog.defNS), calendar);
  DateType end = readDate(tElem.getChild("end", Catalog.defNS), calendar);

  TimeDuration duration = readDuration(tElem.getChild("duration", Catalog.defNS));
  TimeDuration resolution = readDuration(tElem.getChild("resolution", Catalog.defNS));

  try {
    return new DateRange(start, end, duration, resolution);
  } catch (java.lang.IllegalArgumentException e) {
    errlog.format(" ** warning: TimeCoverage error ='%s'%n", e.getMessage());
    logger.debug(" ** warning: TimeCoverage error ='{}'", e.getMessage());
    return null;
  }
}
 
Example #8
Source File: DatasetEnhancer1.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean addMetadata(InvDataset dataset) {
  // <dataset name="2005061512_NAM.wmo" urlPath="2005061512_NAM.wmo"/>
  java.util.regex.Matcher matcher = this.pattern.matcher(dataset.getName());
  if (!matcher.find())
    return (false); // Pattern not found.
  StringBuffer startTime = new StringBuffer();
  matcher.appendReplacement(startTime, this.substitutionPattern);
  startTime.delete(0, matcher.start());

  try {
    ((InvDatasetImpl) dataset).setTimeCoverage(
        new DateRange(new DateType(startTime.toString(), null, null), null, new TimeDuration(this.duration), null));
  } catch (ParseException e) {
    logger.debug("Start time <" + startTime.toString() + "> or duration <" + this.duration + "> not parsable: "
        + e.getMessage());
    return (false);
  }
  ((InvDatasetImpl) dataset).finish();

  return (true);
}
 
Example #9
Source File: InvDatasetFcGrib.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeDatasetsFromGroups(URI catURI, DatasetBuilder parent, String parentPath,
    Iterable<GribCollectionImmutable.GroupGC> groups, boolean isSingleGroup) {

  for (GribCollectionImmutable.GroupGC group : groups) {
    DatasetBuilder ds;
    String dpath;
    if (isSingleGroup) {
      ds = parent;
      dpath = parentPath;
      ds.put(Dataset.Id, parentPath);
      ds.put(Dataset.UrlPath, parentPath);

    } else {
      ds = new DatasetBuilder(parent);
      ds.setName(group.getDescription());

      dpath = parentPath + "/" + group.getId();
      ds.put(Dataset.Id, dpath);
      ds.put(Dataset.UrlPath, dpath);

      // remove the urlPath on the parent if multiple groups;
      // cannot get a dataset with multiple groups in it
      // parent.put(Dataset.UrlPath, null);
      parent.addDataset(ds);
    }

    ThreddsMetadata tmi = ds.getInheritableMetadata();
    tmi.set(Dataset.GeospatialCoverage, extractGeospatial(group));
    tmi.set(Dataset.TimeCoverage, new DateRange(group.makeCalendarDateRange()));
    tmi.set(Dataset.VariableMapLinkURI, makeUriResolved(catURI, makeMetadataLink(dpath, VARIABLES)));
  }
}
 
Example #10
Source File: TimeRangeFilter.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean accept(OpendapLeaf leaf) {
    DateRange timeCoverage = leaf.getDataset().getTimeCoverage();
    if (timeCoverage != null) {
        return fitsToServerSpecifiedTimeRange(timeCoverage);
    }
    return timeStampExtractor == null || fitsToUserSpecifiedTimeRange(leaf);
}
 
Example #11
Source File: TimeRangeFilter.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private boolean fitsToServerSpecifiedTimeRange(DateRange dateRange) {
    if (startDate == null && endDate == null) {
        return true;
    } else if (startDate == null) {
        return endsAtOrBeforeEndDate(dateRange);
    } else if (endDate == null) {
        return startsAtOrAfterStartDate(dateRange);
    }
    return startsAtOrAfterStartDate(dateRange) && endsAtOrBeforeEndDate(dateRange);
}
 
Example #12
Source File: RadarServerConfig.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static DateRange readTimeCoverage(Element tElem) {
  if (tElem == null)
    return null;
  Namespace defNS = tElem.getNamespace();
  DateType start = readDate(tElem.getChild("start", defNS));
  DateType end = readDate(tElem.getChild("end", defNS));
  TimeDuration duration = readDuration(tElem.getChild("duration", defNS));
  TimeDuration resolution = readDuration(tElem.getChild("resolution", defNS));

  try {
    return new DateRange(start, end, duration, resolution);
  } catch (java.lang.IllegalArgumentException e) {
    return null;
  }
}
 
Example #13
Source File: NcssParamsBean.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public CalendarDateRange makeCalendarDateRange(Calendar cal) {
  try {
    // this handles "present"
    DateRange dr = new DateRange(new DateType(time_start, null, null, cal), new DateType(time_end, null, null, cal),
        new TimeDuration(time_duration), null);
    return CalendarDateRange.of(dr.getStart().getCalendarDate(), dr.getEnd().getCalendarDate());
  } catch (ParseException pe) {
    return null; // ??
  }
}
 
Example #14
Source File: PointFeatureDatasetViewer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void subset(LatLonRect geoRegion, DateRange dateRange) throws IOException {
  PointFeatureCollection pc = null;
  CalendarDateRange cdr = CalendarDateRange.of(dateRange);

  if (selectedType == FeatureType.POINT) {
    PointFeatureCollection ptCollection = (PointFeatureCollection) selectedCollection;
    pc = ptCollection.subset(geoRegion, cdr);

  } else if (selectedType == FeatureType.STATION) {
    StationTimeSeriesFeatureCollection stationCollection = (StationTimeSeriesFeatureCollection) selectedCollection;
    /*
     * if (geoRegion != null) {
     * StationTimeSeriesFeatureCollection stationSubset = stationCollection.subset(geoRegion);
     * setStations( stationSubset);
     * return;
     * } else {
     */
    pc = stationCollection.flatten(geoRegion, cdr);
    // } LOOK
  }
  /*
   * else if (selectedType == FeatureType.STATION_PROFILE) {
   * StationProfileFeatureCollection stationProfileCollection = (StationProfileFeatureCollection) selectedCollection;
   * pc = stationProfileCollection.flatten(geoRegion, cdr);
   * }
   */

  if (null != pc) {
    setObservations(pc);
  }
}
 
Example #15
Source File: TimeRangeFilterTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private OpendapLeaf createLeaf() {
    return new OpendapLeaf("", new InvDataset(null, "") {
        @Override
        public DateRange getTimeCoverage() {
            return new DateRange(new GregorianCalendar(2010, 0, 1).getTime(), new GregorianCalendar(2011, 0, 1).getTime());
        }
    });
}
 
Example #16
Source File: StationRegionDateChooser.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setDateRange(DateRange range) {
  dateSelector.setDateRange(range);
}
 
Example #17
Source File: RadarDataInventory.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateRange getTimeCoverage() {
  return this.timeCoverage;
}
 
Example #18
Source File: RadarDataInventory.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setTimeCoverage(DateRange range) {
  this.timeCoverage = range;
}
 
Example #19
Source File: RadarServerController.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@RequestMapping(value = "**/dataset.xml")
@ResponseBody
public HttpEntity<byte[]> datasetCatalog(final HttpServletRequest request) throws IOException {
  if (!enabled)
    return null;

  String URLbase = tdsContext.getContextPath() + "/" + entryPoint;

  // Check the user-agent to try to guess if this request is coming from
  // the IDV--if so, we'll need to tweak the returned catalog XML.
  String agent = request.getHeader("user-agent");
  boolean makeIDVCatalog = false;
  if (agent != null && agent.startsWith("Java/1."))
    makeIDVCatalog = true;

  // Parse the request URL to get the name of the dataset that was
  // requested.
  String dataset = parseDatasetFromURL(request, "/dataset.xml");
  RadarDataInventory di = getInventory(dataset);

  CatalogBuilder cb = new CatalogBuilder();
  cb.addService(new Service("radarServer", URLbase, "DQC", null, null, new ArrayList<Service>(),
      new ArrayList<Property>(), null));
  cb.setName("Radar Data");

  DatasetBuilder mainDB = new DatasetBuilder(null);
  mainDB.setName(di.getName());
  mainDB.put(Dataset.Id, dataset);
  mainDB.put(Dataset.UrlPath, dataset);
  mainDB.put(Dataset.DataFormatType, di.getDataFormat());
  mainDB.put(Dataset.FeatureType, di.getFeatureType().toString());
  mainDB.put(Dataset.ServiceName, "radarServer");

  ThreddsMetadata tmd = new ThreddsMetadata();
  Map<String, Object> metadata = tmd.getFlds();
  metadata.put(Dataset.Documentation, new Documentation(null, null, null, "summary", di.getDescription()));

  RadarServerConfig.RadarConfigEntry.GeoInfo gi = di.getGeoCoverage();
  metadata.put(Dataset.GeospatialCoverage,
      new ThreddsMetadata.GeospatialCoverage(
          new ThreddsMetadata.GeospatialRange(gi.eastWest.start, gi.eastWest.size, 0.0, gi.eastWest.units),
          new ThreddsMetadata.GeospatialRange(gi.northSouth.start, gi.northSouth.size, 0.0, gi.northSouth.units),
          new ThreddsMetadata.GeospatialRange(gi.upDown.start, gi.upDown.size, 0.0, gi.upDown.units),
          new ArrayList<ThreddsMetadata.Vocab>(), null));

  DateRange range = di.getTimeCoverage();
  if (makeIDVCatalog)
    range = idvCompatibleRange(range);
  metadata.put(Dataset.TimeCoverage, range);

  // TODO: Need to be able to get this from the inventory
  List<ThreddsMetadata.Variable> catalogVars = new ArrayList<>();
  for (RadarServerConfig.RadarConfigEntry.VarInfo vi : vars.get(dataset)) {
    catalogVars.add(new ThreddsMetadata.Variable(vi.name, null, vi.vocabName, vi.units, null));
  }
  ThreddsMetadata.VariableGroup vg = new ThreddsMetadata.VariableGroup("DIF", null, null, catalogVars);
  metadata.put(Dataset.VariableGroups, vg);

  mainDB.put(Dataset.ThreddsMetadataInheritable, tmd);

  cb.addDataset(mainDB);

  CatalogXmlWriter writer = new CatalogXmlWriter();
  ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
  writer.writeXML(cb.makeCatalog(), os);

  byte[] xmlBytes;
  if (makeIDVCatalog) {
    String xml = os.toString(CDM.UTF8);
    xml = idvDatasetCatalog(xml);
    xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
  } else {
    xmlBytes = os.toByteArray();
  }

  HttpHeaders header = new HttpHeaders();
  header.setContentType(new MediaType("application", "xml"));
  header.setContentLength(xmlBytes.length);
  return new HttpEntity<>(xmlBytes, header);
}
 
Example #20
Source File: RadarServerController.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private DateRange idvCompatibleRange(DateRange range) {
  CalendarDate start = range.getStart().getCalendarDate();
  CalendarDate end = range.getEnd().getCalendarDate();
  return new DateRange(start.toDate(), end.toDate());
}
 
Example #21
Source File: CdmrfBeanOld.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
DateRange getDateRange() {
  return dateRange;
}
 
Example #22
Source File: TimeRangeFilter.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private boolean endsAtOrBeforeEndDate(DateRange dateRange) {
    return dateRange.getEnd().getCalendarDate().equals(CalendarDate.of(endDate)) || dateRange.getEnd().before(endDate);
}
 
Example #23
Source File: TimeRangeFilter.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private boolean startsAtOrAfterStartDate(DateRange dateRange) {
    return dateRange.getStart().getCalendarDate().equals(CalendarDate.of(startDate)) || dateRange.getStart().after(startDate);
}
 
Example #24
Source File: StationRegionDateChooser.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateRange getDateRange() {
  if (!dateSelect || !dateWindow.isShowing() || !dateSelector.isEnabled())
    return null;
  return dateSelector.getDateRange();
}
 
Example #25
Source File: CalendarDateRange.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Does not handle non-standard calendars
 * 
 * @deprecated
 */
public static CalendarDateRange of(DateRange dr) {
  if (dr == null)
    return null;
  return CalendarDateRange.of(dr.getStart().getDate(), dr.getEnd().getDate());
}
 
Example #26
Source File: AbstractRadialAdapter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateRange getDateRange() {
  return new DateRange(getStartDate(), getEndDate());
}
 
Example #27
Source File: GridDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @deprecated use getEndCalendarDate
 */
public Date getEndDate() {
  DateRange dr = getDateRange();
  return (dr != null) ? dr.getEnd().getDate() : null;
}
 
Example #28
Source File: GridDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @deprecated use getStartCalendarDate
 */
public Date getStartDate() {
  DateRange dr = getDateRange();
  return (dr != null) ? dr.getStart().getDate() : null;
}
 
Example #29
Source File: GridDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @deprecated use getCalendarDateRange
 */
public DateRange getDateRange() {
  CalendarDateRange cdr = getCalendarDateRange();
  return (cdr != null) ? cdr.toDateRange() : null;
}
 
Example #30
Source File: Dataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateRange getTimeCoverage() {
  return (DateRange) getInheritedField(TimeCoverage);
}